|
1 |
| -//! Flash block configuration |
| 1 | +//! Flash controller configuration |
2 | 2 |
|
3 |
| -use crate::target_device::EFC; |
4 | 3 | use crate::pmc::PmcError;
|
| 4 | +use crate::target_device::EFC; |
5 | 5 |
|
6 | 6 | pub struct Efc {
|
7 | 7 | pub(crate) periph: EFC,
|
@@ -42,27 +42,50 @@ pub enum FlashWaitStates {
|
42 | 42 | Six,
|
43 | 43 | }
|
44 | 44 |
|
45 |
| -impl FlashWaitStates { |
46 |
| - /// Calculate the lowest possible number of flash wait states from a given |
47 |
| - /// master clock frequency in MHz. |
48 |
| - /// |
49 |
| - /// The max mck frequency supported is 150MHz. This is *not* the CPU frequency, |
50 |
| - /// which may go up to 300MHz. |
51 |
| - /// |
52 |
| - /// Note: This is probably only valid at VDDIO = 3.0V |
53 |
| - pub fn from_mck_mhz(freq: u8) -> Result<Self, PmcError> { |
54 |
| - // Reference: Table 58-51 Embedded Flash Wait States for Worst-Case Conditions |
55 |
| - let fws = match freq { |
| 45 | +impl TryFrom<u8> for FlashWaitStates { |
| 46 | + type Error = PmcError; |
| 47 | + |
| 48 | + #[cfg(feature = "vddio-3v")] |
| 49 | + fn try_from(freq: u8) -> Result<Self, Error> { |
| 50 | + // References: |
| 51 | + // - Table 58-50 (p. 1804) Embedded Flash Wait States for Worst-Case Conditions (V70/V71) |
| 52 | + // - Table 59-50 (p. 1850) Embedded Flash Wait States for Worst-Case Conditions (E70/S70; VDDIO = 3.0V) |
| 53 | + match freq { |
56 | 54 | 0..=23 => Self::Zero,
|
57 | 55 | 24..=46 => Self::One,
|
58 | 56 | 47..=69 => Self::Two,
|
59 | 57 | 70..=92 => Self::Three,
|
60 | 58 | 93..=115 => Self::Four,
|
61 | 59 | 116..=138 => Self::Five,
|
62 | 60 | 139..=150 => Self::Six,
|
63 |
| - _ => return Err(PmcError::InvalidConfiguration), |
64 |
| - }; |
| 61 | + _ => Err(PmcError::InvalidConfiguration), |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + #[cfg(feature = "vddio-1v")] |
| 66 | + fn try_from(freq: u8) -> Result<Self, Error> { |
| 67 | + // References: |
| 68 | + // - Table 59-50 (p. 1850) Embedded Flash Wait States for Worst-Case Conditions (E70/S70; VDDIO = 1.7V) |
| 69 | + match freq { |
| 70 | + 0..=21 => Self::Zero, |
| 71 | + 22..=42 => Self::One, |
| 72 | + 43..=63 => Self::Two, |
| 73 | + 64..=84 => Self::Three, |
| 74 | + 85..=106 => Self::Four, |
| 75 | + 107..=125 => Self::Five, |
| 76 | + 126..=137 => Self::Six, |
| 77 | + _ => Err(PmcError::InvalidConfiguration), |
| 78 | + } |
| 79 | + } |
| 80 | +} |
65 | 81 |
|
66 |
| - Ok(fws) |
| 82 | +impl FlashWaitStates { |
| 83 | + /// Calculate the lowest possible number of flash wait states from a given |
| 84 | + /// master clock frequency in MHz. |
| 85 | + /// |
| 86 | + /// The max mck frequency supported is 150MHz. This is *not* the CPU frequency, |
| 87 | + /// which may go up to 300MHz. |
| 88 | + pub fn from_mck_mhz(freq: u8) -> Result<Self, PmcError> { |
| 89 | + freq.try_into()? |
67 | 90 | }
|
68 | 91 | }
|
0 commit comments