Skip to content

Commit 3cd0cb6

Browse files
author
Henrik Snöman
committed
Fixed requested changes
1 parent 6c2c83f commit 3cd0cb6

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ embedded-hal = "1.0.0"
6666
defmt = { version = "0.3.8", optional = true }
6767
paste = "1.0.15"
6868
log = { version = "0.4.20", optional = true}
69-
nb = "1.1.0"
7069
rand_core = { version = "0.6", default-features = false, optional = true }
7170

7271
[dev-dependencies]

src/rng.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! - [Random Blinky](https://github.com/stm32-rs/stm32h5xx-hal/blob/master/examples/blinky_random.rs)
77
88
use core::cmp;
9+
use core::marker::PhantomData;
910
use core::mem;
1011

1112
use crate::rcc::{rec, rec::RngClkSel};
@@ -113,10 +114,7 @@ impl RngNist for RNG {
113114
// Enable RNG
114115
self.cr().modify(|_, w| w.rngen().set_bit());
115116

116-
Rng {
117-
rb: self,
118-
_mode: NIST,
119-
}
117+
Rng::new(self)
120118
}
121119
}
122120

@@ -167,10 +165,7 @@ impl RngExt for RNG {
167165
// Enable RNG
168166
self.cr().modify(|_, w| w.rngen().set_bit());
169167

170-
Rng {
171-
rb: self,
172-
_mode: NORMAL,
173-
}
168+
Rng::new(self)
174169
}
175170

176171
/// This uses the register values specified in RM0481 Rev 2 section 32.6.2 RNG configuration B
@@ -212,10 +207,7 @@ impl RngExt for RNG {
212207
// Enable RNG
213208
self.cr().modify(|_, w| w.rngen().set_bit());
214209

215-
Rng {
216-
rb: self,
217-
_mode: FAST,
218-
}
210+
Rng::new(self)
219211
}
220212
}
221213

@@ -241,18 +233,28 @@ pub struct NORMAL;
241233

242234
pub struct Rng<MODE> {
243235
rb: RNG,
244-
_mode: MODE,
236+
_mode: PhantomData<MODE>,
245237
}
246238

247239
impl<MODE> Rng<MODE> {
240+
fn new(rb: RNG) -> Self {
241+
Self {
242+
rb,
243+
_mode: PhantomData,
244+
}
245+
}
248246
/// Returns 32 bits of randomness, or error
247+
/// Automatically resets the seed error flag upon SeedError but will still return SeedError
248+
/// Upon receiving SeedError the user is expected to keep polling this function until a valid value is returned
249249
pub fn value(&mut self) -> Result<u32, Error> {
250250
loop {
251251
let status = self.rb.sr().read();
252252

253253
if status.cecs().bit() {
254254
return Err(Error::ClockError);
255255
} else if status.secs().bit() {
256+
// Reset seed error flag so as to leave the peripheral in a valid state ready for use
257+
self.rb.sr().modify(|_, w| w.seis().clear_bit());
256258
return Err(Error::SeedError);
257259
} else if status.drdy().bit() {
258260
return Ok(self.rb.dr().read().rndata().bits());

0 commit comments

Comments
 (0)