diff options
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/rng.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index dada9bda1..b8dfc7ecf 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs | |||
| @@ -13,6 +13,23 @@ use crate::{Peri, interrupt, pac, peripherals, rcc}; | |||
| 13 | 13 | ||
| 14 | static RNG_WAKER: AtomicWaker = AtomicWaker::new(); | 14 | static RNG_WAKER: AtomicWaker = AtomicWaker::new(); |
| 15 | 15 | ||
| 16 | /// WBA-specific health test configuration values for RNG | ||
| 17 | #[derive(Clone, Copy)] | ||
| 18 | #[allow(dead_code)] | ||
| 19 | enum Htcfg { | ||
| 20 | /// WBA-specific health test configuration (0x0000AAC7) | ||
| 21 | /// Corresponds to configuration A, B, and C thresholds as recommended in the reference manual | ||
| 22 | WbaRecommended = 0x0000_AAC7, | ||
| 23 | } | ||
| 24 | |||
| 25 | impl Htcfg { | ||
| 26 | /// Convert to the raw u32 value for register access | ||
| 27 | #[allow(dead_code)] | ||
| 28 | fn value(self) -> u32 { | ||
| 29 | self as u32 | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 16 | /// RNG error | 33 | /// RNG error |
| 17 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 34 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
| 18 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 35 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -100,7 +117,7 @@ impl<'d, T: Instance> Rng<'d, T> { | |||
| 100 | // wait for CONDRST to be set | 117 | // wait for CONDRST to be set |
| 101 | while !T::regs().cr().read().condrst() {} | 118 | while !T::regs().cr().read().condrst() {} |
| 102 | 119 | ||
| 103 | // TODO for WBA6, the HTCR reg is different | 120 | // Set health test configuration values |
| 104 | #[cfg(not(rng_wba6))] | 121 | #[cfg(not(rng_wba6))] |
| 105 | { | 122 | { |
| 106 | // magic number must be written immediately before every read or write access to HTCR | 123 | // magic number must be written immediately before every read or write access to HTCR |
| @@ -111,6 +128,12 @@ impl<'d, T: Instance> Rng<'d, T> { | |||
| 111 | .htcr() | 128 | .htcr() |
| 112 | .write(|w| w.set_htcfg(pac::rng::vals::Htcfg::RECOMMENDED)); | 129 | .write(|w| w.set_htcfg(pac::rng::vals::Htcfg::RECOMMENDED)); |
| 113 | } | 130 | } |
| 131 | #[cfg(rng_wba6)] | ||
| 132 | { | ||
| 133 | // For WBA6, set RNG_HTCR0 to the recommended value for configurations A, B, and C | ||
| 134 | // This value corresponds to the health test thresholds specified in the reference manual | ||
| 135 | T::regs().htcr(0).write(|w| w.0 = Htcfg::WbaRecommended.value()); | ||
| 136 | } | ||
| 114 | 137 | ||
| 115 | // finish conditioning | 138 | // finish conditioning |
| 116 | T::regs().cr().modify(|reg| { | 139 | T::regs().cr().modify(|reg| { |
