Raspberry Pi Pico factory reset

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
Posts: 2
Joined: Fri Jul 16, 2021 1:58 pm

Raspberry Pi Pico factory reset

Post by amir » Fri Jul 16, 2021 2:14 pm

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.

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
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 3084, in main
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 3050, in real_main
  File "C:\Users\Unknown\AppData\Local\Programs\Python\Python39\lib\site-packages\rshell\main.py", line 332, in autoscan
  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
  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

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 .... 🤒

User avatar
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Raspberry Pi Pico factory reset

Post by Roberthh » Fri Jul 16, 2021 3:56 pm

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.
(8.87 KiB) Downloaded 8517 times

Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: Raspberry Pi Pico factory reset

Post by hippy » Fri Jul 16, 2021 4:24 pm

Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: Raspberry Pi Pico factory reset

Post by fdufnews » Fri Jul 16, 2021 4:32 pm

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.
Last edited by fdufnews on Sat Jul 17, 2021 7:13 am, edited 1 time in total.

Posts: 2
Joined: Fri Jul 16, 2021 1:58 pm

Re: Raspberry Pi Pico factory reset

Post by amir » Sat Jul 17, 2021 12:01 am

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.

Post Reply