diff options
| author | Dion Dokter <[email protected]> | 2024-04-14 00:45:53 +0200 |
|---|---|---|
| committer | Dion Dokter <[email protected]> | 2024-04-14 00:45:53 +0200 |
| commit | ca84be80bcbfb4459212fa02e75cfafc85d6df51 (patch) | |
| tree | d45541d1305b621e3e63eead1e7ffc1c58a7b39e /examples/stm32u0/src/bin/wdt.rs | |
| parent | 0a785585bcc268ca1eb5341b1bcc54113cf96298 (diff) | |
Add wdt and flash
Diffstat (limited to 'examples/stm32u0/src/bin/wdt.rs')
| -rw-r--r-- | examples/stm32u0/src/bin/wdt.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/stm32u0/src/bin/wdt.rs b/examples/stm32u0/src/bin/wdt.rs new file mode 100644 index 000000000..f6276e2e9 --- /dev/null +++ b/examples/stm32u0/src/bin/wdt.rs | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 7 | use embassy_stm32::wdg::IndependentWatchdog; | ||
| 8 | use embassy_time::Timer; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async fn main(_spawner: Spawner) { | ||
| 13 | let p = embassy_stm32::init(Default::default()); | ||
| 14 | info!("Hello World!"); | ||
| 15 | |||
| 16 | let mut led = Output::new(p.PA5, Level::High, Speed::Low); | ||
| 17 | |||
| 18 | let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000); | ||
| 19 | wdt.unleash(); | ||
| 20 | |||
| 21 | let mut i = 0; | ||
| 22 | |||
| 23 | loop { | ||
| 24 | info!("high"); | ||
| 25 | led.set_high(); | ||
| 26 | Timer::after_millis(300).await; | ||
| 27 | |||
| 28 | info!("low"); | ||
| 29 | led.set_low(); | ||
| 30 | Timer::after_millis(300).await; | ||
| 31 | |||
| 32 | // Pet watchdog for 5 iterations and then stop. | ||
| 33 | // MCU should restart in 1 second after the last pet. | ||
| 34 | if i < 5 { | ||
| 35 | info!("Petting watchdog"); | ||
| 36 | wdt.pet(); | ||
| 37 | } | ||
| 38 | |||
| 39 | i += 1; | ||
| 40 | } | ||
| 41 | } | ||
