I am using CircuitPython (CircuitPython 8.0.0-beta.6) on the nrf52840 module (mounted on custom hardware).
Very often (maybe 8 out of 10 times) performing a reset or detecting a Python bug causes the module to go into safe mode and there is no way to get out of it (reset, power cycle do not help).
I have to reflash the image in order to fix the issue. In general the firmware is very stable and works well for long periods but I have been having this issue since 8.0.0-beta.6 (I cannot confirm if this is related yet).
Anyone having such issues?
Cannot get out of safe mode
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- danhalbert
- Posts: 4613
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Cannot get out of safe mode
If you can reproduce this at least some of the time with a particular code.py, could you open an issue with your code here? https://github.com/adafruit/circuitpyth ... new/choose
Is there a boot.py file?
If the program is large, could you try to trim it down? Thanks.
Is there a boot.py file?
If the program is large, could you try to trim it down? Thanks.
- nelfata
- Posts: 31
- Joined: Wed May 07, 2014 9:44 am
Re: Cannot get out of safe mode
I don't have boot.py
Also another piece of information, pressing the reset twice does not trigger the bootloader.
Also another piece of information, pressing the reset twice does not trigger the bootloader.
- danhalbert
- Posts: 4613
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Cannot get out of safe mode
Detecting double-reset is done in the UF2 bootloader. This sounds like it might be a hw issue. Do you see this only on a single piece of hardware? Do you have other samples/instances of your hardware you can test?
- nelfata
- Posts: 31
- Joined: Wed May 07, 2014 9:44 am
Re: Cannot get out of safe mode
I will try on other boards this coming week and report back. The reset seems fine, but maybe the double click requires some certain timing/voltage level to be maintained. If you tell me what to look for I can hook a scope and check.
Also, and probably I need to create another issue. I would like to avoid going into REPL (for production) and start directly into the application in case of a power cycle/reset/watchdog timeout. Would that be possible?
Thank you.
Also, and probably I need to create another issue. I would like to avoid going into REPL (for production) and start directly into the application in case of a power cycle/reset/watchdog timeout. Would that be possible?
Thank you.
- danhalbert
- Posts: 4613
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Cannot get out of safe mode
We do need to be able to get out of safe mode programmatically, and need for this has gone up with more use of wifi, which really brings out unreliability. Issue is here:
https://github.com/adafruit/circuitpython/issues/5956
We expect to do this pretty soon, but not for 8.0.0.
Double-tap reset is done here and surrounding code:
https://github.com/adafruit/Adafruit_nR ... ain.c#L287
After the first reset, we write a flag value in a memory location that is otherwise untouched. Then we wait 500 msec for a second tap. If the bootloader is entered again and that flag value is there, it means there was a previous entry into the bootloader within the past 500 msecs, so it's a double-tap. It never gets to CircuitPython when a double-tap is detected.
https://github.com/adafruit/circuitpython/issues/5956
We expect to do this pretty soon, but not for 8.0.0.
Double-tap reset is done here and surrounding code:
https://github.com/adafruit/Adafruit_nR ... ain.c#L287
After the first reset, we write a flag value in a memory location that is otherwise untouched. Then we wait 500 msec for a second tap. If the bootloader is entered again and that flag value is there, it means there was a previous entry into the bootloader within the past 500 msecs, so it's a double-tap. It never gets to CircuitPython when a double-tap is detected.
- nelfata
- Posts: 31
- Joined: Wed May 07, 2014 9:44 am
Re: Cannot get out of safe mode
Just some additional information.
If I enable BLE (adafruit_ble) and enable advertising then perform microcontroller.reset(), then CircuitPython goes into safe mode and this is when it cannot get out of this mode without reflashing.
This is very problematic and makes the application unreliable. Please propose a short term solution.
If I enable BLE (adafruit_ble) and enable advertising then perform microcontroller.reset(), then CircuitPython goes into safe mode and this is when it cannot get out of this mode without reflashing.
This is very problematic and makes the application unreliable. Please propose a short term solution.
- danhalbert
- Posts: 4613
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Cannot get out of safe mode
Could you post your code?
- nelfata
- Posts: 31
- Joined: Wed May 07, 2014 9:44 am
Re: Cannot get out of safe mode
I have attached a ZIP file with a demo reproducing the issue.
The demo enables the BLE and starts adevertising for 10 seconds, once the advertising times out a reset is issued.
Please see line 80 in ble.py.
Thank you.
The demo enables the BLE and starts adevertising for 10 seconds, once the advertising times out a reset is issued.
Please see line 80 in ble.py.
Thank you.
- Attachments
-
- ScriptsSafeMode.zip
- (10.12 KiB) Downloaded 3 times
- danhalbert
- Posts: 4613
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Cannot get out of safe mode
I tried the code you supplied on a Feather nRF52840, running 8.0.0-rc.1.
I had to install asyncio and adafruit_ble as libraries as well (of course).
I do not see it going into safe mode. Instead, I just see it resetting every 10 seconds, because of the advertising timeout, after which time you force a reset.
- Could you show me the error transcript with safe mode appearing?
- Do you see this on multiple nRF52840 boards? How are you powering the board? Is it connected to a host computer?
- Can you prune the program down to just a single code.py that does advertising? Have you tried this without asyncio?
(BTW, in asyncio, there is only one event loop possible, so don't bother to create a new one. You can just use the default one.)
I had to install asyncio and adafruit_ble as libraries as well (of course).
I do not see it going into safe mode. Instead, I just see it resetting every 10 seconds, because of the advertising timeout, after which time you force a reset.
Code: Select all
-- I press the RESET button
[tio 20:45:11] Disconnected
[tio 20:45:15] Connected
8204.605: INFO - sm_ble running: adv
8214.109: INFO - advertising timeout, resetting
-- it resets and starts up again
[tio 20:45:25] Disconnected
[tio 20:45:29] Connected
8218.031: INFO - sm_ble running: adv
-- Here I typed ctrl-C
Traceback (most recent call last):
File "code.py", line 4, in <module>
File "diags.py", line 20, in __init__
File "asyncio/core.py", line 297, in run
File "asyncio/core.py", line 237, in run_until_complete
File "asyncio/core.py", line 176, in wait_io_event
KeyboardInterrupt:
Code done running.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
Press any key to enter the REPL. Use CTRL-D to reload.
- Do you see this on multiple nRF52840 boards? How are you powering the board? Is it connected to a host computer?
- Can you prune the program down to just a single code.py that does advertising? Have you tried this without asyncio?
(BTW, in asyncio, there is only one event loop possible, so don't bother to create a new one. You can just use the default one.)
- nelfata
- Posts: 31
- Joined: Wed May 07, 2014 9:44 am
Re: Cannot get out of safe mode
Thank you for taking the time with this issue.
I have simplified the code further (no asyncio) and the problem still persists but this time you need to let it do 5 to 10 iterations for it to fail (reduced the timeout so you don't have to wait long).
The board is connected to a host computer (Windows7 as a VM running on MacOS). The power is provided by the USB from the host computer (very low power, so I doubt it is a factor).
I tried only one board so far (I should be getting more soon).
Is it possible that Windows file system is introducing a corruption upon a reset?
Here is the output:
I have simplified the code further (no asyncio) and the problem still persists but this time you need to let it do 5 to 10 iterations for it to fail (reduced the timeout so you don't have to wait long).
The board is connected to a host computer (Windows7 as a VM running on MacOS). The power is provided by the USB from the host computer (very low power, so I doubt it is a factor).
I tried only one board so far (I should be getting more soon).
Is it possible that Windows file system is introducing a corruption upon a reset?
Here is the output:
Code: Select all
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Import modules
Init BLE
Start advertising
Advertising timeout, resetting
Port COM88 disconnected
Opening port COM88...OK
.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Import modules
Init BLE
Start advertising
Advertising timeout, resetting
Port COM88 disconnected
Opening port COM88...OK
.
Adafruit CircuitPython 8.0.0-beta.6-dirty on 2023-01-29; Bemis Remote nRF52840 with nRF52840
>>>
>>>
Auto-reload is off.
Running in safe mode! Not running saved code.
You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
NLR jump failed. Likely memory corruption.
Please file an issue with the contents of your CIRCUITPY drive at
https://github.com/adafruit/circuitpython/issues
Press any key to enter the REPL. Use CTRL-D to reload.
- Attachments
-
- ScriptsSafeModeSimple.zip
- (4.73 KiB) Downloaded 3 times
- nelfata
- Posts: 31
- Joined: Wed May 07, 2014 9:44 am
Re: Cannot get out of safe mode
One more experiment. I used the same code that I sent last and tried it directly on MacOS. I experienced the same behavior but in this case, once the bootloader was triggered if I reset the board then all goes back to normal (CTRL-D did not help) and I am able to get back into the application.
So bottom line on the Windows side I needed to reflash but in MacOS a reset is sufficient.
So bottom line on the Windows side I needed to reflash but in MacOS a reset is sufficient.
- danhalbert
- Posts: 4613
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Cannot get out of safe mode
It looks like you have a custom build. Is that uploaded to a GitHub repo so I can look at the differences? Thanks.
- nelfata
- Posts: 31
- Joined: Wed May 07, 2014 9:44 am
Re: Cannot get out of safe mode
Sure, but I will have to find the procedure for that.
- danhalbert
- Posts: 4613
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Cannot get out of safe mode
We have a guide to using git when working on CircuitPython:
https://learn.adafruit.com/contribute-t ... and-github
https://learn.adafruit.com/contribute-t ... and-github
Please be positive and constructive with your questions and comments.