Adds WDT support for the nrf54l15

This commit is contained in:
nerwalt 2025-08-08 10:23:22 -06:00
parent f2be66a5f9
commit adc0fc0a97
5 changed files with 55 additions and 6 deletions

View File

@ -88,7 +88,7 @@ nrf5340-app-ns = ["_nrf5340-app", "_ns"]
## nRF5340 network core
nrf5340-net = ["_nrf5340-net"]
## nRF54L15 application core in Secure mode
nrf54l15-app-s = ["_nrf54l15-app", "_s"]
nrf54l15-app-s = ["_nrf54l15-app", "_s", "_multi_wdt"]
## nRF54L15 application core in Non-Secure mode
nrf54l15-app-ns = ["_nrf54l15-app", "_ns"]

View File

@ -204,6 +204,11 @@ pub const EASY_DMA_SIZE: usize = (1 << 16) - 1;
//pub const FLASH_SIZE: usize = 1024 * 1024;
embassy_hal_internal::peripherals! {
// WDT
WDT0,
#[cfg(feature = "_s")]
WDT1,
// GPIO port 0
P0_00,
P0_01,
@ -285,6 +290,10 @@ impl_pin!(P2_08, 2, 8);
impl_pin!(P2_09, 2, 9);
impl_pin!(P2_10, 2, 10);
impl_wdt!(WDT0, WDT31, WDT31, 0);
#[cfg(feature = "_s")]
impl_wdt!(WDT1, WDT30, WDT30, 1);
embassy_hal_internal::interrupt_mod!(
SWI00,
SWI01,

View File

@ -170,7 +170,6 @@ pub mod uarte;
feature = "nrf52840"
))]
pub mod usb;
#[cfg(not(feature = "_nrf54l"))] // TODO
pub mod wdt;
// This mod MUST go last, so that it sees all the `impl_foo!` macros

View File

@ -37,9 +37,9 @@ impl Config {
pub fn try_new<T: Instance>(_wdt: &Peri<'_, T>) -> Option<Self> {
let r = T::REGS;
#[cfg(not(any(feature = "_nrf91", feature = "_nrf5340")))]
#[cfg(not(any(feature = "_nrf91", feature = "_nrf5340", feature = "_nrf54l")))]
let runstatus = r.runstatus().read().runstatus();
#[cfg(any(feature = "_nrf91", feature = "_nrf5340"))]
#[cfg(any(feature = "_nrf91", feature = "_nrf5340", feature = "_nrf54l"))]
let runstatus = r.runstatus().read().runstatuswdt();
if runstatus {
@ -90,9 +90,9 @@ impl<T: Instance> Watchdog<T> {
let crv = config.timeout_ticks.max(MIN_TICKS);
let rren = crate::pac::wdt::regs::Rren((1u32 << N) - 1);
#[cfg(not(any(feature = "_nrf91", feature = "_nrf5340")))]
#[cfg(not(any(feature = "_nrf91", feature = "_nrf5340", feature = "_nrf54l")))]
let runstatus = r.runstatus().read().runstatus();
#[cfg(any(feature = "_nrf91", feature = "_nrf5340"))]
#[cfg(any(feature = "_nrf91", feature = "_nrf5340", feature = "_nrf54l"))]
let runstatus = r.runstatus().read().runstatuswdt();
if runstatus {

View File

@ -0,0 +1,41 @@
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_nrf::wdt::{Config, HaltConfig, Watchdog};
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_nrf::init(Default::default());
info!("Hello WDT");
const TIMEOUT_S: u32 = 5;
let mut config = Config::default();
config.timeout_ticks = 32768 * TIMEOUT_S;
// This is needed for `probe-rs run` to be able to catch the panic message
// in the WDT interrupt. The core resets 2 ticks after firing the interrupt.
config.action_during_debug_halt = HaltConfig::PAUSE;
// The nrf54l15 has two watchdogs. Only WDT0 is available in non-secure (ns) mode, as WDT1 is
// reserved for the secure (s) environment. In secure mode, both WDT0 and WDT1 are available.
info!("Watchdog launched with {} s timeout", TIMEOUT_S);
let (_wdt, [mut handle]) = match Watchdog::try_new(p.WDT1, config) {
Ok(x) => x,
Err(_) => {
info!("Watchdog already active with wrong config, waiting for it to timeout...");
loop {}
}
};
for wait in 1..=TIMEOUT_S {
info!("Waiting {} seconds ...", wait);
Timer::after_secs(wait as u64).await;
handle.pet();
info!("Pet watchdog");
}
}