-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Writing to the NVM on the RP2350 crashes to Safe Mode, CP-9.2.0 #9773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
fwiw just referring back to my private notes I tested microcontroller.nvm on rp2350 back on September 17 and didn't see this. However, I didn't record my exact testing steps. I was most likely testing on the Pico 2 and probably wasn't resetting the board during my testing procedure, just immediately reading the value back. |
I tried reproducing this on full content of boot.py:
Full content of code.py:
Testing method: Modify boot.py, changing the value of Outcome: circuitpython boots normally. When I press enter, the expected value is printed. Safe mode does not occur.
This could mean that it's specific to Feather RP2350 (not affecting all RP2350 boards) or that there's another aspect to reproducing the problem that I haven't followed. If you have any more information it might be helpful. For various reasons it's not convenient for me to test on a Feather RP2350 right now. |
I also tried to reproduce, on a Feather RP2350, with PSRAM https://www.adafruit.com/product/4677 installed, running 9.2.0 final. I did not get a crash, either by reset or power cycle. My @b-blake What is in your |
My boot.py
|
# The first 100 lines of a 700+ line program.
# Set the DS3231 time from GPS time.
# Eventually adjust DS3231 for more accurate time keeping.
import gc
import os
import sys
import time
import board
import busio
import random
import binascii
import neopixel
import displayio
import traceback
import digitalio
import terminalio
import supervisor
import microcontroller
import adafruit_gps
import adafruit_ds3231
import adafruit_displayio_ssd1306
from adafruit_display_text import label
# jepler's code
# wait for serial connection
if supervisor.runtime.serial_connected:
print("serial already connected, continuing")
else:
while not supervisor.runtime.serial_connected:
pass
time.sleep(.1)
while supervisor.runtime.serial_bytes_available:
sys.stdin.read(1)
print("press any key", end='')
while not supervisor.runtime.serial_bytes_available:
pass
sys.stdin.read(1)
print()
print(f"dev mode is {hex(microcontroller.nvm[0]}"))
set_alarms = not True
set_DS3231 = not True
calibration = not True
CalValue = -16 # +num = Slower clock, -num = Faster clock
Flip_Flop = 0
OLED = 0x3C
EEPROM = 0x57
RTC3231 = 0x68
srsc = supervisor.runtime.serial_connected
sruc = supervisor.runtime.usb_connected
#>>> dir (supervisor)
#['__class__', '__name__', '__dict__',
#'RunReason', 'SafeModeReason', 'get_previous_traceback', 'reload', 'reset_terminal', 'runtime', 'set_next_code_file', 'set_usb_identification', 'status_bar', 'ticks_ms']
#
#>>> dir (supervisor.runtime)
#['__class__',
#'autoreload', 'ble_workflow', 'rgb_status_brightness', 'run_reason', 'safe_mode_reason', 'serial_bytes_available', 'serial_connected', 'usb_connected']
#>>>
if srsc: print('\t*********************')
if srsc: print('\t*** Program Start ***')
_Delay = const(5)
for _ in range(_Delay):
if srsc: print('\t\t', _Delay - _, end=' \r')
time.sleep(1) # 1 second
if srsc: print('\t*********************')
if board.board_id != 'adafruit_feather_rp2350':
if srsc: print(board.board_id, '~ Wrong CircuitPython OS!\a°')
while True: pass
if srsc: print('\f', end='')
i = 63 # 127 63 31 15 7 3 1
I = i*2+1
Neo_White = ((i, i, I))
Neo_Black = ((0, 0, 0))
Neo_Red = ((i, 0, 0))
Neo_Green = ((0, i, 0))
Neo_Blue = ((0, 0, I))
Neo_Yellow = ((i, i, 0))
Neo_Cyan = ((0, i, I))
Neo_Magenta = ((i, 0, I))
RAINBOW = [Neo_White, Neo_Black, Neo_Red, Neo_Green, Neo_Blue, Neo_Yellow, Neo_Cyan, Neo_Magenta] # 8
DoW = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Beerday')
Month = ('Null', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')
FREQ = ["secondly", "minutely", "hourly", "daily", "weekly", "monthly"]
NMEA = ('$GPRMC', '$GPVTG', '$GPGGA', '$GPGSA', '$GPGSV', '$GPGLL', '$GPTXT')
# board.D12, board.IO4
GPIO4 = digitalio.DigitalInOut(board.D12)
GPIO4.direction = digitalio.Direction.OUTPUT
GPIO4.value = True |
When I change the value:
|
I don't know if this plays in this issue or not; but If I close REPL and edit and save code.py, Jeff's code is skipped and the rest of code.py starts and runs. Only if I change the byte written in boot.py does Jeff's code execute on the second RESET push. P.S. I am on a Windows 10 machine. |
This boot.py has invalid syntax: if go_dev_mode:
if microcontroller.nvm[0:1] == b"\x00":
microcontroller.nvm[0:1] = b"\xff"
elif:
if microcontroller.nvm[0:1] == b"\xff":
microcontroller.nvm[0:1] = b"\x00"
else:
microcontroller.nvm[0:1] = b"\x00" You can't have If that's a red-herring typo, could you show the actual |
Yup, Let me change it back and retest. |
Changed back. I'll have to go look for your smarter code.
|
Dan, I had to change your 'smaller' code example as below. go_dev_mode = True
mode = (microcontroller.nvm[0] == 0xff)
if mode != go_dev_mode:
microcontroller.nvm[0] = 0xff if go_dev_mode else 0x00 |
I am just looking for a small piece of code that causes the safe mode problem, regardless of whether or not it's really doing the mode logic correctly. |
I added extra code to my boot.py file. The NeoPixel flashes as appropriate before the crash. It runs fully. It looks like after the byte in NVM is changed the crash happens during the boot.py hand-off to code.py. I commented out line 47. Here is a .zip of my boot file. |
@b-blake I am unable to cause safe mode with the boot.py you gave. Here is a much simpler test, which always writes boot.py import microcontroller
microcontroller.nvm[0] = (microcontroller.nvm[0] + 1) % 256 code.py import microcontroller
import time
while True:
time.sleep(1)
print(f"{microcontroller.nvm[0]=}") You should see Does this cause safe mode for you? It does not for me. I am running this on 9.2.0 on a Feather RP2350. |
I have found that the problem is adafruit_foo.py {sometimes}. Below is my boot.pt and a very cut down code.py, all of it. If you run as it is, it runs fine, just like Dan's boot.py & code.py. If you uncomment any one of the ignored adafruit_ libraries, it crashes. Why it likes and doesn't like is a mystery to me. FYI I have unzipped all the afafruit libraries in the /lib directory boot.py
code.py
|
If you remove your cut-down Could you erase CIRCUITPY and reinstall those libraries? It's possible one or more of them is corrupted in some way that's causing a hard crash. |
No boot.py, no crash. restored boot.py copied all files to desktop folder EDIT by @dhalbert per comment below. |
Thanks, that's straightforward; I'll attempt to reproduce. |
No change is crash. I was not clear |
I've reproduced this and am working on a fix. |
@b-blake #9783 has a prospective fix. There are builds to try in the "Artifacts" listing here if you would like to test: https://github.com/adafruit/circuitpython/actions/runs/11637328418?pr=9783 |
Thanks for testing. I don't think it's a specific library, but it may have to do with the size of the library. I got it down to importing |
CircuitPython version
Code/REPL
Behavior
In boot.py...
If you change go_dev_mode to 0xff from 0x00 or 0x00 from 0xff the RP2350 MCU crashes to Safe Mode when the RESET button is pushed. Also if you remove and restore power.
Description
The crash happens the first time RESET is pushed after value is changed. The second time RESET is pushed the NVM byte has been changed and no crash happens. When changed back, crash happens on the first RESET, good on the second.
Additional information
No response
The text was updated successfully, but these errors were encountered: