Datasheet

Table Of Contents
48 hw_set_bits(&watchdog_hw->ctrl, dbg_bits);
49 } else {
50 hw_clear_bits(&watchdog_hw->ctrl, dbg_bits);
51 }
52
53 if (!delay_ms) delay_ms = 50;
54
55 if (delay_ms > 0x7fffff)
56 delay_ms = 0x7fffff;
57
58 // Note, we have x2 here as the watchdog HW currently decrements twice per tick
59 load_value = delay_ms * 1000 * 2;
60
61 watchdog_update();
62
63 hw_set_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);
64 }
4.8.5.2. Updating the watchdog counter
Pico SDK: https://github.com/raspberrypi/pico-sdk/tree/pre_release/src/rp2_common/hardware_watchdog/watchdog.c Lines 25 - 28
25 static uint32_t load_value;
26 void watchdog_update(void) {
27 watchdog_hw->load = load_value;
28 }
4.8.5.3. Usage
The Pico Examples repository provides a hello_watchdog example that uses the hardware_watchdog to demonstrate use
of the watchdog.
Pico Examples: https://github.com/raspberrypi/pico-examples/tree/pre_release/watchdog/hello_watchdog/hello_watchdog.c Lines 11 - 33
11 int main() {
12 setup_default_uart();
13
14 if (watchdog_caused_reboot()) {
15 printf("Rebooted by Watchdog!\n");
16 return 0;
17 } else {
18 printf("Clean boot\n");
19 }
20
21 // Enable the watchdog, requiring the watchdog to be updated every 100ms or the chip will
Ê reboot
22 // second arg is pause on debug which means the watchdog will pause when stepping through
Ê code
23 watchdog_enable(100, 1);
24
25 for (uint i = 0; i < 5; i++) {
26 printf("Updating watchdog %d\n", i);
27 watchdog_update();
28 }
29
30 // Wait in an infinite loop and don't update the watchdog so it reboots us
31 printf("Waiting to be rebooted by watchdog\n");
RP2040 Datasheet
4.8. Watchdog 569