aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-10 21:45:34 +0000
committerGitHub <[email protected]>2022-07-10 21:45:34 +0000
commitc6a11db39ef829adfb8b4903065446c4bb7a2ef4 (patch)
tree68294655fd3326356a5d3ab2ba1d1eacfe3a997f /examples/stm32f4/src/bin
parent93e7d53e393a8f79be1c4a5c0e1fd8497305fc50 (diff)
parent5a208d28d011761d88e12881a69ab9c0663149e2 (diff)
Merge #854
854: Implement IWDG timeout calculation r=Dirbaio a=chemicstry Allow specifying `IndependentWatchdog` timeout as `Duration` instead of prescaler value. Since IWDG is clocked from LSI, which differs between families, I standardized HSI/LSI definitions in RCC and used that. Co-authored-by: chemicstry <[email protected]>
Diffstat (limited to 'examples/stm32f4/src/bin')
-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}