Skip to content

Commit 82a3130

Browse files
committed
Tweak RP2040 reset reason
Watchdogs are used to reboot out of the bootloader. There is a scratch register for user watchdogs. So use sdk functions to better distinguish these. Related to #7346
1 parent 79b76f7 commit 82a3130

File tree

1 file changed

+7
-6
lines changed
  • ports/raspberrypi/common-hal/microcontroller

1 file changed

+7
-6
lines changed

ports/raspberrypi/common-hal/microcontroller/Processor.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "src/rp2_common/hardware_adc/include/hardware/adc.h"
3636
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
37+
#include "src/rp2_common/hardware_watchdog/include/hardware/watchdog.h"
3738

3839
#include "src/rp2040/hardware_regs/include/hardware/regs/vreg_and_chip_reset.h"
3940
#include "src/rp2040/hardware_regs/include/hardware/regs/watchdog.h"
@@ -68,7 +69,6 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
6869
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
6970
mcu_reset_reason_t reason = RESET_REASON_UNKNOWN;
7071

71-
uint32_t watchdog_reset_reg = watchdog_hw->reason;
7272
uint32_t chip_reset_reg = vreg_and_chip_reset_hw->chip_reset;
7373

7474
if (chip_reset_reg & VREG_AND_CHIP_RESET_CHIP_RESET_HAD_PSM_RESTART_BITS) {
@@ -86,13 +86,14 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
8686

8787
// Check watchdog after chip reset since watchdog doesn't clear chip_reset, while chip_reset clears the watchdog
8888

89-
if (watchdog_reset_reg & WATCHDOG_REASON_TIMER_BITS) {
90-
// This bit can also be set during a software reset because the pico-sdk performs a software reset by setting an extremely low timeout on the watchdog, rather than triggering a watchdog reset manually
91-
reason = RESET_REASON_WATCHDOG;
89+
// The watchdog is used for software reboots such as resetting after copying a UF2 via the bootloader.
90+
if (watchdog_caused_reboot()) {
91+
reason = RESET_REASON_SOFTWARE;
9292
}
9393

94-
if (watchdog_reset_reg & WATCHDOG_REASON_FORCE_BITS) {
95-
reason = RESET_REASON_SOFTWARE;
94+
// Actual watchdog usage will set a special value that this function detects.
95+
if (watchdog_enable_caused_reboot()) {
96+
reason = RESET_REASON_WATCHDOG;
9697
}
9798

9899
return reason;

0 commit comments

Comments
 (0)