Merge pull request #3395 from microDev1/safeMode

Add esp32s2 safe mode support & fix user_safe_mode output
This commit is contained in:
Jeff Epler 2020-09-13 14:18:59 -05:00 committed by GitHub
commit 73ad78ed1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 116 additions and 82 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-09-09 14:33-0700\n"
"POT-Creation-Date: 2020-09-13 22:53+0530\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -30,12 +30,6 @@ msgid ""
"https://github.com/adafruit/circuitpython/issues\n"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"\n"
"To exit, please reset the board without "
msgstr ""
#: py/obj.c
msgid " File \"%q\""
msgstr ""
@ -1605,6 +1599,10 @@ msgid ""
"Timer was reserved for internal use - declare PWM pins earlier in the program"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid "To exit, please reset the board without "
msgstr ""
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
msgid "Too many channels in sample."
msgstr ""

View File

@ -25,7 +25,7 @@
#define CALIBRATE_CRYSTALLESS 1
// Explanation of how a user got into safe mode.
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
// Increase stack size slightly due to CPX library import nesting
#define CIRCUITPY_DEFAULT_STACK_SIZE (4248) //divisible by 8

View File

@ -27,7 +27,7 @@
#define USER_NEOPIXELS_PIN (&pin_PB23)
// Explanation of how a user got into safe mode.
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
// Increase stack size slightly due to CPX library import nesting
#define CIRCUITPY_DEFAULT_STACK_SIZE (4248) // divisible by 8

View File

@ -25,7 +25,7 @@
#define CALIBRATE_CRYSTALLESS 1
// Explanation of how a user got into safe mode.
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
// Increase stack size slightly due to CPX library import nesting.
#define CIRCUITPY_DEFAULT_STACK_SIZE (4248) // divisible by 8

View File

@ -11,7 +11,7 @@
#define CALIBRATE_CRYSTALLESS 1
// Explanation of how a user got into safe mode.
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
#define DEFAULT_I2C_BUS_SCL (&pin_PA08)
#define DEFAULT_I2C_BUS_SDA (&pin_PA09)

View File

@ -11,7 +11,7 @@
#define CALIBRATE_CRYSTALLESS 1
// Explanation of how a user got into safe mode.
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
#define DEFAULT_I2C_BUS_SCL (&pin_PA01)
#define DEFAULT_I2C_BUS_SDA (&pin_PA00)

View File

@ -29,4 +29,8 @@
#define MICROPY_HW_BOARD_NAME "BastWiFi"
#define MICROPY_HW_MCU_NAME "ESP32S2"
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
#define AUTORESET_DELAY_MS 500

View File

@ -31,4 +31,8 @@
#define MICROPY_HW_NEOPIXEL (&pin_GPIO45)
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
#define AUTORESET_DELAY_MS 500

View File

@ -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.\n"
#define AUTORESET_DELAY_MS 500

View File

@ -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.\n"
#define AUTORESET_DELAY_MS 500

View File

@ -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.\n"
#define AUTORESET_DELAY_MS 500

View File

@ -29,6 +29,10 @@
#define MICROPY_HW_BOARD_NAME "FeatherS2"
#define MICROPY_HW_MCU_NAME "ESP32S2"
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
#define AUTORESET_DELAY_MS 500
// Doesn't work with this on.

View File

@ -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,79 @@ 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:
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("To exit, please reset the board without "));
serial_write_compressed(translate(BOARD_USER_SAFE_MODE_ACTION));
#else
break;
}
#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);
}