blob: a54ec493a8d0fbf3c6329fa9d0ba816098069e94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
//! This example shows how to use Watchdog in the RP235x chip.
//!
//! It does not work with the RP Pico W board. See wifi_blinky.rs or connect external LED and resistor.
#![no_std]
#![no_main]
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();
Timer::after_secs(2).await;
// Set to watchdog to reset if it's not fed within 1.05 seconds, and start it
watchdog.start(Duration::from_millis(1_050));
info!("Started the watchdog timer");
// Blink once a second for 5 seconds, feed the watchdog timer once a second to avoid a reset
for _ in 1..=5 {
led.set_low();
Timer::after_millis(500).await;
led.set_high();
Timer::after_millis(500).await;
info!("Feeding watchdog");
watchdog.feed();
}
info!("Stopped feeding, device will reset in 1.05 seconds");
// Blink 10 times per second, not feeding the watchdog.
// The processor should reset in 1.05 seconds.
loop {
led.set_low();
Timer::after_millis(100).await;
led.set_high();
Timer::after_millis(100).await;
}
}
|