Platformio Debug - Pico or Pico-W debug with raspberrypi debug probe

I’ve install VSCode and platformio. Then i add the raspberrypi pico board and so on. I create an example project and now i want to debug a simple blink example. To use the debug probe i’ve edit the platformio.ini with:

[env]
platform = //github.com/maxgerhardt/platform-raspberrypi.git
framework = arduino
board_build.core = earlephilhower
board_build.filesystem_size = 0.5m

[env:pico]
board = pico
; if using picoprobe SWD upload / debugging
upload_protocol = cmsis-dap
debug_tool = cmsis-dap
; note: newer PicoProbe firmwares emulate a CMSIS-DAP, so you
; use “cmsis-dap” as upload_protocol and debug_tool.
; for more info see docs
build_type = debug

Now i could build the project successfully and i could upload it to an pico via the debug probe. Now i want to debug the simple project. I select the VSCode debugger and select the first debugger. The build process is still successfully the debugger starts sometime i could see the debug bar. But after two seconds the debugger is still closed without an error message. The launch.json is:

// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
//
// PIO Unified Debugger
//
// Documentation: 
// Configuration: 

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug",
            "executable": "PlatformIO/Projects/230927-082714-arduino-blink/.pio/build/pico/firmware.elf",
            "projectEnvName": "pico",
            "toolchainBinDir": ".platformio/packages/toolchain-rp2040-earlephilhower/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "svdPath": ".platformio/platforms/raspberrypi@src-ff76a3915224135aafad379817f41edd/misc/svd/rp2040.svd",
            "preLaunchTask": {
                "type": "PlatformIO",
                "task": "Pre-Debug"
            }
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (skip Pre-Debug)",
            "executable": "PlatformIO/Projects/230927-082714-arduino-blink/.pio/build/pico/firmware.elf",
            "projectEnvName": "pico",
            "toolchainBinDir": ".platformio/packages/toolchain-rp2040-earlephilhower/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "svdPath": ".platformio/platforms/raspberrypi@src-ff76a3915224135aafad379817f41edd/misc/svd/rp2040.svd"
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (without uploading)",
            "executable": "PlatformIO/Projects/230927-082714-arduino-blink/.pio/build/pico/firmware.elf",
            "projectEnvName": "pico",
            "toolchainBinDir": ".platformio/packages/toolchain-rp2040-earlephilhower/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "svdPath": ".platformio/platforms/raspberrypi@src-ff76a3915224135aafad379817f41edd/misc/svd/rp2040.svd",
            "loadMode": "manual"
        }
    ]
}

Could anybody help me to debug my pico/pico-w with the original raspberrypi debug probe?

Thx

1 Like

If the “Debug” tab in VSCode is empty, you might be running into one of the already solved issues of https://github.com/earlephilhower/pico-quick-toolchain/issues/30.

What I want you to do is simply:

  1. Delete ~/.platformio/packages/toolchain-rp2040-earlephilhower
  2. Delete ~/.platformio/platforms/raspberrypi*
  3. Delete ~/.platformio/.cache

Build the project again. This should install the newest toolchain and platform versions of everything. Then try debugging again.

Hi max,

okay i tried it - but it was not successful. The first thing is: the option toolchainBinDir in the launch.json was set to toolchain-rp2040-earlephilhower. After the project rebuild the tool-openocd-rp2040-earlephilhower was generated and i could edit the option to the new entry. When i start the debugger again. I could not debug because the debugger starts for 2 second and end without an error message.

Resolving pico dependencies...

Platform Manager: Installing git+//github.com/maxgerhardt/platform-raspberrypi.git

git version 2.42.0.windows.2

Cloning into 'C:\Users\benny\.platformio\.cache\tmp\pkg-installing-3c7r5ulv'...

Submodule 'builder/frameworks/arduino/mbed-core' (s://github.com/platformio/builder-framework-arduino-core-mbed.git) registered for path 'builder/frameworks/arduino/mbed-core'

Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-3c7r5ulv/builder/frameworks/arduino/mbed-core'...

Submodule path 'builder/frameworks/arduino/mbed-core': checked out '6174f769bfc8610a397ed0c912cd059246e547cd'

Platform Manager: raspberrypi@1.9.0+sha.612de53 has been installed!

Tool Manager: Installing s://github.com/earlephilhower/pico-quick-toolchain/releases/download/2.1.0-a/x86_64-w64-mingw32.arm-none-eabi-d3d2e6b.230911.zip

Tool Manager: toolchain-rp2040-earlephilhower@5.120300.230911 has been installed!

Tool Manager: Installing git+s://github.com/earlephilhower/arduino-pico.git#41b0686aec4b0655e518e3ef98379131ad3773fa

git version 2.42.0.windows.2

Cloning into 'C:\Users\benny\.platformio\.cache\tmp\pkg-installing-l6wqdsek'...

Updating files: 100% (912/912), done.

Submodule 'ArduinoCore-API' (ttps://github.com/earlephilhower/ArduinoCore-API.git) registered for path 'ArduinoCore-API'

Submodule 'libraries/Adafruit_TinyUSB_Arduino' (ttps://github.com/adafruit/Adafruit_TinyUSB_Arduino.git) registered for path 'libraries/Adafruit_TinyUSB_Arduino'

Submodule 'pico-sdk' (ttps://github.com/raspberrypi/pico-sdk.git) registered for path 'pico-sdk'

Submodule 'system/pyserial' (ttps://github.com/pyserial/pyserial.git) registered for path 'tools/pyserial'

Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-l6wqdsek/ArduinoCore-API'...

Submodule path 'ArduinoCore-API': checked out 'ece6e68f29c6f406a4434659bcbcfe558baaa3a9'

Submodule path 'pico-sdk': checked out '6a7db34ff63345a7badec79ebea3aaef1712f374'

Submodule 'lib/cyw43-driver' (ttps://github.com/georgerobotics/cyw43-driver.git) registered for path 'pico-sdk/lib/cyw43-driver'

Submodule 'lib/mbedtls' (ttps://github.com/Mbed-TLS/mbedtls.git) registered for path 'pico-sdk/lib/mbedtls'

Submodule path 'pico-sdk/lib/cyw43-driver': checked out '8ef38a6d32c54f850bff8f189bdca19ded33792a'

Submodule path 'pico-sdk/lib/mbedtls': checked out 'a77287f8fa6b76f74984121fdafc8563147435c8'

Submodule 'hw/mcu/raspberry_pi/Pico-PIO-USB' (ttps://github.com/sekigon-gonnoc/Pico-PIO-USB.git) registered for path 'pico-sdk/lib/tinyusb/hw/mcu/raspberry_pi/Pico-PIO-USB'

Submodule 'lib/CMSIS_5' (ttps://github.com/ARM-software/CMSIS_5.git) registered for path 'pico-sdk/lib/tinyusb/lib/CMSIS_5'

Submodule 'tools/uf2' (ttps://github.com/microsoft/uf2.git) registered for path 'pico-sdk/lib/tinyusb/tools/uf2'

Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-l6wqdsek/pico-sdk/lib/tinyusb/hw/mcu/allwinner'...

Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-l6wqdsek/pico-sdk/lib/tinyusb/hw/mcu/raspberry_pi/Pico-PIO-USB'...

Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-l6wqdsek/pico-sdk/lib/tinyusb/hw/mcu/ti'...

Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-l6wqdsek/pico-sdk/lib/tinyusb/hw/mcu/wch/ch32v307'...

Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-l6wqdsek/pico-sdk/lib/tinyusb/lib/CMSIS_5'...


Cloning into 'C:/Users/benny/.platformio/.cache/tmp/pkg-installing-l6wqdsek/pico-sdk/lib/tinyusb/tools/uf2'...

Submodule path 'pico-sdk/lib/tinyusb/hw/mcu/allwinner': checked out '8e5e89e8e132c0fd90e72d5422e5d3d68232b756'

Submodule 'firmware.wiki' (ttps://github.com/raspberrypi/firmware.wiki.git) registered for path 'pico-sdk/lib/tinyusb/hw/mcu/broadcom/firmware.wiki'

Submodule path 'pico-sdk/lib/tinyusb/hw/mcu/raspberry_pi/Pico-PIO-USB': checked out '52805e6d92556e67d3738bd8fb10227a45b13a08'

Submodule path 'pico-sdk/lib/tinyusb/tools/uf2': checked out '19615407727073e36d81bf239c52108ba92e7660'


Submodule path 'tools/pyserial': checked out '0e7634747568547b8a7f9fd0c48ed74f16af4b23'

HEAD is now at 41b0686 Update version

Submodule path 'ArduinoCore-API': checked out 'ece6e68f29c6f406a4434659bcbcfe558baaa3a9'

Submodule path 'pico-sdk': checked out '6a7db34ff63345a7badec79ebea3aaef1712f374'

Submodule path 'pico-sdk/lib/tinyusb/tools/uf2': checked out '19615407727073e36d81bf239c52108ba92e7660'

Submodule path 'pico-sdk/lib/tinyusb/tools/uf2/hidapi': checked out 'a6a622ffb680c55da0de787ff93b80280498330f'

Submodule path 'tools/libbearssl/bearssl': checked out 'f294aa022f82833941ffdf3b0f306c2072e3a26c'

Submodule path 'tools/pyserial': checked out '0e7634747568547b8a7f9fd0c48ed74f16af4b23'

Tool Manager: framework-arduinopico@1.30600.0+sha.41b0686 has been installed!

Tool Manager: Installing platformio/tool-rp2040tools @ ~1.0.2

Tool Manager: tool-rp2040tools@1.0.2 has been installed!

Tool Manager: Installing platformio/tool-scons @ ~4.40502.0

Tool Manager: tool-scons@4.40502.0 has been installed!

Updating metadata for the vscode IDE...

Project has been successfully updated!

Do you have any other idea why the debugger does not work?

Is there no text in the “Debug” tab at all?

What happens when you start PlatformIO core CLI and execute

pio debug --interface=gdb -- -x .pioinit

?

okay when i execute the command in the cli i get nothing out:

230927-082714-arduino-blink> pio debug --interface=gdb – -x .pioinit
230927-082714-arduino-blink>

In that same PlatformIO CLI, can you now execute

C:/Users/benny/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-gdb.exe --version

What is the output? Does an error message pop up?

The execution failed. exitcode is 1

Is that the exact text? Can you please make a screenshot of that? (Windows + Shift + S → rectangle select → Ctrl+V here)

when i execute the command in a seperate cmd i get the following error message:

grafik

Oh okay.

So that is exactly the linked issue but I didn’t realize the URLs had updated, I thought they stayed the same. But they added a -v2 to the toolchain download.

Let me quickly correct that and get back to you…

I’ve pushed Use actually updated toolchain links · maxgerhardt/platform-raspberrypi@ffb6889 · GitHub to counteract this.

Please close VSCode, then follow this exact procedure again

Then restart VSCode, build the project again, hit Debug again. It should now at least try to start GDB and OpenOCD.

Okay, now i could debug successfull. Very good! Thank you for your very fast answers and yout help!

The framework setup still support the pico-w or?

A Pico W is just a Pico with a Broadcom WiFi chip slapped on top via SDIO. It should still be as debuggable as a regular Pico or any RP2040-based board.

Hi max,

i transfer the project to an raspi (PI4 8GB) and i tried to debug the project on this platform. But i get the following error messages:
Downloading…
Unpacking…
Tool Manager: tool-openocd-rp2040-earlephilhower@5.120300.230911 has been installed!
Warning! Your /etc/udev/rules.d/99-platformio-udev.rules are outdated. Please update or reinstall them.
More details: 99-platformio-udev.rules — PlatformIO latest documentation
Reading symbols from /home/pi/Dokumente/PlatformIO/Projects/230927-203225-arduino-blink/.pio/build/pico/firmware.elf…
Warning: ‘set target-async’, an alias for the command ‘set mi-async’, is deprecated.
Use ‘set mi-async’.

PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = cmsis-dap
PlatformIO: Initializing remote target…
/home/pi/.platformio/packages/tool-openocd-rp2040-earlephilhower/bin/openocd: error while loading shared libraries: libhidapi-hidraw.so.0: cannot open shared object file: No such file or directory
.pioinit:13: Error in sourced command file:
Remote communication error. Target disconnected.: Die Verbindung wurde vom Kommunikationspartner zur�ckgesetzt.

Could you help me?

Thx

Some of the toolchain binaries require preinstalled libraries. A quick

sudo apt update && sudo apt install libhidapi-hidraw0 libhidapi-libusb0

should resolve this, no? And of course, you should follow PlatformIO’s suggestion of installing udev rules (and user group permissions) per the link above.

Sorry for the late answer. Yes of course this is the solution for thr problem. Now it is still working.

I have a similar issue: platformio debugging a pico with the debug probe does not work (Fedora 38). It hangs and runs into a timeout.

[env:picow-debugprobe]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
framework = arduino
board = pico
board_build.filesystem_size = 0.5m
board_build.core = earlephilhower
upload_protocol = cmsis-dap
debug_speed = 5000
debug_init_break = tbreak setup
debug_port = /dev/ttyACM0
debug_tool = cmsis-dap

When the PIO debug session is started I get the following output in the debug console:
(which is the same as for pio debug --interface=gdb – -x .pioinit)

Open On-Chip Debugger 0.12.0-g4d87f6dca (2023-09-11-23:12)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E661640843995133
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001
Info : [rp2040.core0] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core0] target has 4 breakpoints, 2 watchpoints
Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
/home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-gdb: /usr/lib64/libtinfo.so.5: no version information available (required by /home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-gdb)
Reading symbols from /home/manuel/Documents/PlatformIO/Projects/PicoBlinky/.pio/build/picow-debugprobe/firmware.elf...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = cmsis-dap
PlatformIO: Initializing remote target...
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response

So here it hangs and there is a timeout after a while.

However, if I manually launch openocd and gdb it works:

"$ /home/manuel/.platformio/packages/tool-openocd-rp2040-earlephilhower/bin/openocd" -f "interface/cmsis-dap.cfg" -f "target/rp2040.cfg"
 -c "adapter speed 5000" -c "program {.pio/build/picow-debugprobe/firmware.elf} verify
" -c "reset init" -c "resume"
Open On-Chip Debugger 0.12.0-g4d87f6dca (2023-09-11-23:12)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz

Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E661640843995133
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001
Info : [rp2040.core0] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core0] target has 4 breakpoints, 2 watchpoints
Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
[rp2040.core0] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
[rp2040.core1] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
** Programming Started **
Info : Found flash device 'win w25q16jv' (ID 0x001540ef)
Info : RP2040 B0 Flash Probe: 2097152 bytes @0x10000000, in 32 sectors

Info : Padding image section 1 at 0x100173f0 with 16 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x10017400 .. 0x1001ffff
** Programming Finished **
** Verify Started **
** Verified OK **
[rp2040.core0] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
[rp2040.core1] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : accepting 'gdb' connection on tcp/3333
Info : New GDB Connection: 1, Target rp2040.core0, state: halted
[rp2040.core0] halted due to debug-request, current mode: Thread 
xPSR: 0x41000000 pc: 0x10009692 msp: 0x20041ef8
[rp2040.core1] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000184 msp: 0x20041f00

Also using a cortex-debug launch configuration works:

        {
            "name": "Pico Debug",
            "cwd": "${workspaceRoot}",
            "executable": "/home/manuel/Documents/PlatformIO/Projects/PicoBlinky/.pio/build/picow-debugprobe/firmware.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd",
            "gdbPath": "/home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-gdb",
            "device": "RP2040",
            "configFiles": [
                "interface/cmsis-dap.cfg",
                "target/rp2040.cfg"
            ],
            "svdFile": "/home/manuel/.platformio/platforms/raspberrypi/misc/svd/rp2040.svd",
            "runToEntryPoint": "setup",
            "postRestartCommands": [
                "break setup",
                "continue"
            ]
        }
Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage

Reading symbols from /home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-objdump --syms -C -h -w /home/manuel/Documents/PlatformIO/Projects/PicoBlinky/.pio/build/picow-debugprobe/firmware.elf

Reading symbols from /home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-nm --defined-only -S -l -C -p /home/manuel/Documents/PlatformIO/Projects/PicoBlinky/.pio/build/picow-debugprobe/firmware.elf

Launching GDB: /home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-gdb -q --interpreter=mi2

IMPORTANT: Set "showDevDebugOutput": "raw" in "launch.json" to see verbose GDB transactions here. Very helpful to debug issues or report problems

Launching gdb-server: openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /home/manuel/Documents/PlatformIO/Projects/PicoBlinky -f /home/manuel/.vscode/extensions/marus25.cortex-debug-1.12.1/support/openocd-helpers.tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg

Please check TERMINAL tab (gdb-server) for output from openocd

Finished reading symbols from objdump: Time: 43 ms

/home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-gdb: /usr/lib64/libtinfo.so.5: no version information available (required by /home/manuel/.platformio/packages/toolchain-rp2040-earlephilhower/bin/arm-none-eabi-gdb)

Output radix now set to decimal 10, hex a, octal 12.
Input radix now set to decimal 10, hex a, octal 12.
Finished reading symbols from nm: Time: 102 ms

warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread
setup () at src/main.cpp:83
83	void setup() {
Program stopped, probably due to a reset and/or halt issued by debugger
[rp2040.core0] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
[rp2040.core1] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
[rp2040.core0] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
[rp2040.core1] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
Note: automatically using hardware breakpoints for read-only addresses.

Thread 1 "rp2040.core0" hit Temporary breakpoint 2, setup () at src/main.cpp:83
83	void setup() {

Is this arm-none-eabi-gdb refusing to launch because it doesn’t have libtinfo.so.5? Can you try the suggestions from https://stackoverflow.com/questions/48674104/clang-error-while-loading-shared-libraries-libtinfo-so-5-cannot-open-shared-o for installing it / symlinking it to the v6 version?