diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-08-08 23:20:47 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-08 23:20:47 +0200 |
| commit | 1f19430f2ebda4d686057a854f6b74b8643cd56b (patch) | |
| tree | 6e3669596380599c38535a3da7a403b178028abb /examples | |
| parent | 68b2c1fb4b39115800e82c0b26d736e13c8711dc (diff) | |
| parent | 3a6d927ed5a85fd2381d7896455265b5cd24c42d (diff) | |
Merge pull request #4518 from nerwalt/nrf54l15-wdt
Adds WDT support for the nrf54l15
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf54l15/src/bin/wdt.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/nrf54l15/src/bin/wdt.rs b/examples/nrf54l15/src/bin/wdt.rs new file mode 100644 index 000000000..9fe37d080 --- /dev/null +++ b/examples/nrf54l15/src/bin/wdt.rs | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_nrf::wdt::{Config, HaltConfig, Watchdog}; | ||
| 7 | use embassy_time::Timer; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_nrf::init(Default::default()); | ||
| 13 | info!("Hello WDT"); | ||
| 14 | |||
| 15 | const TIMEOUT_S: u32 = 5; | ||
| 16 | |||
| 17 | let mut config = Config::default(); | ||
| 18 | config.timeout_ticks = 32768 * TIMEOUT_S; | ||
| 19 | |||
| 20 | // This is needed for `probe-rs run` to be able to catch the panic message | ||
| 21 | // in the WDT interrupt. The core resets 2 ticks after firing the interrupt. | ||
| 22 | config.action_during_debug_halt = HaltConfig::PAUSE; | ||
| 23 | |||
| 24 | // The nrf54l15 has two watchdogs. Only one (WDT) is available in non-secure (ns) mode, as the | ||
| 25 | // other is reserved for the secure (s) environment. In secure mode, both are available as WDT0 | ||
| 26 | // and WDT1. | ||
| 27 | info!("Watchdog launched with {} s timeout", TIMEOUT_S); | ||
| 28 | let (_wdt, [mut handle]) = match Watchdog::try_new(p.WDT1, config) { | ||
| 29 | Ok(x) => x, | ||
| 30 | Err(_) => { | ||
| 31 | info!("Watchdog already active with wrong config, waiting for it to timeout..."); | ||
| 32 | loop {} | ||
| 33 | } | ||
| 34 | }; | ||
| 35 | |||
| 36 | for wait in 1..=TIMEOUT_S { | ||
| 37 | info!("Waiting {} seconds ...", wait); | ||
| 38 | Timer::after_secs(wait as u64).await; | ||
| 39 | handle.pet(); | ||
| 40 | info!("Pet watchdog"); | ||
| 41 | } | ||
| 42 | } | ||
