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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-11-17 18:42:14 -05:00
parent b9a378c1ca
commit 8977c4e764
1 changed files with 3 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#include "generic/armcm_reset.h" // try_request_canboot #include "generic/armcm_reset.h" // try_request_canboot
#include "hardware/structs/clocks.h" // clock_hw_t #include "hardware/structs/clocks.h" // clock_hw_t
#include "hardware/structs/pll.h" // pll_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/resets.h" // sio_hw
#include "hardware/structs/watchdog.h" // watchdog_hw #include "hardware/structs/watchdog.h" // watchdog_hw
#include "hardware/structs/xosc.h" // xosc_hw #include "hardware/structs/xosc.h" // xosc_hw
@ -30,6 +31,7 @@ DECL_TASK(watchdog_reset);
void void
watchdog_init(void) watchdog_init(void)
{ {
psm_hw->wdsel = PSM_WDSEL_BITS & ~(PSM_WDSEL_ROSC_BITS|PSM_WDSEL_XOSC_BITS);
watchdog_reset(); watchdog_reset();
watchdog_hw->ctrl = (WATCHDOG_CTRL_PAUSE_DBG0_BITS watchdog_hw->ctrl = (WATCHDOG_CTRL_PAUSE_DBG0_BITS
| WATCHDOG_CTRL_PAUSE_DBG1_BITS | WATCHDOG_CTRL_PAUSE_DBG1_BITS
@ -46,6 +48,7 @@ DECL_INIT(watchdog_init);
void void
bootloader_request(void) bootloader_request(void)
{ {
watchdog_hw->ctrl = 0;
try_request_canboot(); try_request_canboot();
// Use the bootrom-provided code to reset into BOOTSEL mode // Use the bootrom-provided code to reset into BOOTSEL mode
reset_to_usb_boot(0, 0); reset_to_usb_boot(0, 0);