The reasons for entering safe mode fall into several categories. All safe mode reasons are enumerated as constants in the supervisor.SafeModeReason
class. The reasons as of CircuitPython 8.1.0 are listed below, in code text
. The bold text is what is printed in the console. Refer to the documentation for the latest list and for more details.
Internal Software Errors
These safe mode reasons reflect internal errors in CircuitPython, probably because of a bug:
-
Heap allocation when VM not running.
SafeModeReason.GC_ALLOC_OUTSIDE_VM
-
Failed to write internal flash.
SafeModeReason.FLASH
_WRITE_FAIL
This might be a hardware error as well. -
Hard fault: memory access or instruction error.
(previously Fault detected by hardware.)SafeModeReason.HARD_FAULT
This is often an out-of-bounds memory reference. It does not indicate a hardware failure. -
Interrupt error.
SafeModeReason.INTERRUPT_ERROR
Some error associated with interrupts. -
NLR jump failed. Likely memory corruption.
SafeModeReason.NLR_JUMP_FAILED
This is a "Non Local Return" (exception handling) problem. -
Unable to allocate the heap.
SafeModeReason.NO_HEAP
-
Third-party firmware fatal error.
SafeModeReason.SDK_FATAL_ERROR
Reported when third-party software used by CircuitPython reports an unrecoverable error. -
Internal watchdog timer expired.
SafeModeReason.WATCHDOG
An internal watchdog timer went off. Something is looping or taking more time than expected. This is not the watchdog timer used formicrocontroller.watchdog
. Ifmicrocontroller.watchdog
is enabled to do a reset, it will do a regular reset; it will not go into safe mode.
Hardware Failures
-
CIRCUITPY drive could not be found or created.
SafeModeReason.NO_CIRCUITPY
This is often due to a hardware failure in the external flash chip on the board.
Power Problem
A power supply issue may cause the BROWNOUT
safe mode. Your battery may be getting low, or you may be trying to draw too much current from a USB port or other power source:
-
The power dipped. Make sure you are providing enough power.
SafeModeReason.BROWNOUT
Stack Size
The STACK_OVERFLOW
safe mode may be correctable by increasing the stack size, using supervisor.runtime.next_stack_limit
:
- Heap was corrupted because the stack was too small. Increase stack size.
-
Stack overflow. Increase stack size [changed in CircuitPython 9.0.0]
SafeModeReason.STACK_OVERFLOW
boot.py USB Problems
These safe modes are due to erroneous USB configurations set up in boot.py:
- USB devices need more endpoints than are available.
SafeModeReason.USB_TOO_MANY_ENDPOINTS
- USB devices specify too many interface names.
SafeModeReason.USB_TOO_MANY_INTERFACE_NAMES
-
Boot device must be first (interface #0).
SafeModeReason.USB_BOOT_DEVICE_NOT_INTERFACE_ZERO
safemode.py Problem
If an error is encountered while running safemode.py, you'll get this:
- Error in safemode.py.
SafeModeReason.SAFE_MODE_PY_ERROR
Programmatic Safe Mode
-
The `microcontroller` module was used to boot into safe mode.
SafeModeReason.PROGRAMMATIC
You can write code to enter safe mode using microcontroller.on_next_reset():
microcontroller.on_next_reset(microcontroller.RunMode.SAFE_MODE) microcontroller.reset()
Manual Safe Mode
You can press some combination of buttons that entered safe mode. The button(s) you use vary per board. On many boards, the RGB or single-color status LED will blink briefly a few times after you press RESET. If you press RESET during the blinks, the board will enter safe mode. On other boards, you will enter safe mode if you hold down one or more buttons and press RESET. For instance on Circuit Playground boards, you enter safe mode by holding down both button A and button B while pressing RESET.
- You pressed the BOOT button at start up.
- You pressed the reset button during boot.
- You pressed button A at start up.
- [and similar messages]
SafemodeReason.USER
Manual (aka USER
) safe mode is useful if your program causes a boot loop and you can't control-C the program. Or, you may have set CIRCUITPY to be read-only from the host computer by doing a storage.remount()
in boot.py. If you didn't provide a way out of this (by, say, not doing the remount
when a button is pressed), then entering safe mode manually will skip boot.py and you'll be able to edit your CIRCUITPY files.
Text editor powered by tinymce.