From 8977c4e764688917689f1c2ac427d4cddcbe0515 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 17 Nov 2022 18:42:14 -0500 Subject: [PATCH] rp2040: Fix watchdog enable The rp2040 watchdog does not actually reset anything by default. The psm_hw->wdsel field must be programmed to actually get a reset on a watchdog failure. Program that field so the watchdog is usable. Also, disable the watchdog before attempting a reboot into the bootloader. Otherwise the machine may just reboot a second time due to a missed watchdog event in the bootloader. Signed-off-by: Kevin O'Connor --- src/rp2040/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rp2040/main.c b/src/rp2040/main.c index eac3a0b9..c14e2759 100644 --- a/src/rp2040/main.c +++ b/src/rp2040/main.c @@ -9,6 +9,7 @@ #include "generic/armcm_reset.h" // try_request_canboot #include "hardware/structs/clocks.h" // clock_hw_t #include "hardware/structs/pll.h" // pll_hw_t +#include "hardware/structs/psm.h" // psm_hw #include "hardware/structs/resets.h" // sio_hw #include "hardware/structs/watchdog.h" // watchdog_hw #include "hardware/structs/xosc.h" // xosc_hw @@ -30,6 +31,7 @@ DECL_TASK(watchdog_reset); void watchdog_init(void) { + psm_hw->wdsel = PSM_WDSEL_BITS & ~(PSM_WDSEL_ROSC_BITS|PSM_WDSEL_XOSC_BITS); watchdog_reset(); watchdog_hw->ctrl = (WATCHDOG_CTRL_PAUSE_DBG0_BITS | WATCHDOG_CTRL_PAUSE_DBG1_BITS @@ -46,6 +48,7 @@ DECL_INIT(watchdog_init); void bootloader_request(void) { + watchdog_hw->ctrl = 0; try_request_canboot(); // Use the bootrom-provided code to reset into BOOTSEL mode reset_to_usb_boot(0, 0);