forked from stm32-rs/stm32h7xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_watchdog.rs
57 lines (44 loc) · 1.57 KB
/
system_watchdog.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
#![no_main]
#![no_std]
#[macro_use]
mod utilities;
use stm32h7xx_hal::{pac, prelude::*, system_watchdog::SystemWindowWatchdog};
use cortex_m_rt::entry;
use log::info;
#[entry]
fn main() -> ! {
utilities::logger::init();
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 rcc = dp.RCC.constrain();
let ccdr = rcc.sys_ck(96.MHz()).freeze(pwrcfg, &dp.SYSCFG);
#[cfg(any(feature = "rm0433", feature = "rm0455"))]
let mut watchdog = SystemWindowWatchdog::new(dp.WWDG, &ccdr);
// Dual core parts
#[cfg(all(feature = "rm0399", feature = "cm7"))]
let mut watchdog = SystemWindowWatchdog::new(dp.WWDG1, &ccdr);
#[cfg(all(feature = "rm0399", feature = "cm4"))]
let mut watchdog = SystemWindowWatchdog::new(dp.WWDG2, &ccdr);
// RM0468
#[cfg(feature = "rm0468")]
let mut watchdog = SystemWindowWatchdog::new(dp.WWDG1, &ccdr);
info!("");
info!("stm32h7xx-hal example - Watchdog");
info!("");
// If the watchdog is working correctly this print should
// appear again and again as the chip gets restarted
info!("Watchdog restarted! ");
// Enable the watchdog with a limit of 100 ms and wait forever
// -> restart the chip
watchdog.start(100.millis());
loop {
// We can feed the watchdog like this:
// watchdog.feed();
cortex_m::asm::nop()
}
}