aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorchemicstry <[email protected]>2022-07-10 20:38:30 +0300
committerchemicstry <[email protected]>2022-07-10 20:38:30 +0300
commitbd01e90bfa4895b45e41ad538cb24a959b0b58ab (patch)
treeec86a61d00a087e1faba730d922e53c8f3086f2f /examples
parent5f43c1d37e9db847c7861fe0bd821db62edba9f6 (diff)
Implement IWDG timeout calculation
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f4/src/bin/wdt.rs44
1 files changed, 44 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..41e1f4c7b
--- /dev/null
+++ b/examples/stm32f4/src/bin/wdt.rs
@@ -0,0 +1,44 @@
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, Duration::from_secs(1));
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 if i < 5 {
36 info!("Petting watchdog");
37 unsafe {
38 wdt.pet();
39 }
40 }
41
42 i += 1;
43 }
44}