Added esp32s2 safe_mode & fixed user_safe_mode
This commit is contained in:
parent
9256e6b376
commit
305bed6d9e
|
@ -31,4 +31,8 @@
|
|||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_GPIO18)
|
||||
|
||||
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
|
||||
|
||||
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up."
|
||||
|
||||
#define AUTORESET_DELAY_MS 500
|
||||
|
|
|
@ -31,4 +31,8 @@
|
|||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_GPIO18)
|
||||
|
||||
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
|
||||
|
||||
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up."
|
||||
|
||||
#define AUTORESET_DELAY_MS 500
|
||||
|
|
|
@ -32,4 +32,8 @@
|
|||
#define MICROPY_HW_LED (&pin_GPIO21)
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_GPIO33)
|
||||
|
||||
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
|
||||
|
||||
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up."
|
||||
|
||||
#define AUTORESET_DELAY_MS 500
|
||||
|
|
|
@ -60,6 +60,11 @@ safe_mode_t wait_for_safe_mode_reset(void) {
|
|||
common_hal_digitalio_digitalinout_construct(&status_led, MICROPY_HW_LED_STATUS);
|
||||
common_hal_digitalio_digitalinout_switch_to_output(&status_led, true, DRIVE_MODE_PUSH_PULL);
|
||||
#endif
|
||||
#ifdef CIRCUITPY_BOOT_BUTTON
|
||||
digitalio_digitalinout_obj_t boot_button;
|
||||
common_hal_digitalio_digitalinout_construct(&boot_button, CIRCUITPY_BOOT_BUTTON);
|
||||
common_hal_digitalio_digitalinout_switch_to_input(&boot_button, PULL_UP);
|
||||
#endif
|
||||
uint64_t start_ticks = supervisor_ticks_ms64();
|
||||
uint64_t diff = 0;
|
||||
while (diff < 700) {
|
||||
|
@ -67,6 +72,11 @@ safe_mode_t wait_for_safe_mode_reset(void) {
|
|||
// Blink on for 100, off for 100, on for 100, off for 100 and on for 200
|
||||
common_hal_digitalio_digitalinout_set_value(&status_led, diff > 100 && diff / 100 != 2 && diff / 100 != 4);
|
||||
#endif
|
||||
#ifdef CIRCUITPY_BOOT_BUTTON
|
||||
if (!common_hal_digitalio_digitalinout_get_value(&boot_button)) {
|
||||
return USER_SAFE_MODE;
|
||||
}
|
||||
#endif
|
||||
diff = supervisor_ticks_ms64() - start_ticks;
|
||||
}
|
||||
#ifdef MICROPY_HW_LED_STATUS
|
||||
|
@ -103,77 +113,80 @@ void print_safe_mode_message(safe_mode_t reason) {
|
|||
return;
|
||||
}
|
||||
serial_write("\n");
|
||||
// Output a user safe mode string if it's set.
|
||||
#ifdef BOARD_USER_SAFE_MODE
|
||||
if (reason == USER_SAFE_MODE) {
|
||||
serial_write_compressed(translate("You requested starting safe mode by "));
|
||||
serial_write(BOARD_USER_SAFE_MODE_ACTION);
|
||||
serial_write_compressed(translate("\nTo exit, please reset the board without "));
|
||||
serial_write(BOARD_USER_SAFE_MODE_ACTION);
|
||||
serial_write("\n");
|
||||
} else
|
||||
#endif
|
||||
switch (reason) {
|
||||
case MANUAL_SAFE_MODE:
|
||||
serial_write_compressed(translate("CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.\n"));
|
||||
return;
|
||||
case PROGRAMMATIC_SAFE_MODE:
|
||||
serial_write_compressed(translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.\n"));
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
serial_write_compressed(translate("You are in safe mode: something unanticipated happened.\n"));
|
||||
switch (reason) {
|
||||
case BROWNOUT:
|
||||
serial_write_compressed(translate("The microcontroller's power dipped. Make sure your power supply provides\nenough power for the whole circuit and press reset (after ejecting CIRCUITPY).\n"));
|
||||
return;
|
||||
case HEAP_OVERWRITTEN:
|
||||
serial_write_compressed(translate("The CircuitPython heap was corrupted because the stack was too small.\nPlease increase the stack size if you know how, or if not:"));
|
||||
serial_write_compressed(FILE_AN_ISSUE);
|
||||
return;
|
||||
case NO_HEAP:
|
||||
serial_write_compressed(translate("CircuitPython was unable to allocate the heap.\n"));
|
||||
serial_write_compressed(FILE_AN_ISSUE);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (reason) {
|
||||
case USER_SAFE_MODE:
|
||||
#ifdef BOARD_USER_SAFE_MODE_ACTION
|
||||
// Output a user safe mode string if it's set.
|
||||
serial_write_compressed(translate("You requested starting safe mode by "));
|
||||
serial_write_compressed(translate(BOARD_USER_SAFE_MODE_ACTION));
|
||||
serial_write_compressed(translate("\nTo exit, please reset the board without "));
|
||||
serial_write_compressed(translate(BOARD_USER_SAFE_MODE_ACTION));
|
||||
serial_write("\n");
|
||||
#else
|
||||
// fallthrough
|
||||
#endif
|
||||
return;
|
||||
case MANUAL_SAFE_MODE:
|
||||
serial_write_compressed(translate("CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.\n"));
|
||||
return;
|
||||
case PROGRAMMATIC_SAFE_MODE:
|
||||
serial_write_compressed(translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.\n"));
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
|
||||
switch (reason) {
|
||||
case HARD_CRASH:
|
||||
serial_write_compressed(translate("Crash into the HardFault_Handler."));
|
||||
return;
|
||||
case MICROPY_NLR_JUMP_FAIL:
|
||||
serial_write_compressed(translate("MicroPython NLR jump failed. Likely memory corruption."));
|
||||
return;
|
||||
case MICROPY_FATAL_ERROR:
|
||||
serial_write_compressed(translate("MicroPython fatal error."));
|
||||
break;
|
||||
case GC_ALLOC_OUTSIDE_VM:
|
||||
serial_write_compressed(translate("Attempted heap allocation when MicroPython VM not running."));
|
||||
break;
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// defined in ports/nrf/bluetooth/bluetooth_common.mk
|
||||
// will print "Unknown reason" if somehow encountered on other ports
|
||||
case NORDIC_SOFT_DEVICE_ASSERT:
|
||||
serial_write_compressed(translate("Nordic Soft Device failure assertion."));
|
||||
break;
|
||||
#endif
|
||||
case FLASH_WRITE_FAIL:
|
||||
serial_write_compressed(translate("Failed to write internal flash."));
|
||||
break;
|
||||
case MEM_MANAGE:
|
||||
serial_write_compressed(translate("Invalid memory access."));
|
||||
break;
|
||||
case WATCHDOG_RESET:
|
||||
serial_write_compressed(translate("Watchdog timer expired."));
|
||||
break;
|
||||
default:
|
||||
serial_write_compressed(translate("Unknown reason."));
|
||||
break;
|
||||
}
|
||||
serial_write_compressed(FILE_AN_ISSUE);
|
||||
serial_write_compressed(translate("You are in safe mode: something unanticipated happened.\n"));
|
||||
switch (reason) {
|
||||
case BROWNOUT:
|
||||
serial_write_compressed(translate("The microcontroller's power dipped. Make sure your power supply provides\nenough power for the whole circuit and press reset (after ejecting CIRCUITPY).\n"));
|
||||
return;
|
||||
case HEAP_OVERWRITTEN:
|
||||
serial_write_compressed(translate("The CircuitPython heap was corrupted because the stack was too small.\nPlease increase the stack size if you know how, or if not:"));
|
||||
serial_write_compressed(FILE_AN_ISSUE);
|
||||
return;
|
||||
case NO_HEAP:
|
||||
serial_write_compressed(translate("CircuitPython was unable to allocate the heap.\n"));
|
||||
serial_write_compressed(FILE_AN_ISSUE);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
|
||||
switch (reason) {
|
||||
case HARD_CRASH:
|
||||
serial_write_compressed(translate("Crash into the HardFault_Handler."));
|
||||
return;
|
||||
case MICROPY_NLR_JUMP_FAIL:
|
||||
serial_write_compressed(translate("MicroPython NLR jump failed. Likely memory corruption."));
|
||||
return;
|
||||
case MICROPY_FATAL_ERROR:
|
||||
serial_write_compressed(translate("MicroPython fatal error."));
|
||||
break;
|
||||
case GC_ALLOC_OUTSIDE_VM:
|
||||
serial_write_compressed(translate("Attempted heap allocation when MicroPython VM not running."));
|
||||
break;
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// defined in ports/nrf/bluetooth/bluetooth_common.mk
|
||||
// will print "Unknown reason" if somehow encountered on other ports
|
||||
case NORDIC_SOFT_DEVICE_ASSERT:
|
||||
serial_write_compressed(translate("Nordic Soft Device failure assertion."));
|
||||
break;
|
||||
#endif
|
||||
case FLASH_WRITE_FAIL:
|
||||
serial_write_compressed(translate("Failed to write internal flash."));
|
||||
break;
|
||||
case MEM_MANAGE:
|
||||
serial_write_compressed(translate("Invalid memory access."));
|
||||
break;
|
||||
case WATCHDOG_RESET:
|
||||
serial_write_compressed(translate("Watchdog timer expired."));
|
||||
break;
|
||||
default:
|
||||
serial_write_compressed(translate("Unknown reason."));
|
||||
break;
|
||||
}
|
||||
serial_write_compressed(FILE_AN_ISSUE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue