Skip to content

Commit 328585f

Browse files
committed
don't enter safemode.py on USER safe mode
1 parent 0f099cd commit 328585f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ Behavior
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.
141141
- 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. USB is not
143-
available so nothing can be printed. ``safemode.py`` can determine why the safe mode occurred
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
144146
using ``supervisor.runtime.safe_mode_reason``, and take appropriate action. For instance,
145147
if a hard crash occurred, ``safemode.py`` may do a ``microcontroller.reset()``
146148
to automatically restart despite the crash.

main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,9 @@ vstr_t *boot_output;
733733
#if CIRCUITPY_SAFEMODE_PY
734734
STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) {
735735
// Don't run if we aren't in safe mode or we won't be able to find safemode.py.
736-
if (safe_mode == SAFE_MODE_NONE || !filesystem_present()) {
736+
// Also don't run if it's a user-initiated safemode (pressing button(s) during boot),
737+
// since that's deliberate.
738+
if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER || !filesystem_present()) {
737739
return;
738740
}
739741

shared-bindings/supervisor/SafeModeReason.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ MAKE_ENUM_MAP(supervisor_safe_mode_reason) {
137137
MAKE_ENUM_MAP_ENTRY(safe_mode_reason, USB_TOO_MANY_INTERFACE_NAMES),
138138

139139
//| USER: object
140-
//| """The user pressed one or more buttons to enter safe mode."""
140+
//| """The user pressed one or more buttons to enter safe mode.
141+
//| This safe mode does **not** cause ``safemode.py`` to be run, since its purpose
142+
//| is to prevent all user code from running.
143+
//| This allows errors in ``safemode.py`` to be corrected easily.
144+
//| """
141145
//|
142146
MAKE_ENUM_MAP_ENTRY(safe_mode_reason, USER),
143147

0 commit comments

Comments
 (0)