Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak RP2040 reset reason #7462

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions ports/raspberrypi/common-hal/microcontroller/Processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "src/rp2_common/hardware_adc/include/hardware/adc.h"
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
#include "src/rp2_common/hardware_watchdog/include/hardware/watchdog.h"

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

uint32_t watchdog_reset_reg = watchdog_hw->reason;
uint32_t chip_reset_reg = vreg_and_chip_reset_hw->chip_reset;

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

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

if (watchdog_reset_reg & WATCHDOG_REASON_TIMER_BITS) {
// 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
reason = RESET_REASON_WATCHDOG;
// The watchdog is used for software reboots such as resetting after copying a UF2 via the bootloader.
if (watchdog_caused_reboot()) {
reason = RESET_REASON_SOFTWARE;
}

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

return reason;
Expand Down