Skip to content

Commit 4df3c72

Browse files
authored
Add way to get reset reason (#120)
1 parent 064e9b4 commit 4df3c72

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/rcc/mod.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,61 @@ impl Rcc {
439439
self.rb.csr.modify(|_, w| w.lsion().set_bit());
440440
while self.rb.csr.read().lsirdy().bit_is_clear() {}
441441
}
442+
443+
pub fn get_reset_reason(&self) -> ResetReason {
444+
let csr = self.rb.csr.read();
445+
446+
ResetReason {
447+
low_power: csr.lpwrstf().bit(),
448+
window_watchdog: csr.wwdgrstf().bit(),
449+
independent_watchdog: csr.iwdgrstf().bit(),
450+
software: csr.sftrstf().bit(),
451+
brown_out: csr.borrstf().bit(),
452+
reset_pin: csr.pinrstf().bit(),
453+
option_byte: csr.oblrstf().bit(),
454+
}
455+
}
456+
457+
pub fn clear_reset_reason(&mut self) {
458+
self.rb.csr.modify(|_, w| w.rmvf().set_bit());
459+
}
460+
}
461+
462+
pub struct ResetReason {
463+
/// Low-power reset flag
464+
///
465+
/// Set by hardware when a reset occurs to illegal Stop, Standby or Shutdown mode entry.
466+
pub low_power: bool,
467+
468+
/// Window watchdog reset flag
469+
///
470+
/// Set by hardware when a window watchdog reset occurs.
471+
pub window_watchdog: bool,
472+
473+
/// Independent window watchdog reset flag
474+
///
475+
/// Set by hardware when an independent watchdog reset occurs.
476+
pub independent_watchdog: bool,
477+
478+
/// Software reset flag
479+
///
480+
/// Set by hardware when a software reset occurs.
481+
pub software: bool,
482+
483+
/// Brown out reset flag
484+
///
485+
/// Set by hardware when a brown out reset occurs.
486+
pub brown_out: bool,
487+
488+
/// Pin reset flag
489+
///
490+
/// Set by hardware when a reset from the NRST pin occurs.
491+
pub reset_pin: bool,
492+
493+
/// Option byte loader reset flag
494+
///
495+
/// Set by hardware when a reset from the Option Byte loading occurs.
496+
pub option_byte: bool,
442497
}
443498

444499
/// Extension trait that constrains the `RCC` peripheral

0 commit comments

Comments
 (0)