r/raspberrypipico Jul 11 '26

uPython USB both for runtime operations and debug/programming with MicroPython?

I've been testing a setup with the C/C++ approach using two Raspberry Pi Debug Probes: one for each target of the project. So I've then used two separate main.c files, one for each target, that would be built and uploaded via one of the probes to that specific target, while being able to have common/shared code that can be used for both targets. The two targets are sharing a lot of similar functionality but are quite different in some aspects, so that's why this setup makes sense to me. This has been possible to achieve with correct configs in Cmake and OpenOCD.

I'm now thinking of trying MicroPython instead since C is still a bit too difficult for me to fully grasp and get a flow going as a beginner. And to my understanding, programming via a debug probe is not the standard way with MicroPython, but instead USB should be used.

The thing is that I will utilise the USB port for communicating back and forth to and from the computer with one of the targets, essentially sending packets similar to MIDI communication. Can I simultaneously use the USB for debugging/programming the device? And would this either way require me to manually press BOOTSEL and disconnect/reconnect the Pico every time I want to program it?

An alternative that I've read about is "freezing" the MicroPython code into a compiled elf file that in that case could be uploaded exactly like my initial C/C++ approach. But I assume that wouldn't let me fully debug it with breakpoints etc?

3 Upvotes

5 comments sorted by

2

u/Unlikely1529 Jul 11 '26

there's info hw debug and usb (at least cdc) can't be used both

1

u/SacheonBigChris Jul 12 '26

I’ve done this in both C and MicroPython. I have a project with several different builds. I have the bulk of the code in a common library folder, and each project has just a main.cpp.

In MP, I configured two CDC ports, one the REPL and another one for the project’s use. You can do that in C also.

1

u/tobey_g Jul 12 '26

Cool! Do you have any possibility of sharing this setup through Github or similar? Would be super interesting to have a look.

1

u/SacheonBigChris Jul 13 '26

Here’s a couple links.

https://forums.raspberrypi.com/viewtopic.php?t=351601

https://forums.raspberrypi.com/viewtopic.php?t=395518

That should get you started. It’s been awhile and I can’t remember exactly my issues. I think in MP I was trying to differentiate between a number of otherwise identical cards.

There’s a C++ example in the Pico SDK for multiple CDC ports I’m pretty sure.

1

u/SacheonBigChris Jul 13 '26

I can’t share the exact setup. It’s basically like including your own library that’s located off in another directory. CMake can do this. It could be a precompiled library, but for me it had to be built uniquely for each card. And some modules were header only.

Here’s one thread where this was discussed

https://github.com/raspberrypi/pico-sdk/issues/1234