Skip to content

Commit bbadc00

Browse files
authored
Merge pull request #7577 from dhalbert/safemode-py
Implement safemode.py
2 parents e47e645 + f79459c commit bbadc00

File tree

56 files changed

+566
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+566
-394
lines changed

README.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,26 @@ Behavior
138138
- Adds a safe mode that does not run user code after a hard crash or brown out. This makes it
139139
possible to fix code that causes nasty crashes by making it available through mass storage after
140140
the crash. A reset (the button) is needed after it's fixed to get back into normal mode.
141+
- Safe mode may be handled programmatically by providing a ``safemode.py``.
142+
``safemode.py`` is run if the board has reset due to entering safe mode, unless the safe mode
143+
initiated by the user by pressing button(s).
144+
USB is not available so nothing can be printed.
145+
``safemode.py`` can determine why the safe mode occurred
146+
using ``supervisor.runtime.safe_mode_reason``, and take appropriate action. For instance,
147+
if a hard crash occurred, ``safemode.py`` may do a ``microcontroller.reset()``
148+
to automatically restart despite the crash.
149+
If the battery is low, but is being charged, ``safemode.py`` may put the board in deep sleep
150+
for a while. Or it may simply reset, and have ``code.py`` check the voltage and do the sleep.
141151
- RGB status LED indicating CircuitPython state.
142152
- One green flash - code completed without error.
143153
- Two red flashes - code ended due to an exception.
144154
- Three yellow flashes - safe mode. May be due to CircuitPython internal error.
145155
- Re-runs ``code.py`` or other main file after file system writes by a workflow. (Disable with
146156
``supervisor.disable_autoreload()``)
147157
- Autoreload is disabled while the REPL is active.
148-
- Main is one of these: ``code.txt``, ``code.py``, ``main.py``,
149-
``main.txt``
150-
- Boot is one of these: ``boot.py``, ``boot.txt``
158+
- ``code.py`` may also be named``code.txt``, ``main.py``, or ``main.txt``.
159+
- ``boot.py`` may also be named ``boot.txt``.
160+
- ``safemode.py`` may also be named ``safemode.txt``.
151161

152162
API
153163
~~~

locale/circuitpython.pot

Lines changed: 78 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +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."
36+
msgstr ""
37+
38+
#: supervisor/shared/safe_mode.c
39+
msgid ""
40+
"\n"
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"
3648
msgstr ""
3749

3850
#: py/obj.c
@@ -85,7 +97,7 @@ msgstr ""
8597
#: ports/raspberrypi/common-hal/alarm/__init__.c
8698
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
8799
#: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c
88-
#: ports/stm/common-hal/rtc/RTC.c
100+
#: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c
89101
msgid "%q"
90102
msgstr ""
91103

@@ -530,10 +542,6 @@ msgstr ""
530542
msgid "Attempt to allocate %d blocks"
531543
msgstr ""
532544

533-
#: supervisor/shared/safe_mode.c
534-
msgid "Attempted heap allocation when VM not running."
535-
msgstr ""
536-
537545
#: ports/raspberrypi/audio_dma.c
538546
msgid "Audio conversion not implemented"
539547
msgstr ""
@@ -582,20 +590,13 @@ msgid "Bitmap size and bits per value must match"
582590
msgstr ""
583591

584592
#: supervisor/shared/safe_mode.c
585-
msgid "Boot device must be first device (interface #0)."
593+
msgid "Boot device must be first (interface #0)."
586594
msgstr ""
587595

588596
#: ports/mimxrt10xx/common-hal/busio/UART.c
589597
msgid "Both RX and TX required for flow control"
590598
msgstr ""
591599

592-
#: ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
593-
#: ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h
594-
#: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h
595-
#: ports/atmel-samd/boards/meowmeow/mpconfigboard.h
596-
msgid "Both buttons were pressed at start up.\n"
597-
msgstr ""
598-
599600
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
600601
msgid "Both pins must support hardware interrupts"
601602
msgstr ""
@@ -661,12 +662,6 @@ msgstr ""
661662
msgid "Bus pin %d is already in use"
662663
msgstr ""
663664

664-
#: ports/espressif/boards/m5stack_core_basic/mpconfigboard.h
665-
#: ports/espressif/boards/m5stack_core_fire/mpconfigboard.h
666-
#: ports/espressif/boards/m5stack_stick_c/mpconfigboard.h
667-
msgid "Button A was pressed at start up.\n"
668-
msgstr ""
669-
670665
#: shared-bindings/_bleio/UUID.c
671666
msgid "Byte buffer must be 16 bytes."
672667
msgstr ""
@@ -797,10 +792,6 @@ msgstr ""
797792
msgid "CircuitPython core code crashed hard. Whoops!\n"
798793
msgstr ""
799794

800-
#: supervisor/shared/safe_mode.c
801-
msgid "CircuitPython was unable to allocate the heap."
802-
msgstr ""
803-
804795
#: shared-module/bitbangio/I2C.c
805796
msgid "Clock stretch too long"
806797
msgstr ""
@@ -839,10 +830,6 @@ msgstr ""
839830
msgid "Couldn't allocate decoder"
840831
msgstr ""
841832

842-
#: supervisor/shared/safe_mode.c
843-
msgid "Crash into the HardFault_Handler."
844-
msgstr ""
845-
846833
#: ports/stm/common-hal/analogio/AnalogOut.c
847834
msgid "DAC Channel Init Error"
848835
msgstr ""
@@ -934,6 +921,10 @@ msgstr ""
934921
msgid "Error in regex"
935922
msgstr ""
936923

924+
#: supervisor/shared/safe_mode.c
925+
msgid "Error in safemode.py."
926+
msgstr ""
927+
937928
#: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c
938929
msgid "Error: Failure to bind"
939930
msgstr ""
@@ -1007,7 +998,7 @@ msgid "Failed to write internal flash."
1007998
msgstr ""
1008999

10091000
#: supervisor/shared/safe_mode.c
1010-
msgid "Fatal error."
1001+
msgid "Fault detected by hardware."
10111002
msgstr ""
10121003

10131004
#: py/moduerrno.c
@@ -1095,6 +1086,15 @@ msgstr ""
10951086
msgid "Hardware in use, try alternative pins"
10961087
msgstr ""
10971088

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+
10981098
#: extmod/vfs_posix_file.c py/objstringio.c
10991099
msgid "I/O operation on closed file"
11001100
msgstr ""
@@ -1209,6 +1209,10 @@ msgstr ""
12091209
msgid "Internal watchdog timer expired."
12101210
msgstr ""
12111211

1212+
#: supervisor/shared/safe_mode.c
1213+
msgid "Interrupt error."
1214+
msgstr ""
1215+
12121216
#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c
12131217
msgid "Invalid %q"
12141218
msgstr ""
@@ -1257,10 +1261,6 @@ msgstr ""
12571261
msgid "Invalid format chunk size"
12581262
msgstr ""
12591263

1260-
#: supervisor/shared/safe_mode.c
1261-
msgid "Invalid memory access."
1262-
msgstr ""
1263-
12641264
#: ports/espressif/common-hal/wifi/Radio.c
12651265
msgid "Invalid multicast MAC address"
12661266
msgstr ""
@@ -1549,10 +1549,6 @@ msgstr ""
15491549
msgid "No timer available"
15501550
msgstr ""
15511551

1552-
#: supervisor/shared/safe_mode.c
1553-
msgid "Nordic system firmware failure assertion."
1554-
msgstr ""
1555-
15561552
#: ports/nrf/common-hal/_bleio/__init__.c
15571553
msgid "Nordic system firmware out of memory"
15581554
msgstr ""
@@ -2004,53 +2000,19 @@ msgid "Temperature read timed out"
20042000
msgstr ""
20052001

20062002
#: supervisor/shared/safe_mode.c
2007-
msgid "The BOOT button was pressed at start up.\n"
2008-
msgstr ""
2009-
2010-
#: supervisor/shared/safe_mode.c
2011-
msgid ""
2012-
"The CircuitPython heap was corrupted because the stack was too small.\n"
2013-
"Increase the stack size if you know how. If not:"
2014-
msgstr ""
2015-
2016-
#: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h
2017-
msgid "The SW38 button was pressed at start up.\n"
2018-
msgstr ""
2019-
2020-
#: ports/espressif/boards/hardkernel_odroid_go/mpconfigboard.h
2021-
msgid "The VOLUME button was pressed at start up.\n"
2022-
msgstr ""
2023-
2024-
#: supervisor/shared/safe_mode.c
2025-
msgid ""
2026-
"The `microcontroller` module was used to boot into safe mode. Press reset to "
2027-
"exit safe mode."
2003+
msgid "The `microcontroller` module was used to boot into safe mode."
20282004
msgstr ""
20292005

20302006
#: py/obj.c
20312007
msgid "The above exception was the direct cause of the following exception:"
20322008
msgstr ""
20332009

2034-
#: ports/espressif/boards/m5stack_atom_echo/mpconfigboard.h
2035-
#: ports/espressif/boards/m5stack_atom_lite/mpconfigboard.h
2036-
#: ports/espressif/boards/m5stack_atom_matrix/mpconfigboard.h
2037-
#: ports/espressif/boards/m5stack_atom_u/mpconfigboard.h
2038-
msgid "The central button was pressed at start up.\n"
2039-
msgstr ""
2040-
2041-
#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h
2042-
msgid "The left button was pressed at start up.\n"
2043-
msgstr ""
2044-
20452010
#: shared-bindings/rgbmatrix/RGBMatrix.c
20462011
msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30"
20472012
msgstr ""
20482013

20492014
#: supervisor/shared/safe_mode.c
2050-
msgid ""
2051-
"The microcontroller's power dipped. Make sure your power supply provides\n"
2052-
"enough power for the whole circuit and press reset (after ejecting "
2053-
"CIRCUITPY)."
2015+
msgid "The power dipped. Make sure you are providing enough power."
20542016
msgstr ""
20552017

20562018
#: shared-module/audiomixer/MixerVoice.c
@@ -2069,6 +2031,10 @@ msgstr ""
20692031
msgid "The sample's signedness does not match the mixer's"
20702032
msgstr ""
20712033

2034+
#: supervisor/shared/safe_mode.c
2035+
msgid "Third-party firmware fatal error."
2036+
msgstr ""
2037+
20722038
#: shared-module/imagecapture/ParallelImageCapture.c
20732039
msgid "This microcontroller does not support continuous capture."
20742040
msgstr ""
@@ -2101,10 +2067,6 @@ msgstr ""
21012067
msgid "Timeout is too long: Maximum timeout length is %d seconds"
21022068
msgstr ""
21032069

2104-
#: supervisor/shared/safe_mode.c
2105-
msgid "To exit, please reset the board without requesting safe mode."
2106-
msgstr ""
2107-
21082070
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
21092071
msgid "Too many channels in sample"
21102072
msgstr ""
@@ -2196,6 +2158,10 @@ msgstr ""
21962158
msgid "Unable to allocate buffers for signed conversion"
21972159
msgstr ""
21982160

2161+
#: supervisor/shared/safe_mode.c
2162+
msgid "Unable to allocate the heap."
2163+
msgstr ""
2164+
21992165
#: ports/espressif/common-hal/busio/I2C.c
22002166
msgid "Unable to create lock"
22012167
msgstr ""
@@ -2401,13 +2367,44 @@ msgstr ""
24012367
msgid "Writes not supported on Characteristic"
24022368
msgstr ""
24032369

2370+
#: ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
2371+
#: ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h
2372+
#: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h
2373+
#: ports/atmel-samd/boards/meowmeow/mpconfigboard.h
2374+
msgid "You pressed both buttons at start up."
2375+
msgstr ""
2376+
2377+
#: ports/espressif/boards/m5stack_core_basic/mpconfigboard.h
2378+
#: ports/espressif/boards/m5stack_core_fire/mpconfigboard.h
2379+
#: ports/espressif/boards/m5stack_stick_c/mpconfigboard.h
2380+
msgid "You pressed button A at start up."
2381+
msgstr ""
2382+
24042383
#: supervisor/shared/safe_mode.c
2405-
msgid "You are in safe mode because:\n"
2384+
msgid "You pressed the BOOT button at start up"
2385+
msgstr ""
2386+
2387+
#: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h
2388+
msgid "You pressed the SW38 button at start up."
2389+
msgstr ""
2390+
2391+
#: ports/espressif/boards/hardkernel_odroid_go/mpconfigboard.h
2392+
msgid "You pressed the VOLUME button at start up."
2393+
msgstr ""
2394+
2395+
#: ports/espressif/boards/m5stack_atom_echo/mpconfigboard.h
2396+
#: ports/espressif/boards/m5stack_atom_lite/mpconfigboard.h
2397+
#: ports/espressif/boards/m5stack_atom_matrix/mpconfigboard.h
2398+
#: ports/espressif/boards/m5stack_atom_u/mpconfigboard.h
2399+
msgid "You pressed the central button at start up."
2400+
msgstr ""
2401+
2402+
#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h
2403+
msgid "You pressed the left button at start up."
24062404
msgstr ""
24072405

24082406
#: supervisor/shared/safe_mode.c
2409-
msgid ""
2410-
"You pressed the reset button during boot. Press again to exit safe mode."
2407+
msgid "You pressed the reset button during boot."
24112408
msgstr ""
24122409

24132410
#: supervisor/shared/micropython.c

0 commit comments

Comments
 (0)