1 parent 8c5df5f commit e738f5eCopy full SHA for e738f5e
1 file changed
ports/nrf/supervisor/port.c
@@ -131,6 +131,21 @@ safe_mode_t port_init(void) {
131
analogin_init();
132
#endif
133
134
+ // If the board was reset by the WatchDogTimer, we may
135
+ // need to boot into safe mode. Reset the RESETREAS bit
136
+ // for the WatchDogTimer so we don't encounter this the
137
+ // next time we reboot.
138
+ if (NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk) {
139
+ NRF_POWER->RESETREAS = POWER_RESETREAS_DOG_Msk;
140
+ uint32_t usb_reg = NRF_POWER->USBREGSTATUS;
141
+
142
+ // If USB is connected, then the user might be editing `code.py`,
143
+ // in which case we should reboot into Safe Mode.
144
+ if (usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk) {
145
+ return WATCHDOG_RESET;
146
+ }
147
148
149
return NO_SAFE_MODE;
150
}
151
0 commit comments