12.9. Watchdog

12.9.1. Overview

The watchdog is a countdown timer which can be configured to reset selected components when it reaches zero. In normal operation it is periodically loaded with a non-zero value to prevent the reset occurring. If the chip locks up or software gets stuck in a loop, the reset allows recovery.

The watchdog is reset by any chip-level reset (see Section 7.3 ). The sources of the chip-level reset are:

These are described in Section 7.3.3 .

12.9.2. Changes from RP2040

On RP2040, the watchdog contained a tick generator used to generate a 1µs tick for the watchdog. This was also distributed to the system timer. On RP2350, the watchdog instead takes a tick input from the system-level ticks block. See Section 8.5 .

As on RP2040 the watchdog can trigger a PSM (Power-on State Machine) sequence to reset system components or it can be used to reset selected subsystem components. On RP2350, the watchdog can also trigger a chip level reset.

12.9.3. Watchdog counter

The watchdog counter is loaded by the LOAD register. The current value can be seen in CTRL.TIME .

12.9.4. Control watchdog reset levels

To control the level of reset triggered by a watchdog event, use the registers outside the watchdog register block:

These are described in the Resets section, see Chapter 7 .

12.9.5. Scratch registers

The watchdog contains eight 32-bit scratch registers that can store information between soft resets of the chip. The scratch registers reset when:

The bootrom checks the watchdog scratch registers for a magic number on boot. You can use this to soft reset the chip into user-specified code. See Section 5.2.4 for more information.

NOTE

Additional general-purpose scratch registers are available in POWMAN SCRATCH0 through SCRATCH7. These registers also survive power cycling the switched core domain.

12.9.6. Programmer's model

The SDK provides a hardware_watchdog driver to control the watchdog.

12.9.6.1. Enabling the watchdog

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_watchdog/watchdog.c Lines 47 - 76

47 // Helper function used by both watchdog_enable and watchdog_reboot
48 void _watchdog_enable(uint32_t delay_ms, bool pause_on_debug) {
49     valid_params_if(HARDWARE_WATCHDOG, delay_ms <= WATCHDOG_LOAD_BITS / (1000 *
        WATCHDOG_XFACTOR));
50     hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);
51
52     // Reset everything apart from ROSC and XOSC
53     hw_set_bits(&psm_hw->wdsel, PSM_WDSEL_BITS & ~(PSM_WDSEL_ROSC_BITS |
        PSM_WDSEL_XOSC_BITS));
54
55     uint32_t dbg_bits = WATCHDOG_CTRL_PAUSE_DBG0_BITS |
56                         WATCHDOG_CTRL_PAUSE_DBG1_BITS |
57                         WATCHDOG_CTRL_PAUSE_JTAG_BITS;
58
59     if (pause_on_debug) {
60         hw_set_bits(&watchdog_hw->ctrl, dbg_bits);
61     } else {
62         hw_clear_bits(&watchdog_hw->ctrl, dbg_bits);
63     }
64
65     if (!delay_ms) {
66         hw_set_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_TRIGGER_BITS);
67     } else {
68         load_value = delay_ms * (1000 * WATCHDOG_XFACTOR);
69         if (load_value > WATCHDOG_LOAD_BITS)
70             load_value = WATCHDOG_LOAD_BITS;
71
72         watchdog_update();
73
74         hw_set_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);
75     }
76 }

12.9.6.2. Updating the watchdog counter

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2-common/hardware_watchdog/watchdog.c Lines 24 - 28

24 static uint32_t load_value;
25
26 void watchdog_update(void) {
27     watchdog_hw->load = load_value;
28 }

12.9.6.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/blob/master/watchdog/hello_watchdog/hello_watchdog.c Lines 11 - 33

11 int main() {
12     stdio_init_all();
13
14     if (watchdog_enable_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");
32     while(1);
33 }

12.9.7. List of registers

The watchdog registers start at a base address of 0x400d8000(defined as WATCHDOG_BASE in SDK).

Table 1247. List of
WATCHDOG registers

OffsetNameInfo
0x00CTRLWatchdog control
The rst_wdsel register determines which subsystems are reset when the watchdog is triggered.
The watchdog can be triggered in software.
0x04LOADLoad the watchdog timer. The maximum setting is 0xfffff which corresponds to approximately 16 seconds.
0x08REASONLogs the reason for the last reset. Both bits are zero for the case of a hardware reset.

Additionally, as of RP2350, a debugger warm reset of either core ( SYSRESETREQ or hartreset) will also clear the watchdog reason register, so that software loaded under the debugger following a watchdog timeout will not continue to see the timeout condition.
0x0cSCRATCH0Scratch register. Information persists through soft reset of the chip.
0x10SCRATCH1Scratch register. Information persists through soft reset of the chip.
0x14SCRATCH2Scratch register. Information persists through soft reset of the chip.
0x18SCRATCH3Scratch register. Information persists through soft reset of the chip.
0x1cSCRATCH4Scratch register. Information persists through soft reset of the chip.
0x20SCRATCH5Scratch register. Information persists through soft reset of the chip.
0x24SCRATCH6Scratch register. Information persists through soft reset of the chip.
0x28SCRATCH7Scratch register. Information persists through soft reset of the chip.

WATCHDOG: CTRL Register

Offset: 0x00

Description

Watchdog control

The rst_wdsel register determines which subsystems are reset when the watchdog is triggered.

The watchdog can be triggered in software.

Table 1248. CTRL
Register

BitsDescriptionTypeReset
31TRIGGER: Trigger a watchdog resetSC0x0
30ENABLE: When not enabled the watchdog timer is pausedRW0x0
29:27Reserved.--
26PAUSE_DBG1: Pause the watchdog timer when processor 1 is in debug modeRW0x1
BitsDescriptionTypeReset
25PAUSE_DBG0 : Pause the watchdog timer when processor 0 is in debug modeRW0x1
24PAUSE_JTAG : Pause the watchdog timer when JTAG is accessing the bus fabricRW0x1
23:0TIME : Indicates the time in usec before a watchdog reset will be triggeredRO0x000000

WATCHDOG: LOAD Register

Offset: 0x04

Table 1249. LOAD Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Load the watchdog timer. The maximum setting is 0xfffff which corresponds to approximately 16 seconds.WF0x000000

WATCHDOG: REASON Register

Offset: 0x08

Description

Logs the reason for the last reset. Both bits are zero for the case of a hardware reset.

Additionally, as of RP2350, a debugger warm reset of either core (SYSRESETREQ or hartreset) will also clear the watchdog reason register, so that software loaded under the debugger following a watchdog timeout will not continue to see the timeout condition.

Table 1250. REASON Register

BitsDescriptionTypeReset
31:2Reserved.--
1FORCERO0x0
0TIMERRO0x0

WATCHDOG: SCRATCH0, SCRATCH1, ..., SCRATCH6, SCRATCH7 Registers

Offsets: 0x0c, 0x10, ..., 0x24, 0x28

Table 1251. SCRATCH0, SCRATCH1, ..., SCRATCH6, SCRATCH7 Registers

BitsDescriptionTypeReset
31:0Scratch register. Information persists through soft reset of the chip.RW0x00000000