-
Notifications
You must be signed in to change notification settings - Fork 102
/
reset_reason.rs
57 lines (45 loc) · 1.53 KB
/
reset_reason.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Example that identifes the reset source
//!
//! Tested on a NUCLEO-H7A3ZI-Q board
#![deny(warnings)]
#![no_main]
#![no_std]
use cortex_m_rt::entry;
#[macro_use]
mod utilities;
use stm32h7xx_hal::{pac, prelude::*, rcc::ResetReason};
use log::info;
#[entry]
fn main() -> ! {
utilities::logger::init();
let cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();
// Constrain and Freeze power
info!("Setup PWR... ");
let pwr = dp.PWR.constrain();
let pwrcfg = example_power!(pwr).freeze();
// Constrain and Freeze clock
info!("Setup RCC... ");
let mut rcc = dp.RCC.constrain();
let reason = rcc.get_reset_reason();
let ccdr = rcc.sys_ck(100.MHz()).freeze(pwrcfg, &dp.SYSCFG);
let gpiob = dp.GPIOB.split(ccdr.peripheral.GPIOB);
let gpioe = dp.GPIOE.split(ccdr.peripheral.GPIOE);
info!("");
info!("stm32h7xx-hal example - Reset Reason");
info!("");
info!("The reset reason was: {}", reason);
// Indicate what caused the last reset
let mut pin = match reason {
ResetReason::PowerOnReset => gpiob.pb14.into_push_pull_output().erase(),
ResetReason::PinReset => gpioe.pe1.into_push_pull_output().erase(),
_ => gpiob.pb0.into_push_pull_output().erase(),
};
pin.set_high();
// delay 10s
let mut delay = cp.SYST.delay(ccdr.clocks);
delay.delay_ms(10_000u16);
// system reset
stm32h7xx_hal::pac::SCB::sys_reset()
// the example will restart, and pb0 will go high
}