diff options
| author | Sean Cross <sean@xobs.io> | 2020-05-22 12:56:49 +0800 |
|---|---|---|
| committer | Sean Cross <sean@xobs.io> | 2020-05-27 11:28:49 +0800 |
| commit | e738f5eaa13c0e30dc082c511d9659c5f35e7f7e (patch) | |
| tree | f60a7c6c56a27b73b1797c1d90a2300fb3ef9786 /ports/nrf | |
| parent | 8c5df5f7329f84c005d217d18148b616f55b942f (diff) | |
nrf: boot into safe mode sometimes for watchdog reset
If the watchdog resets the system and we're plugged into USB, boot into
safe mode.
Signed-off-by: Sean Cross <sean@xobs.io>
Diffstat (limited to 'ports/nrf')
| -rw-r--r-- | ports/nrf/supervisor/port.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 36725293c..89797e6dc 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -131,6 +131,21 @@ safe_mode_t port_init(void) { analogin_init(); #endif + // If the board was reset by the WatchDogTimer, we may + // need to boot into safe mode. Reset the RESETREAS bit + // for the WatchDogTimer so we don't encounter this the + // next time we reboot. + if (NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk) { + NRF_POWER->RESETREAS = POWER_RESETREAS_DOG_Msk; + uint32_t usb_reg = NRF_POWER->USBREGSTATUS; + + // If USB is connected, then the user might be editing `code.py`, + // in which case we should reboot into Safe Mode. + if (usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk) { + return WATCHDOG_RESET; + } + } + return NO_SAFE_MODE; } |
