Rework safe mode so we can trigger on all resets
This commit is contained in:
parent
837d3f57ee
commit
b87565138e
@ -63,17 +63,11 @@ void common_hal_mcu_enable_interrupts(void) {
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
static mcu_runmode_t next_reset;
|
||||
|
||||
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
|
||||
if (runmode == RUNMODE_BOOTLOADER && !bootloader_available()) {
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present."));
|
||||
}
|
||||
next_reset = runmode;
|
||||
}
|
||||
|
||||
void common_hal_mcu_reset(void) {
|
||||
if (next_reset == RUNMODE_BOOTLOADER) {
|
||||
if (runmode == RUNMODE_BOOTLOADER) {
|
||||
if (!bootloader_available()) {
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present."));
|
||||
}
|
||||
// Pretend to be the first of the two reset presses needed to enter the
|
||||
// bootloader. That way one reset will end in the bootloader.
|
||||
_bootloader_dbl_tap = DBL_TAP_MAGIC;
|
||||
@ -81,11 +75,12 @@ void common_hal_mcu_reset(void) {
|
||||
// Set up the default.
|
||||
_bootloader_dbl_tap = DBL_TAP_MAGIC_QUICK_BOOT;
|
||||
}
|
||||
|
||||
if (next_reset == RUNMODE_SAFE_MODE) {
|
||||
reset_into_safe_mode(PROGRAMMATIC_SAFE_MODE);
|
||||
return; // Doesn't actually return but it's here to make it clear.
|
||||
if (runmode == RUNMODE_SAFE_MODE) {
|
||||
safe_mode_on_next_reset(PROGRAMMATIC_SAFE_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
void common_hal_mcu_reset(void) {
|
||||
reset();
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,10 @@ safe_mode_t wait_for_safe_mode_reset(void) {
|
||||
return NO_SAFE_MODE;
|
||||
}
|
||||
|
||||
void safe_mode_on_next_reset(safe_mode_t reason) {
|
||||
port_set_saved_word(SAFE_MODE_DATA_GUARD | (reason << 8));
|
||||
}
|
||||
|
||||
// Don't inline this so it's easy to break on it from GDB.
|
||||
void __attribute__((noinline,)) reset_into_safe_mode(safe_mode_t reason) {
|
||||
if (current_safe_mode > BROWNOUT && reason > BROWNOUT) {
|
||||
@ -85,7 +89,7 @@ void __attribute__((noinline,)) reset_into_safe_mode(safe_mode_t reason) {
|
||||
}
|
||||
}
|
||||
|
||||
port_set_saved_word(SAFE_MODE_DATA_GUARD | (reason << 8));
|
||||
safe_mode_on_next_reset(reason);
|
||||
reset_cpu();
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ typedef enum {
|
||||
|
||||
safe_mode_t wait_for_safe_mode_reset(void);
|
||||
|
||||
void safe_mode_on_next_reset(safe_mode_t reason);
|
||||
void reset_into_safe_mode(safe_mode_t reason);
|
||||
|
||||
void print_safe_mode_message(safe_mode_t reason);
|
||||
|
Loading…
x
Reference in New Issue
Block a user