Skip to content

Commit 3e2d1c6

Browse files
author
Henrik Snöman
committed
Changed clock error handling
1 parent 57b83d1 commit 3e2d1c6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/rng.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,18 @@ impl<MODE> Rng<MODE> {
247247
/// Automatically resets the seed error flag upon SeedError but will still return SeedError
248248
/// 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> {
250-
loop {
250+
'outer: loop {
251251
let status = self.rb.sr().read();
252252

253253
if status.cecs().bit() {
254-
return Err(Error::ClockError);
254+
let sr = self.rb.sr();
255+
// Give rng some time to recover from clock disturbance, this time seems to be about a handful of milliseconds
256+
for _ in 0..100_000 {
257+
if sr.read().cecs().bit_is_clear() {
258+
continue 'outer;
259+
}
260+
}
261+
panic!("Failed to automatically recover from Rng Clock Error");
255262
} else if status.secs().bit() {
256263
// Reset seed error flag so as to leave the peripheral in a valid state ready for use
257264
self.rb.sr().modify(|_, w| w.seis().clear_bit());

0 commit comments

Comments
 (0)