Skip to content

Commit d46d9d5

Browse files
committed
shorten safe mode messages; improve message printing; fix CIRCUITPY_SAFEMODE_PY=0
1 parent d8231f1 commit d46d9d5

File tree

6 files changed

+88
-89
lines changed

6 files changed

+88
-89
lines changed

locale/circuitpython.pot

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ msgstr ""
3131
#: supervisor/shared/safe_mode.c
3232
msgid ""
3333
"\n"
34-
"Please file an issue with the contents of your CIRCUITPY drive at \n"
35-
"https://github.com/adafruit/circuitpython/issues\n"
34+
"Please file an issue with your program at https://github.com/adafruit/"
35+
"circuitpython/issues."
3636
msgstr ""
3737

3838
#: supervisor/shared/safe_mode.c
3939
msgid ""
4040
"\n"
41-
"To exit, reset the board without requesting safe mode."
41+
"Press reset to exit safe mode.\n"
42+
msgstr ""
43+
44+
#: supervisor/shared/safe_mode.c
45+
msgid ""
46+
"\n"
47+
"You are in safe mode because:\n"
4248
msgstr ""
4349

4450
#: py/obj.c
@@ -536,10 +542,6 @@ msgstr ""
536542
msgid "Attempt to allocate %d blocks"
537543
msgstr ""
538544

539-
#: supervisor/shared/safe_mode.c
540-
msgid "Attempted heap allocation when VM not running."
541-
msgstr ""
542-
543545
#: ports/raspberrypi/audio_dma.c
544546
msgid "Audio conversion not implemented"
545547
msgstr ""
@@ -588,7 +590,7 @@ msgid "Bitmap size and bits per value must match"
588590
msgstr ""
589591

590592
#: supervisor/shared/safe_mode.c
591-
msgid "Boot device must be first device (interface #0)."
593+
msgid "Boot device must be first (interface #0)."
592594
msgstr ""
593595

594596
#: ports/mimxrt10xx/common-hal/busio/UART.c
@@ -790,10 +792,6 @@ msgstr ""
790792
msgid "CircuitPython core code crashed hard. Whoops!\n"
791793
msgstr ""
792794

793-
#: supervisor/shared/safe_mode.c
794-
msgid "CircuitPython was unable to allocate the heap."
795-
msgstr ""
796-
797795
#: shared-module/bitbangio/I2C.c
798796
msgid "Clock stretch too long"
799797
msgstr ""
@@ -832,10 +830,6 @@ msgstr ""
832830
msgid "Couldn't allocate decoder"
833831
msgstr ""
834832

835-
#: supervisor/shared/safe_mode.c
836-
msgid "Crash into the HardFault_Handler."
837-
msgstr ""
838-
839833
#: ports/stm/common-hal/analogio/AnalogOut.c
840834
msgid "DAC Channel Init Error"
841835
msgstr ""
@@ -1003,6 +997,10 @@ msgstr ""
1003997
msgid "Failed to write internal flash."
1004998
msgstr ""
1005999

1000+
#: supervisor/shared/safe_mode.c
1001+
msgid "Fault detected by hardware."
1002+
msgstr ""
1003+
10061004
#: py/moduerrno.c
10071005
msgid "File exists"
10081006
msgstr ""
@@ -1088,6 +1086,15 @@ msgstr ""
10881086
msgid "Hardware in use, try alternative pins"
10891087
msgstr ""
10901088

1089+
#: supervisor/shared/safe_mode.c
1090+
msgid "Heap allocation when VM not running."
1091+
msgstr ""
1092+
1093+
#: supervisor/shared/safe_mode.c
1094+
msgid ""
1095+
"Heap was corrupted because the stack was too small. Increase stack size."
1096+
msgstr ""
1097+
10911098
#: extmod/vfs_posix_file.c py/objstringio.c
10921099
msgid "I/O operation on closed file"
10931100
msgstr ""
@@ -1993,15 +2000,7 @@ msgid "Temperature read timed out"
19932000
msgstr ""
19942001

19952002
#: supervisor/shared/safe_mode.c
1996-
msgid ""
1997-
"The CircuitPython heap was corrupted because the stack was too small.\n"
1998-
"Increase the stack size if you know how. If not:"
1999-
msgstr ""
2000-
2001-
#: supervisor/shared/safe_mode.c
2002-
msgid ""
2003-
"The `microcontroller` module was used to boot into safe mode. Press reset to "
2004-
"exit safe mode."
2003+
msgid "The `microcontroller` module was used to boot into safe mode."
20052004
msgstr ""
20062005

20072006
#: py/obj.c
@@ -2013,10 +2012,7 @@ msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30"
20132012
msgstr ""
20142013

20152014
#: supervisor/shared/safe_mode.c
2016-
msgid ""
2017-
"The microcontroller's power dipped. Make sure your power supply provides\n"
2018-
"enough power for the whole circuit and press reset (after ejecting "
2019-
"CIRCUITPY)."
2015+
msgid "The power dipped. Make sure you are providing enough power."
20202016
msgstr ""
20212017

20222018
#: shared-module/audiomixer/MixerVoice.c
@@ -2162,6 +2158,10 @@ msgstr ""
21622158
msgid "Unable to allocate buffers for signed conversion"
21632159
msgstr ""
21642160

2161+
#: supervisor/shared/safe_mode.c
2162+
msgid "Unable to allocate the heap."
2163+
msgstr ""
2164+
21652165
#: ports/espressif/common-hal/busio/I2C.c
21662166
msgid "Unable to create lock"
21672167
msgstr ""
@@ -2367,10 +2367,6 @@ msgstr ""
23672367
msgid "Writes not supported on Characteristic"
23682368
msgstr ""
23692369

2370-
#: supervisor/shared/safe_mode.c
2371-
msgid "You are in safe mode because:\n"
2372-
msgstr ""
2373-
23742370
#: ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
23752371
#: ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h
23762372
#: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h
@@ -2385,7 +2381,7 @@ msgid "You pressed button A at start up."
23852381
msgstr ""
23862382

23872383
#: supervisor/shared/safe_mode.c
2388-
msgid "You pressed the BOOT button at start up."
2384+
msgid "You pressed the BOOT button at start up"
23892385
msgstr ""
23902386

23912387
#: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h

py/circuitpy_defns.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,16 @@ $(filter $(SRC_PATTERNS), \
525525
qrio/PixelPolicy.c \
526526
qrio/QRInfo.c \
527527
supervisor/RunReason.c \
528-
supervisor/SafeModeReason.c \
529528
supervisor/StatusBar.c \
530529
wifi/AuthMode.c \
531530
wifi/Packet.c \
532531
)
533532

533+
ifeq ($(CIRCUITPY_SAFEMODE_PY),1)
534+
SRC_BINDINGS_ENUMS += \
535+
supervisor/SafeModeReason.c
536+
endif
537+
534538
SRC_BINDINGS_ENUMS += \
535539
util.c
536540

shared-bindings/supervisor/Runtime.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ MP_PROPERTY_GETTER(supervisor_runtime_run_reason_obj,
117117
(mp_obj_t)&supervisor_runtime_get_run_reason_obj);
118118

119119
//| safe_mode_reason: SafeModeReason
120-
//| """Why CircuitPython went into safe mode this particular time (read-only)."""
120+
//| """Why CircuitPython went into safe mode this particular time (read-only).
121+
//|
122+
//| **Limitations**: Raises ``NotImplementedError`` on builds that do not implement ``safemode.py``.
123+
//| """
121124
STATIC mp_obj_t supervisor_runtime_get_safe_mode_reason(mp_obj_t self) {
122125
#if CIRCUITPY_SAFEMODE_PY
123126
return cp_enum_find(&supervisor_safe_mode_reason_type, get_safe_mode());

shared-bindings/supervisor/SafeModeReason.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
// Reuse the non-Python safe_mode_t enum
3232
#include "supervisor/shared/safe_mode.h"
3333

34-
#if CIRCUITPY_SAFEMODE_PY
3534
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, NONE, SAFE_MODE_NONE);
3635
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, BROWNOUT, SAFE_MODE_BROWNOUT);
3736
// alphabetical from here down
@@ -50,16 +49,16 @@ MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USB_TOO_MANY
5049
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USB_TOO_MANY_INTERFACE_NAMES, SAFE_MODE_USB_TOO_MANY_INTERFACE_NAMES);
5150
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USER, SAFE_MODE_USER);
5251
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, WATCHDOG, SAFE_MODE_WATCHDOG);
53-
#endif
5452

5553

5654
//| class SafeModeReason:
57-
//| """The reason that CircuitPython went into safe mode."""
55+
//| """The reason that CircuitPython went into safe mode.
56+
//|
57+
//| **Limitations**: Class not available on builds that do not implement ``safemode.py``.
58+
//| """
5859
//|
5960
MAKE_ENUM_MAP(supervisor_safe_mode_reason) {
6061

61-
#if CIRCUITPY_SAFEMODE_PY
62-
6362
//| NONE: object
6463
//| """CircuitPython is not in safe mode."""
6564
//|
@@ -146,7 +145,6 @@ MAKE_ENUM_MAP(supervisor_safe_mode_reason) {
146145
//| """An internal watchdog timer expired."""
147146
//|
148147
MAKE_ENUM_MAP_ENTRY(safe_mode_reason, WATCHDOG),
149-
#endif
150148
};
151149

152150
STATIC MP_DEFINE_CONST_DICT(supervisor_safe_mode_reason_locals_dict, supervisor_safe_mode_reason_locals_table);

shared-bindings/supervisor/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
339339
#if CIRCUITPY_SAFEMODE_PY
340340
{ MP_ROM_QSTR(MP_QSTR_SafeModeReason), MP_ROM_PTR(&supervisor_safe_mode_reason_type) },
341341
#else
342-
{ MP_ROM_QSTR(MP_QSTR_SafeModeReason), mp_const_none },
342+
{ MP_ROM_QSTR(MP_QSTR_SafeModeReason), MP_ROM_NONE },
343343
#endif
344344
{ MP_ROM_QSTR(MP_QSTR_set_next_code_file), MP_ROM_PTR(&supervisor_set_next_code_file_obj) },
345345
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&supervisor_ticks_ms_obj) },

supervisor/shared/safe_mode.c

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -145,46 +145,47 @@ void print_safe_mode_message(safe_mode_t reason) {
145145
return;
146146
}
147147

148-
serial_write("\r\n");
149-
serial_write_compressed(translate("You are in safe mode because:\n"));
148+
serial_write_compressed(translate("\nYou are in safe mode because:\n"));
150149

151150
const compressed_string_t *message = NULL;
152151

153152
// First check for safe mode reasons that do not necessarily reflect bugs.
154153

155154
switch (reason) {
156155
case SAFE_MODE_BROWNOUT:
157-
message = translate("The microcontroller's power dipped. Make sure your power supply provides\nenough power for the whole circuit and press reset (after ejecting CIRCUITPY).");
156+
message = translate("The power dipped. Make sure you are providing enough power.");
158157
break;
159158
case SAFE_MODE_USER:
160159
#if defined(BOARD_USER_SAFE_MODE_ACTION)
161160
message = BOARD_USER_SAFE_MODE_ACTION;
162161
#elif defined(CIRCUITPY_BOOT_BUTTON)
163-
message = translate("You pressed the BOOT button at start up.");
162+
message = translate("You pressed the BOOT button at start up");
164163
#else
165164
message = translate("You pressed the reset button during boot.");
166165
#endif
167-
serial_write_compressed(message);
168-
message = translate("\nTo exit, reset the board without requesting safe mode.");
169-
// The final piece is printed below.
170166
break;
171167
case SAFE_MODE_NO_CIRCUITPY:
172168
message = translate("CIRCUITPY drive could not be found or created.");
173169
break;
174170
case SAFE_MODE_PROGRAMMATIC:
175-
message = translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode.");
171+
message = translate("The `microcontroller` module was used to boot into safe mode.");
176172
break;
173+
#if CIRCUITPY_SAFEMODE_PY
177174
case SAFE_MODE_SAFEMODE_PY_ERROR:
178175
message = translate("Error in safemode.py.");
179176
break;
177+
#endif
178+
case SAFE_MODE_STACK_OVERFLOW:
179+
message = translate("Heap was corrupted because the stack was too small. Increase stack size.");
180+
break;
180181
case SAFE_MODE_USB_TOO_MANY_ENDPOINTS:
181182
message = translate("USB devices need more endpoints than are available.");
182183
break;
183184
case SAFE_MODE_USB_TOO_MANY_INTERFACE_NAMES:
184185
message = translate("USB devices specify too many interface names.");
185186
break;
186187
case SAFE_MODE_USB_BOOT_DEVICE_NOT_INTERFACE_ZERO:
187-
message = translate("Boot device must be first device (interface #0).");
188+
message = translate("Boot device must be first (interface #0).");
188189
break;
189190
case SAFE_MODE_WATCHDOG:
190191
message = translate("Internal watchdog timer expired.");
@@ -194,44 +195,41 @@ void print_safe_mode_message(safe_mode_t reason) {
194195
}
195196

196197
if (message) {
198+
// Non-crash safe mode.
197199
serial_write_compressed(message);
198-
serial_write("\r\n");
199-
return;
200+
} else {
201+
// Something worse happened.
202+
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
203+
switch (reason) {
204+
case SAFE_MODE_GC_ALLOC_OUTSIDE_VM:
205+
message = translate("Heap allocation when VM not running.");
206+
break;
207+
case SAFE_MODE_FLASH_WRITE_FAIL:
208+
message = translate("Failed to write internal flash.");
209+
break;
210+
case SAFE_MODE_HARD_FAULT:
211+
message = translate("Fault detected by hardware.");
212+
break;
213+
case SAFE_MODE_INTERRUPT_ERROR:
214+
message = translate("Interrupt error.");
215+
break;
216+
case SAFE_MODE_NLR_JUMP_FAIL:
217+
message = translate("NLR jump failed. Likely memory corruption.");
218+
break;
219+
case SAFE_MODE_NO_HEAP:
220+
message = translate("Unable to allocate the heap.");
221+
break;
222+
case SAFE_MODE_SDK_FATAL_ERROR:
223+
message = translate("Third-party firmware fatal error.");
224+
break;
225+
default:
226+
message = translate("Unknown reason.");
227+
break;
228+
}
229+
serial_write_compressed(message);
230+
serial_write_compressed(translate("\nPlease file an issue with your program at https://github.com/adafruit/circuitpython/issues."));
200231
}
201232

202-
// Something worse happened.
203-
204-
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
205-
206-
switch (reason) {
207-
case SAFE_MODE_GC_ALLOC_OUTSIDE_VM:
208-
message = translate("Attempted heap allocation when VM not running.");
209-
break;
210-
case SAFE_MODE_FLASH_WRITE_FAIL:
211-
message = translate("Failed to write internal flash.");
212-
break;
213-
case SAFE_MODE_HARD_FAULT:
214-
message = translate("Crash into the HardFault_Handler.");
215-
break;
216-
case SAFE_MODE_INTERRUPT_ERROR:
217-
message = translate("Interrupt error.");
218-
break;
219-
case SAFE_MODE_NLR_JUMP_FAIL:
220-
message = translate("NLR jump failed. Likely memory corruption.");
221-
break;
222-
case SAFE_MODE_NO_HEAP:
223-
message = translate("CircuitPython was unable to allocate the heap.");
224-
break;
225-
case SAFE_MODE_SDK_FATAL_ERROR:
226-
message = translate("Third-party firmware fatal error.");
227-
break;
228-
case SAFE_MODE_STACK_OVERFLOW:
229-
message = translate("The CircuitPython heap was corrupted because the stack was too small.\nIncrease the stack size if you know how. If not:");
230-
break;
231-
default:
232-
message = translate("Unknown reason.");
233-
break;
234-
}
235-
serial_write_compressed(message);
236-
serial_write_compressed(translate("\nPlease file an issue with the contents of your CIRCUITPY drive at \nhttps://github.com/adafruit/circuitpython/issues\n"));
233+
// Always tell user how to get out of safe mode.
234+
serial_write_compressed(translate("\nPress reset to exit safe mode.\n"));
237235
}

0 commit comments

Comments
 (0)