Module rp2040_hal::watchdog

source ·
Expand description

Watchdog

The watchdog is a countdown timer that can restart parts of the chip if it reaches zero. This can be used to restart the processor if software gets stuck in an infinite loop. The programmer must periodically write a value to the watchdog to stop it from reaching zero.

See Chapter 4 Section 7 of the datasheet for more details

§Usage

use cortex_m::prelude::{_embedded_hal_watchdog_Watchdog, _embedded_hal_watchdog_WatchdogEnable};
use fugit::ExtU32;
use rp2040_hal::{clocks::init_clocks_and_plls, pac, watchdog::Watchdog};
let mut pac = pac::Peripherals::take().unwrap();
let mut watchdog = Watchdog::new(pac.WATCHDOG);
let _clocks = init_clocks_and_plls(
    12_000_000,
    pac.XOSC,
    pac.CLOCKS,
    pac.PLL_SYS,
    pac.PLL_USB,
    &mut pac.RESETS,
    &mut watchdog,
).ok().unwrap();
// Set to watchdog to reset if it's not reloaded within 1.05 seconds, and start it
watchdog.start(1_050_000.micros());
// Feed the watchdog once per cycle to avoid reset
for _ in 1..=10000 {
    cortex_m::asm::delay(100_000);
    watchdog.feed();
}
// Stop feeding, now we'll reset
loop {}

See examples/watchdog.rs for a more complete example

Structs§

Enums§