forked from stm32-rs/stm32h7xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
independent_watchdog.rs
62 lines (48 loc) · 1.8 KB
/
independent_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
58
59
60
61
62
#![no_main]
#![no_std]
#[macro_use]
mod utilities;
use stm32h7xx_hal::{
independent_watchdog::IndependentWatchdog, pac, prelude::*,
};
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 = IndependentWatchdog::new(dp.IWDG);
// Dual core parts
#[cfg(all(feature = "rm0399", feature = "cm7"))]
let mut watchdog = IndependentWatchdog::new(dp.IWDG1);
#[cfg(all(feature = "rm0399", feature = "cm4"))]
let mut watchdog = IndependentWatchdog::new(dp.IWDG2);
// RM0468
#[cfg(feature = "rm0468")]
let mut watchdog = IndependentWatchdog::new(dp.IWDG1);
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 32.76 seconds (which is the maximum this watchdog can do) and wait forever
// -> restart the chip
watchdog.start(32_760.millis());
// Alternatively, there's also a windowed option where if the watchdog is fed before the window time, it will reset the chip as well
// watchdog.start_windowed(100.millis(), 200.millis());
loop {
// We can feed the watchdog like this:
// watchdog.feed();
cortex_m::asm::nop()
}
}