imxrt_boot_gen/flexspi/fields.rs
1//! FlexSPI configuration block fields
2
3use core::num::NonZeroU8;
4
5/// `readSampleClkSrc` of the general FCB
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7#[repr(u8)]
8pub enum ReadSampleClockSource {
9 InternalLoopback = 0x00,
10 LoopbackFromDQSPad = 0x01,
11 FlashProvidedDQS = 0x03,
12}
13
14/// `columnAdressWidth`
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16#[repr(u8)]
17pub enum ColumnAddressWidth {
18 OtherDevices = 0,
19 Hyperflash = 3,
20 // TODO serial NAND flash values 12 and 13 apply, at a minimum,
21 // to the following chips:
22 //
23 // - imxrt1020
24 // - imxrt1170
25}
26
27/// Sequence parameter for device mode configuration
28#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)]
29#[repr(C, packed)]
30pub struct DeviceModeSequence {
31 /// How many sequences are needed
32 /// to execute the command?
33 sequence_count: u8,
34 /// Where do we start in the LUT?
35 sequence_index: u8,
36 _reserved: u16,
37}
38
39impl DeviceModeSequence {
40 /// Create a new sequence parameter for device configuration
41 ///
42 /// `sequence_index`: starting LUT index of Device mode configuration command
43 /// `sequence_count`: number of LUT sequences for Device mode configuration command
44 pub const fn new(sequence_count: u8, sequence_index: u8) -> Self {
45 Self {
46 sequence_count,
47 sequence_index,
48 _reserved: 0,
49 }
50 }
51
52 pub(crate) const fn zeroed() -> Self {
53 Self::new(0, 0)
54 }
55}
56
57/// Configuration commands to augment LUT sequences.
58pub type ConfigurationCommand = DeviceModeSequence;
59
60/// Describes both the `deviceModeCfgEnable` field, and
61/// the `deviceModeArg` field, which is only valid if
62/// the configuration is enabled.
63#[derive(Clone, Copy, PartialEq, Eq, Default)]
64pub enum DeviceModeConfiguration {
65 /// Device configuration mode is disabled
66 #[default]
67 Disabled,
68 /// Device configuration mode is enabled
69 ///
70 /// Tells the processor to use the associated device mode argument and sequence
71 Enabled {
72 /// `deviceModeArg`
73 device_mode_arg: u32,
74 /// `deviceModeSeq`
75 device_mode_seq: DeviceModeSequence,
76 },
77}
78
79/// Wait time for all configuration commands
80///
81/// From the docs...
82///
83/// > Available for device that support v1.1.0 FlexSPI configuration block.
84/// > If it is greater than 0, ROM will wait waitTimeCfgCommands * 100us
85/// > for all device memory configuration commands instead of using read
86/// > status to wait until these commands complete.
87#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88#[repr(transparent)]
89pub struct WaitTimeConfigurationCommands(u16);
90impl WaitTimeConfigurationCommands {
91 pub const fn disable() -> Self {
92 WaitTimeConfigurationCommands(0)
93 }
94
95 /// Computes the wait time from the specified `wait_time_us` (microseconds)
96 ///
97 /// The duration should be divisible by `100us`, since the
98 /// value is a factor scaled by `100us`
99 pub const fn new(wait_time_us: u16) -> Self {
100 WaitTimeConfigurationCommands(wait_time_us / 100)
101 }
102}
103
104/// `sFlashPad` field
105#[derive(Debug, Clone, Copy, PartialEq, Eq)]
106#[repr(u8)]
107pub enum FlashPadType {
108 Single = 1,
109 Dual = 2,
110 Quad = 4,
111 Octal = 8,
112}
113
114/// Options for the serial clock frequency.
115///
116/// Use this with an [`Imxrt`](crate::Imxrt) to produce
117/// a [`SerialClockFrequency`]. Note that not all options
118/// are valid for all parts.
119#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
120#[repr(u8)]
121pub enum SerialClockOption {
122 MHz30,
123 MHz50,
124 MHz60,
125 MHz75,
126 MHz80,
127 MHz100,
128 MHz120,
129 MHz133,
130 MHz166,
131}
132
133/// Serial clock frequency for flash read / write.
134#[derive(Debug, Clone, Copy, PartialEq, Eq)]
135#[repr(transparent)]
136pub struct SerialClockFrequency(pub(crate) NonZeroU8);
137
138impl SerialClockFrequency {
139 /// Returns the raw value for this clock frequency enum.
140 pub const fn get(self) -> u8 {
141 self.0.get()
142 }
143}
144
145/// A FlexSPI serial flash region
146#[derive(Debug, Clone, Copy, PartialEq, Eq)]
147#[repr(usize)]
148pub enum SerialFlashRegion {
149 A1,
150 A2,
151 B1,
152 B2,
153}