aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f4/src/bin/wdt.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs
new file mode 100644
index 000000000..bfc487c31
--- /dev/null
+++ b/examples/stm32f4/src/bin/wdt.rs
@@ -0,0 +1,46 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::wdg::IndependentWatchdog;
10use embassy_stm32::Peripherals;
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 info!("Hello World!");
16
17 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
18
19 let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000);
20 unsafe {
21 wdt.unleash();
22 }
23
24 let mut i = 0;
25
26 loop {
27 info!("high");
28 led.set_high();
29 Timer::after(Duration::from_millis(300)).await;
30
31 info!("low");
32 led.set_low();
33 Timer::after(Duration::from_millis(300)).await;
34
35 // Pet watchdog for 5 iterations and then stop.
36 // MCU should restart in 1 second after the last pet.
37 if i < 5 {
38 info!("Petting watchdog");
39 unsafe {
40 wdt.pet();
41 }
42 }
43
44 i += 1;
45 }
46}