aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf54l15/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'examples/nrf54l15/src/bin')
-rw-r--r--examples/nrf54l15/src/bin/wdt.rs41
1 files changed, 41 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..28856dad4
--- /dev/null
+++ b/examples/nrf54l15/src/bin/wdt.rs
@@ -0,0 +1,41 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_nrf::wdt::{Config, HaltConfig, Watchdog};
7use embassy_time::Timer;
8use {defmt_rtt as _, panic_probe as _};
9
10#[embassy_executor::main]
11async 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 WDT0 is available in non-secure (ns) mode, as WDT1 is
25 // reserved for the secure (s) environment. In secure mode, both WDT0 and WDT1 are available.
26 info!("Watchdog launched with {} s timeout", TIMEOUT_S);
27 let (_wdt, [mut handle]) = match Watchdog::try_new(p.WDT1, config) {
28 Ok(x) => x,
29 Err(_) => {
30 info!("Watchdog already active with wrong config, waiting for it to timeout...");
31 loop {}
32 }
33 };
34
35 for wait in 1..=TIMEOUT_S {
36 info!("Waiting {} seconds ...", wait);
37 Timer::after_secs(wait as u64).await;
38 handle.pet();
39 info!("Pet watchdog");
40 }
41}