We just gave MicroPython something it has never had: a real debugger.
Set a breakpoint in VS Code. Press F5. Your code deploys to the board and execution stops on that line, with the call stack, your variables, and a working watch window. No JTAG, no debug probe, no extra wiring. One USB cable.
If you have written embedded Python, you know the alternative: scatter print statements, reflash, guess, repeat.
Why we could build this: we have shipped a source-level debugger for C# on microcontrollers for years, in production devices. The hard part was never the VS Code side. It was the protocol running on a chip with kilobytes of RAM, and we already had that working. We brought it to MicroPython.
It is free, MIT licensed, and works on Raspberry Pi Pico, Pico 2, and ESP32-S2/S3 boards. Firmware installs from inside the extension.
4 Likes
Thank you, Gus for that functionality.
That’s really great.
I quickly tried setting a breakpoint in a test program and stepping through the program line by line, and it works pretty well.
However the default for the debugger’s handling of exceptions is not yet optimal.
Maybe I missed something in the UI regarding how to ignore all or individual exceptions?
For example, my test program uses the “Microdot” (WebServer) library: The library can be used in various environments and therefore attempts to load platform-specific libraries using the import statement. As the libraries are only available on some systems and hence cannot be imported, they are handled specifically in the code:
try:
import orjson as json
except ImportError:
import json
produces
Uncaught exception: ImportError(“no module named ‘orjson’”,)
I think the programming in “Microdot” is a valid approach, but you have to manually skip all these exceptions one by one every time you start the debugger.
Also, the async-await implementation internally throws an exception when an async operation has completed.
await asyncio.sleep (sleep_secs)
produces
Uncaught exception: StopIteration()
This makes it somewhat annoying to wait for a normal breakpoint while the program is running, since asynchronous tasks are constantly completing and their exceptions must be handled manually.
Thank you for the feedback. We will look into it soon.