Skip to content
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

Code gets wiped when power-cycling between 2.8 and 3.0 seconds #5514

Closed
shabaz123 opened this issue Oct 26, 2021 · 4 comments · Fixed by #5536
Closed

Code gets wiped when power-cycling between 2.8 and 3.0 seconds #5514

shabaz123 opened this issue Oct 26, 2021 · 4 comments · Fixed by #5536
Assignees
Labels
bug rp2040 Raspberry Pi RP2040
Milestone

Comments

@shabaz123
Copy link

CircuitPython version

Adafruit CircuitPython 7.0.0 on 2021-09-20; Raspberry Pi Pico with rp2040

Code/REPL

import board
import time
import digitalio

# variables
forever = 1

# main program
def main():
    heartbeat_toggle = False
    print("Hello")
    boardled = digitalio.DigitalInOut(board.GP25)
    boardled.direction = digitalio.Direction.OUTPUT
    out0 = digitalio.DigitalInOut(board.GP0)
    out0.direction = digitalio.Direction.OUTPUT
    while forever:
        heartbeat_toggle = not (heartbeat_toggle)
        boardled.value = heartbeat_toggle  # toggle the LED
        out0.value = heartbeat_toggle  # toggle GPIO0
        time.sleep(0.1)

main()

Behavior

Hello, seeing an issue with the official 7.0 release of CircuitPython on Pi Pico.

It seems to handle power-cycling quite badly.. the chances are high that when a user plugs/unplugs a battery or controls a power switch, that the user's code.py could be wiped from Flash. There's at least a 200msec window where this happens.

Also, it takes a very long time (just over 3 seconds) for the code.py to start executing.

I only investigated because it happened several times to me within a week, just connecting/disconnecting a Battery with LDO regulator, and noticing my code was gone.

To test it, I stripped down my code.py to just an LED blink program, and then applied power under control of a script to switch the power on/off on the VSYS pin. It seems to only be an issue in 7.0. I tried the older 6.2 release and that behaves as expected, with a 1-second delay before code.py execution. I could not get that version 6.2 to fail with power cycling at 100msec increments between 100msec and 1 seconds. However with version 7.0, the startup time is just slightly over 3 seconds and I tried power cycling version 7.0 and between 2.8 seconds and 3.0 seconds the code gets wiped. I recorded a private unlisted YouTube video here showing the issue:

https://youtu.be/eG4jziJHroE

Description

CircuitPython 7.0 startup time to execute code.py is unusually long (just over 3 seconds), and if a power-cycle occurs just before then, at 2.8-3.0 seconds, then the code gets wiped and the default code.py runs. The user code is permanently gone and then needs transferring again via USB.

The period 2.8-3.0 seconds might sound very specific, but I randomly got the problem to occur by just plugging a battery + LDO voltage regulator on/off the Pico board, occurring for me several times within a week just by accident.

I have tested with two Pi Pico boards, and they both had the same issue.

Also, the 3-second delay before code.py execution will cause issues because kids are not expecting to wait so long between pushing a power button on, and using their Pi Pico projects. That then causes a high probability that they will power-cycle within that time, a bit like pressing a button on a TV remote repeatedly if it doesn't respond in the expected time.

Additional information

Using release 6.2 resolves the issue (startup time is reduced from 3 seconds to 1 second, and the code wiping issue has not been observed).

@shabaz123 shabaz123 added the bug label Oct 26, 2021
@dhalbert
Copy link
Collaborator

Thanks for the report. You mentioned 6.2.0. Did you also test with 6.3.0? That would just help us narrow it down.

@shabaz123
Copy link
Author

Hi @dhalbert thanks for the response! Release 6.3 seems fine too. With release 6.3, the code.py startup time is slightly longer than release 6.2. Startup time is about 350 msec longer with release 6.3 compared to the approx 1-second startup time of release 6.2.
I tried power-cycling at 1.2, 1.3, 1.4 and 3.0 second intervals with release 6.2, and there was no code-wiping observed.

@tannewt tannewt added the rp2040 Raspberry Pi RP2040 label Oct 28, 2021
@tannewt tannewt added this to the Long term milestone Oct 28, 2021
@dhalbert dhalbert self-assigned this Nov 1, 2021
@dhalbert
Copy link
Collaborator

dhalbert commented Nov 1, 2021

I think this is because we are writing more info to boot_out.txt, but the code that checks to see whether boot_out.txt needs rewriting is not taking that new info into account. So boot_out.txt is being rewritten on every hard reset. That rewrite delays for 1.5 seconds, which would explain the longer boot time. The rewrite also explains the wiping: if you remove power in the middle of the write, it will corrupt the filesystem. I'll work on a fix.

@dhalbert dhalbert modified the milestones: Long term, 7.x.x Nov 1, 2021
@tannewt tannewt modified the milestones: 7.x.x, 7.1.0 Nov 1, 2021
@dhalbert
Copy link
Collaborator

dhalbert commented Nov 3, 2021

Fixed by #5536.

@dhalbert dhalbert closed this as completed Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rp2040 Raspberry Pi RP2040
Projects
None yet
3 participants