Page 1 of 1

Raspberry Pi Pico factory reset

Posted: Fri Jul 16, 2021 2:14 pm
by amir
Hi,
I have uploaded a main.py to my pi pico that works with UART and writes on a file at the same time. As a result the pi pico hangs and can not continue. (I have added a periodic flashing code as well to determine the health of the program).

Now I just want to get rid of main.py but every time I plug it into the USB whether I hold BOOTSEL or not it starts running and hanging !!!

Is there a way to tell pi pico to start without running the main.py ?

I tried to connect pin 11 (RUN(RESET)) to the Ground but it cause the board to stop being a usb storage as well !

so I am really out of options to prevent that code to run.

When I hold the BOOTSEL button and connect the USB I see this error message when I try to connect using rshell :

Code: Select all

Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>rshell
Connecting to COM7 (buffer-size 128)...
Trying to connect to REPL  connected
Retrieving sysname ... b'OK\r\nMPY: soft r'
Traceback (most recent call last):
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\Scripts\rshell-script.py", line 33, in <module>
    sys.exit(load_entry_point('rshell==0.0.29', 'console_scripts', 'rshell')())
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\command_line.py", line 4, in main
    rshell.main.main()
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 3084, in main
    real_main()
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 3050, in real_main
    autoscan()
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 332, in autoscan
    connect_serial(port[0])
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 1413, in connect_serial
    dev = DeviceSerial(port, baud, wait)
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 1744, in __init__
    Device.__init__(self, pyb)
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 1497, in __init__
    self.sysname = self.remote_eval(sysname)
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 1632, in remote_eval
    return eval(self.remote(func, *args, **kwargs))
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 1610, in remote
    self.pyb.enter_raw_repl()
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\pyboard.py", line 203, in enter_raw_repl
    raise PyboardError('could not enter raw repl')
rshell.pyboard.PyboardError: could not enter raw repl

C:\WINDOWS\system32>
also my rshell is pico friendly.

I am sure all of these goes back to that problematic main.py.

I should get rid of it or factory reset the board.

Please introduce me more options to delete or prevent main.py from running .... 🤒

Re: Raspberry Pi Pico factory reset

Posted: Fri Jul 16, 2021 3:56 pm
by Roberthh
There is a special .uf2 image which just wipes out the whole flash. I could not find the link again, but IO have a copy of that file. After running it, you must install the firmware .uf file again.
flash_nuke.zip
(8.87 KiB) Downloaded 12264 times

Re: Raspberry Pi Pico factory reset

Posted: Fri Jul 16, 2021 4:24 pm
by hippy

Re: Raspberry Pi Pico factory reset

Posted: Fri Jul 16, 2021 4:32 pm
by fdufnews
flash_nuke will erase all the flash. if the problem is only an "uncontrolled" main.py there is a less damaging solution.
https://www.raspberrypi.org/forums/view ... 6&t=305432
MicroPython_RenameMainDotPy only zap main.py and preserve the filesystem so if you already have any file saved on the file system they will be kept.

Edit: It seems that hippy has been faster than me.

Re: Raspberry Pi Pico factory reset

Posted: Sat Jul 17, 2021 12:01 am
by amir
Thanks to Roberthh / hippy / fdufnews , I learned two methods to restore a Pi Pico 👍
Although I restored the Pi Pico with the nuke method but I also successfully tested the rename method as well which is really useful when there are log files on the file system.

Thanks again and have a good one everyone.