imxrt1170evk_fcb/
lib.rs

1//! FlexSPI configuration block (FCB) for the iMXRT1170EVK.
2//!
3//! This FCB is compatible with the IS25WB QuadSPI flash storage found on the
4//! iMXRT1170EVK.
5#![no_std]
6
7pub use nor::ConfigurationBlock;
8
9use imxrt_boot_gen::flexspi::{self, opcodes::sdr::*, *};
10use imxrt_boot_gen::flexspi::{
11    FlashPadType, ReadSampleClockSource, SerialClockFrequency, SerialFlashRegion,
12};
13use imxrt_boot_gen::serial_flash::*;
14
15const SEQ_READ: Sequence = SequenceBuilder::new()
16    .instr(Instr::new(CMD, Pads::One, 0xEB))
17    .instr(Instr::new(RADDR, Pads::Four, 0x18))
18    .instr(Instr::new(DUMMY, Pads::Four, 0x06))
19    .instr(Instr::new(READ, Pads::Four, 0x04))
20    .build();
21const SEQ_READ_STATUS: Sequence = SequenceBuilder::new()
22    .instr(Instr::new(CMD, Pads::One, 0x05))
23    .instr(Instr::new(READ, Pads::One, 0x04))
24    .build();
25const SEQ_WRITE_ENABLE: Sequence = SequenceBuilder::new()
26    .instr(Instr::new(CMD, Pads::One, 0x06))
27    .build();
28const SEQ_ERASE_SECTOR: Sequence = SequenceBuilder::new()
29    .instr(Instr::new(CMD, Pads::One, 0x20))
30    .instr(Instr::new(RADDR, Pads::One, 0x18))
31    .build();
32const SEQ_PAGE_PROGRAM: Sequence = SequenceBuilder::new()
33    .instr(Instr::new(CMD, Pads::One, 0x02))
34    .instr(Instr::new(RADDR, Pads::One, 0x18))
35    .instr(Instr::new(WRITE, Pads::One, 0x04))
36    .build();
37const SEQ_CHIP_ERASE: Sequence = SequenceBuilder::new()
38    .instr(Instr::new(CMD, Pads::One, 0x60))
39    .build();
40
41const LUT: LookupTable = LookupTable::new()
42    .command(Command::Read, SEQ_READ)
43    .command(Command::ReadStatus, SEQ_READ_STATUS)
44    .command(Command::WriteEnable, SEQ_WRITE_ENABLE)
45    .command(Command::EraseSector, SEQ_ERASE_SECTOR)
46    .command(Command::PageProgram, SEQ_PAGE_PROGRAM)
47    .command(Command::ChipErase, SEQ_CHIP_ERASE);
48
49const COMMON_CONFIGURATION_BLOCK: flexspi::ConfigurationBlock =
50    flexspi::ConfigurationBlock::new(LUT)
51        .version(Version::new(1, 4, 0))
52        .read_sample_clk_src(ReadSampleClockSource::LoopbackFromDQSPad)
53        .cs_hold_time(3)
54        .cs_setup_time(3)
55        .controller_misc_options(0x10)
56        .serial_flash_pad_type(FlashPadType::Quad)
57        .serial_clk_freq(SerialClockFrequency::MHz133)
58        .flash_size(SerialFlashRegion::A1, 16 * 1024 * 1024);
59
60pub const SERIAL_NOR_CONFIGURATION_BLOCK: nor::ConfigurationBlock =
61    nor::ConfigurationBlock::new(COMMON_CONFIGURATION_BLOCK)
62        .page_size(256)
63        .sector_size(4 * 1024)
64        .ip_cmd_serial_clk_freq(nor::SerialClockFrequency::MHz30)
65        .block_size(64 * 1024);
66
67#[no_mangle]
68#[cfg_attr(all(target_arch = "arm", target_os = "none"), link_section = ".fcb")]
69pub static FLEXSPI_CONFIGURATION_BLOCK: nor::ConfigurationBlock = SERIAL_NOR_CONFIGURATION_BLOCK;
70
71#[cfg(test)]
72mod tests {
73    use super::SERIAL_NOR_CONFIGURATION_BLOCK;
74
75    /// Magic numbers extracted from a build of the 1170 EVK's SDK.
76    ///
77    /// The actual configuration has an instruction sequence, 'erase block,'
78    /// at offset 0x100. I I dropped it when coping over the raw values, since
79    /// we don't have support for custom instruction sequences. Erase sector and
80    /// erase chip are both implemented.
81    const EXPECTED: [u32; 128] = [
82        0x46434642, 0x00040156, 0x00000000, 0x01030300, 0x00000000, 0x00000000, 0x00000000,
83        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
84        0x00000000, 0x00000000, 0x10000000, 0x01040700, 0x00000000, 0x00000000, 0x00000001,
85        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
86        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xeb04180a, 0x06320426, 0x00000000,
87        0x00000000, 0x05040424, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
88        0x00000000, 0x00000000, 0x06040000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
89        0x00000000, 0x00000000, 0x00000000, 0x20041808, 0x00000000, 0x00000000, 0x00000000,
90        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
91        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02041808, 0x04200000,
92        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x60040000,
93        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
94        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
95        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
96        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
97        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
98        0x00010000, 0x00100000, 0x01000000, 0x00000000, 0x00000100, 0x00000000, 0x00000000,
99        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
100        0x00000000, 0x00000000,
101    ];
102
103    #[test]
104    fn imxrt1170evk() {
105        let actual: [u32; 128] = unsafe { core::mem::transmute(SERIAL_NOR_CONFIGURATION_BLOCK) };
106        for (i, (a, e)) in actual.iter().zip(EXPECTED).enumerate() {
107            let offset = i * 4;
108            assert_eq!(
109                a.to_be_bytes(),
110                e.to_le_bytes(),
111                "Offset {offset:#X}\nACTUAL: {actual:?}\nEXPECTED: {EXPECTED:?}"
112            );
113        }
114    }
115}