From bc156afbb2950ae073d0f271f26517cf16b35263 Mon Sep 17 00:00:00 2001 From: Lucas Granberg Date: Thu, 10 Aug 2023 16:16:45 +0300 Subject: [PATCH] fix rng ced toggling sequence on reset. --- embassy-stm32/src/rng.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 2a4978ec..30816e43 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -73,15 +73,20 @@ impl<'d, T: Instance> Rng<'d, T> { #[cfg(not(rng_v1))] pub fn reset(&mut self) { T::regs().cr().write(|reg| { - reg.set_rngen(false); reg.set_condrst(true); + reg.set_nistc(pac::rng::vals::Nistc::CUSTOM); // set RNG config "A" according to reference manual // this has to be written within the same write access as setting the CONDRST bit - reg.set_nistc(pac::rng::vals::Nistc::DEFAULT); reg.set_rng_config1(pac::rng::vals::RngConfig1::CONFIGA); + reg.set_clkdiv(pac::rng::vals::Clkdiv::NODIV); reg.set_rng_config2(pac::rng::vals::RngConfig2::CONFIGA_B); reg.set_rng_config3(pac::rng::vals::RngConfig3::CONFIGA); - reg.set_clkdiv(pac::rng::vals::Clkdiv::NODIV); + reg.set_ced(true); + reg.set_ie(false); + reg.set_rngen(true); + }); + T::regs().cr().write(|reg| { + reg.set_ced(false); }); // wait for CONDRST to be set while !T::regs().cr().read().condrst() {}