Skip to content

Commit 73ad78e

Browse files
authored
Merge pull request #3395 from microDev1/safeMode
Add esp32s2 safe mode support & fix user_safe_mode output
2 parents a81a2cf + 506bb09 commit 73ad78e

File tree

13 files changed

+116
-82
lines changed

13 files changed

+116
-82
lines changed

locale/circuitpython.pot

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-09-09 14:33-0700\n"
11+
"POT-Creation-Date: 2020-09-13 22:53+0530\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -30,12 +30,6 @@ msgid ""
3030
"https://github.com/adafruit/circuitpython/issues\n"
3131
msgstr ""
3232

33-
#: supervisor/shared/safe_mode.c
34-
msgid ""
35-
"\n"
36-
"To exit, please reset the board without "
37-
msgstr ""
38-
3933
#: py/obj.c
4034
msgid " File \"%q\""
4135
msgstr ""
@@ -1605,6 +1599,10 @@ msgid ""
16051599
"Timer was reserved for internal use - declare PWM pins earlier in the program"
16061600
msgstr ""
16071601

1602+
#: supervisor/shared/safe_mode.c
1603+
msgid "To exit, please reset the board without "
1604+
msgstr ""
1605+
16081606
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
16091607
msgid "Too many channels in sample."
16101608
msgstr ""

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define CALIBRATE_CRYSTALLESS 1
2626

2727
// Explanation of how a user got into safe mode.
28-
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
28+
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
2929

3030
// Increase stack size slightly due to CPX library import nesting
3131
#define CIRCUITPY_DEFAULT_STACK_SIZE (4248) //divisible by 8

ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#define USER_NEOPIXELS_PIN (&pin_PB23)
2828

2929
// Explanation of how a user got into safe mode.
30-
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
30+
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
3131

3232
// Increase stack size slightly due to CPX library import nesting
3333
#define CIRCUITPY_DEFAULT_STACK_SIZE (4248) // divisible by 8

ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define CALIBRATE_CRYSTALLESS 1
2626

2727
// Explanation of how a user got into safe mode.
28-
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
28+
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
2929

3030
// Increase stack size slightly due to CPX library import nesting.
3131
#define CIRCUITPY_DEFAULT_STACK_SIZE (4248) // divisible by 8

ports/atmel-samd/boards/escornabot_makech/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define CALIBRATE_CRYSTALLESS 1
1212

1313
// Explanation of how a user got into safe mode.
14-
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
14+
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
1515

1616
#define DEFAULT_I2C_BUS_SCL (&pin_PA08)
1717
#define DEFAULT_I2C_BUS_SDA (&pin_PA09)

ports/atmel-samd/boards/meowmeow/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define CALIBRATE_CRYSTALLESS 1
1212

1313
// Explanation of how a user got into safe mode.
14-
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
14+
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up.\n"
1515

1616
#define DEFAULT_I2C_BUS_SCL (&pin_PA01)
1717
#define DEFAULT_I2C_BUS_SDA (&pin_PA00)

ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@
2929
#define MICROPY_HW_BOARD_NAME "BastWiFi"
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

32+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
33+
34+
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
35+
3236
#define AUTORESET_DELAY_MS 500

ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@
3131

3232
#define MICROPY_HW_NEOPIXEL (&pin_GPIO45)
3333

34+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
35+
36+
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
37+
3438
#define AUTORESET_DELAY_MS 500

ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@
3131

3232
#define MICROPY_HW_NEOPIXEL (&pin_GPIO18)
3333

34+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
35+
36+
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
37+
3438
#define AUTORESET_DELAY_MS 500

ports/esp32s2/boards/espressif_saola_1_wrover/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@
3131

3232
#define MICROPY_HW_NEOPIXEL (&pin_GPIO18)
3333

34+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
35+
36+
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
37+
3438
#define AUTORESET_DELAY_MS 500

ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@
3232
#define MICROPY_HW_LED (&pin_GPIO21)
3333
#define MICROPY_HW_NEOPIXEL (&pin_GPIO33)
3434

35+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
36+
37+
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
38+
3539
#define AUTORESET_DELAY_MS 500

ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#define MICROPY_HW_BOARD_NAME "FeatherS2"
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

32+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
33+
34+
#define BOARD_USER_SAFE_MODE_ACTION "pressing boot button at start up.\n"
35+
3236
#define AUTORESET_DELAY_MS 500
3337

3438
// Doesn't work with this on.

supervisor/shared/safe_mode.c

Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ safe_mode_t wait_for_safe_mode_reset(void) {
6060
common_hal_digitalio_digitalinout_construct(&status_led, MICROPY_HW_LED_STATUS);
6161
common_hal_digitalio_digitalinout_switch_to_output(&status_led, true, DRIVE_MODE_PUSH_PULL);
6262
#endif
63+
#ifdef CIRCUITPY_BOOT_BUTTON
64+
digitalio_digitalinout_obj_t boot_button;
65+
common_hal_digitalio_digitalinout_construct(&boot_button, CIRCUITPY_BOOT_BUTTON);
66+
common_hal_digitalio_digitalinout_switch_to_input(&boot_button, PULL_UP);
67+
#endif
6368
uint64_t start_ticks = supervisor_ticks_ms64();
6469
uint64_t diff = 0;
6570
while (diff < 700) {
6671
#ifdef MICROPY_HW_LED_STATUS
6772
// Blink on for 100, off for 100, on for 100, off for 100 and on for 200
6873
common_hal_digitalio_digitalinout_set_value(&status_led, diff > 100 && diff / 100 != 2 && diff / 100 != 4);
6974
#endif
75+
#ifdef CIRCUITPY_BOOT_BUTTON
76+
if (!common_hal_digitalio_digitalinout_get_value(&boot_button)) {
77+
return USER_SAFE_MODE;
78+
}
79+
#endif
7080
diff = supervisor_ticks_ms64() - start_ticks;
7181
}
7282
#ifdef MICROPY_HW_LED_STATUS
@@ -103,77 +113,79 @@ void print_safe_mode_message(safe_mode_t reason) {
103113
return;
104114
}
105115
serial_write("\n");
106-
// Output a user safe mode string if it's set.
107-
#ifdef BOARD_USER_SAFE_MODE
108-
if (reason == USER_SAFE_MODE) {
109-
serial_write_compressed(translate("You requested starting safe mode by "));
110-
serial_write(BOARD_USER_SAFE_MODE_ACTION);
111-
serial_write_compressed(translate("\nTo exit, please reset the board without "));
112-
serial_write(BOARD_USER_SAFE_MODE_ACTION);
113-
serial_write("\n");
114-
} else
115-
#endif
116-
switch (reason) {
117-
case MANUAL_SAFE_MODE:
118-
serial_write_compressed(translate("CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.\n"));
119-
return;
120-
case PROGRAMMATIC_SAFE_MODE:
121-
serial_write_compressed(translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.\n"));
122-
return;
123-
default:
124-
break;
125-
}
126116

127-
serial_write_compressed(translate("You are in safe mode: something unanticipated happened.\n"));
128-
switch (reason) {
129-
case BROWNOUT:
130-
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"));
131-
return;
132-
case HEAP_OVERWRITTEN:
133-
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:"));
134-
serial_write_compressed(FILE_AN_ISSUE);
135-
return;
136-
case NO_HEAP:
137-
serial_write_compressed(translate("CircuitPython was unable to allocate the heap.\n"));
138-
serial_write_compressed(FILE_AN_ISSUE);
139-
return;
140-
default:
117+
switch (reason) {
118+
case USER_SAFE_MODE:
119+
#ifdef BOARD_USER_SAFE_MODE_ACTION
120+
// Output a user safe mode string if it's set.
121+
serial_write_compressed(translate("You requested starting safe mode by "));
122+
serial_write_compressed(translate(BOARD_USER_SAFE_MODE_ACTION));
123+
serial_write_compressed(translate("To exit, please reset the board without "));
124+
serial_write_compressed(translate(BOARD_USER_SAFE_MODE_ACTION));
125+
#else
141126
break;
142-
}
127+
#endif
128+
return;
129+
case MANUAL_SAFE_MODE:
130+
serial_write_compressed(translate("CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.\n"));
131+
return;
132+
case PROGRAMMATIC_SAFE_MODE:
133+
serial_write_compressed(translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.\n"));
134+
return;
135+
default:
136+
break;
137+
}
143138

144-
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
145-
switch (reason) {
146-
case HARD_CRASH:
147-
serial_write_compressed(translate("Crash into the HardFault_Handler."));
148-
return;
149-
case MICROPY_NLR_JUMP_FAIL:
150-
serial_write_compressed(translate("MicroPython NLR jump failed. Likely memory corruption."));
151-
return;
152-
case MICROPY_FATAL_ERROR:
153-
serial_write_compressed(translate("MicroPython fatal error."));
154-
break;
155-
case GC_ALLOC_OUTSIDE_VM:
156-
serial_write_compressed(translate("Attempted heap allocation when MicroPython VM not running."));
157-
break;
158-
#ifdef SOFTDEVICE_PRESENT
159-
// defined in ports/nrf/bluetooth/bluetooth_common.mk
160-
// will print "Unknown reason" if somehow encountered on other ports
161-
case NORDIC_SOFT_DEVICE_ASSERT:
162-
serial_write_compressed(translate("Nordic Soft Device failure assertion."));
163-
break;
164-
#endif
165-
case FLASH_WRITE_FAIL:
166-
serial_write_compressed(translate("Failed to write internal flash."));
167-
break;
168-
case MEM_MANAGE:
169-
serial_write_compressed(translate("Invalid memory access."));
170-
break;
171-
case WATCHDOG_RESET:
172-
serial_write_compressed(translate("Watchdog timer expired."));
173-
break;
174-
default:
175-
serial_write_compressed(translate("Unknown reason."));
176-
break;
177-
}
178-
serial_write_compressed(FILE_AN_ISSUE);
139+
serial_write_compressed(translate("You are in safe mode: something unanticipated happened.\n"));
140+
switch (reason) {
141+
case BROWNOUT:
142+
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"));
143+
return;
144+
case HEAP_OVERWRITTEN:
145+
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:"));
146+
serial_write_compressed(FILE_AN_ISSUE);
147+
return;
148+
case NO_HEAP:
149+
serial_write_compressed(translate("CircuitPython was unable to allocate the heap.\n"));
150+
serial_write_compressed(FILE_AN_ISSUE);
151+
return;
152+
default:
153+
break;
154+
}
155+
156+
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
157+
switch (reason) {
158+
case HARD_CRASH:
159+
serial_write_compressed(translate("Crash into the HardFault_Handler."));
160+
return;
161+
case MICROPY_NLR_JUMP_FAIL:
162+
serial_write_compressed(translate("MicroPython NLR jump failed. Likely memory corruption."));
163+
return;
164+
case MICROPY_FATAL_ERROR:
165+
serial_write_compressed(translate("MicroPython fatal error."));
166+
break;
167+
case GC_ALLOC_OUTSIDE_VM:
168+
serial_write_compressed(translate("Attempted heap allocation when MicroPython VM not running."));
169+
break;
170+
#ifdef SOFTDEVICE_PRESENT
171+
// defined in ports/nrf/bluetooth/bluetooth_common.mk
172+
// will print "Unknown reason" if somehow encountered on other ports
173+
case NORDIC_SOFT_DEVICE_ASSERT:
174+
serial_write_compressed(translate("Nordic Soft Device failure assertion."));
175+
break;
176+
#endif
177+
case FLASH_WRITE_FAIL:
178+
serial_write_compressed(translate("Failed to write internal flash."));
179+
break;
180+
case MEM_MANAGE:
181+
serial_write_compressed(translate("Invalid memory access."));
182+
break;
183+
case WATCHDOG_RESET:
184+
serial_write_compressed(translate("Watchdog timer expired."));
185+
break;
186+
default:
187+
serial_write_compressed(translate("Unknown reason."));
188+
break;
189+
}
190+
serial_write_compressed(FILE_AN_ISSUE);
179191
}

0 commit comments

Comments
 (0)