summaryrefslogtreecommitdiff
path: root/supervisor
diff options
context:
space:
mode:
authormicroDev <70126934+microDev1@users.noreply.github.com>2020-09-11 21:06:54 +0530
committermicroDev <70126934+microDev1@users.noreply.github.com>2020-09-11 21:06:54 +0530
commit305bed6d9e9581ed19d2043622bc77106a0c3b5b (patch)
tree7f0e5a01d064e1c5cb77746d6758df58e8826dba /supervisor
parent9256e6b376c5a8a6c185e6a4ab25e01987e04445 (diff)
Added esp32s2 safe_mode & fixed user_safe_mode
Diffstat (limited to 'supervisor')
-rw-r--r--supervisor/shared/safe_mode.c155
1 files changed, 84 insertions, 71 deletions
diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c
index 29a0a6a4f..cbbdfe427 100644
--- a/supervisor/shared/safe_mode.c
+++ b/supervisor/shared/safe_mode.c
@@ -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);
}