2023-07-13 11:16:11 +02:00
|
|
|
//! This example shows how to use Watchdog in the RP2040 chip.
|
|
|
|
//!
|
|
|
|
//! It does not work with the RP Pico W board. See wifi_blinky.rs or connect external LED and resistor.
|
|
|
|
|
2022-12-24 02:51:06 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::info;
|
|
|
|
use embassy_executor::Spawner;
|
|
|
|
use embassy_rp::gpio;
|
|
|
|
use embassy_rp::watchdog::*;
|
|
|
|
use embassy_time::{Duration, Timer};
|
|
|
|
use gpio::{Level, Output};
|
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
|
|
|
info!("Hello world!");
|
|
|
|
|
|
|
|
let mut watchdog = Watchdog::new(p.WATCHDOG);
|
|
|
|
let mut led = Output::new(p.PIN_25, Level::Low);
|
|
|
|
|
|
|
|
// Set the LED high for 2 seconds so we know when we're about to start the watchdog
|
|
|
|
led.set_high();
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_secs(2).await;
|
2022-12-24 02:51:06 +01:00
|
|
|
|
2022-12-24 03:22:51 +01:00
|
|
|
// Set to watchdog to reset if it's not fed within 1.05 seconds, and start it
|
2022-12-24 02:51:06 +01:00
|
|
|
watchdog.start(Duration::from_millis(1_050));
|
|
|
|
info!("Started the watchdog timer");
|
|
|
|
|
2022-12-24 03:22:51 +01:00
|
|
|
// Blink once a second for 5 seconds, feed the watchdog timer once a second to avoid a reset
|
2022-12-24 02:51:06 +01:00
|
|
|
for _ in 1..=5 {
|
|
|
|
led.set_low();
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_millis(500).await;
|
2022-12-24 02:51:06 +01:00
|
|
|
led.set_high();
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_millis(500).await;
|
2022-12-24 02:51:06 +01:00
|
|
|
info!("Feeding watchdog");
|
|
|
|
watchdog.feed();
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("Stopped feeding, device will reset in 1.05 seconds");
|
|
|
|
// Blink 10 times per second, not feeding the watchdog.
|
2022-12-24 03:22:51 +01:00
|
|
|
// The processor should reset in 1.05 seconds.
|
2022-12-24 02:51:06 +01:00
|
|
|
loop {
|
|
|
|
led.set_low();
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_millis(100).await;
|
2022-12-24 02:51:06 +01:00
|
|
|
led.set_high();
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_millis(100).await;
|
2022-12-24 02:51:06 +01:00
|
|
|
}
|
|
|
|
}
|