Giter VIP home page Giter VIP logo

unbrickpipicopython's Introduction

PI Pico - how to unbrick from infinite loop in python

The problem

As a genius in programming I was interrested in how PI Pico will deal with infinite loop of some math (may to be hot?), so I made a "code" with While True :. Right after I press "Run" in Thonny, it saves program into memory, so a second after Pico disappear from device list. BOOM.

You can put any new .uf2 sketch and it will works fine. You can start in BOOTSEL mode, but here is no "wrong" file - just initial files with help, which doesn't help much. As soon as you put python' .uf2 back (say instead of blink), it returns to infinite loop.

This wasn't my plan.

The Idea

Well, if Pico works with any other program, the thing is in code of python interpretator, which runs main.py right after start. This file doesn't exists in "file" folder, so here have to be other one - probably virtual - disk with files visible from Thonny (which can't be used now as soon as Pico cannot communicate via virtual comport).

So how does Pico stores files for python?

Fast and bored solution

Well, if You will scroll down the page "Getting started with Pico" you will found uf2 for Resetting Flash memory.

OR you can read below

Tools

  1. Go to picotool and install it (you can find detailed instruction in Pico books)
  2. Find what HEX-editor is suitable for you, in my case it is "Sublime Text" and viewer (in my case MC)
  3. A terminal window

How to

  1. Put python' .uf2 back to Pico using BOOTSEL mode. Pico will restart and hangs, but in our case it is OK
  2. Reboot Pico in BOOTSEL mode again to operate with picotool
  3. Use picotool info -a and find address info of embedded drive, in my case embedded drive: 0x100a0000-0x10200000 (1408K): MicroPython
  4. Lets dump it using picotool save -r 0x100a0000 0x10200000 ~/Desktop/pico.bin this will give us 1441792 bytes file
  5. Make copy: cp ~/Desktop/pico.bin ~/Desktop/pico.bak just for a case
  6. Open .bin file in HEX viewer to be sure you see something like 6C69 7474 6C65 6673 2FE0 (which is littlefs/ btw)
  7. Scroll through file to find your wrong code
  8. Simple edit your code, may be overwriting first letters of each row with hash (# is 23 in HEX) OR do as I did: put FF instead whole code
  9. Save binary file and check its size (must be same!)
  10. Now it is time to return file to Pico: picotool load ~/Desktop/pico.bin -t bin -o 0x100a0000
  11. Reboot: picotool reboot

It was fun

Well, I make it brick right in 11th minute of the very first try. I tried to find a solution in internet but wasn't succeed. So I've documented what found in next 40 minutes. It was FUN!

The ticket

Posted here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.