Cannot debug Pi Pico with CMSIS-DAP - "CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed"

Hi! This is my first post here, so please forgive me if I did something wrong or missed a rule somewhere!

I am trying to configure PlatformIO to be able to debug a Raspberry Pi Pico. I used pico-debug to be able to use the CMSIS-DAP debug interface with my Pico, and am able to connect using openocd and gdb-multiarch, using the command
openocd -f interface/cmsis-dap.cfg -c "transport select swd" -c "adapter speed 4000" -f target/rp2040-core0.cfg,
but when I attempt to debug with PlatformIO, I am faced with an error:

Reading symbols from /home/neilbaner/Documents/PlatformIO/Projects/pico-demo/.pio/build/pico/firmware.elf...
PlatformIO Unified Debugger ->
PlatformIO: debug_tool = cmsis-dap
PlatformIO: Initializing remote target...
Open On-Chip Debugger 0.11.0+dev-gec0240e6a-dirty (2021-03-09-09:49)
Licensed under GNU GPL v2
For bug reports, read
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : tcl server disabled
Info : telnet server disabled
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Serial# = E6605838830B8B34
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Error: CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed.

.pioinit:13: Error in sourced command file:
Remote communication error.  Target disconnected.: Connection reset by peer.

I have tried this using VS Code on both Windows 10 and Linux (Mint); both throw the same error. I thought this may be to do with the debug clock speed being set incorrectly, so I tried setting debug_speed to various values: 4000 (because that’s what was in the command I used), 133000 (clock speed of the Pico), 4 (just in case) - none of these worked.

Edited to add: Here are the contents of my platformio.ini file:

platform = raspberrypi
board = pico
framework = arduino
upload_port = /dev/ttyACM0
debug_speed = 4000

Does anyone have any idea where I’m going wrong?


Did you manage to get it working? I’m having the same problem trying to use a DAPLink device to debug on Pi Pico. (on MacOS in my case)

Nope. Got busy with other things and haven’t had time to try since.

Did you see Error CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed – Alan C. Assis where you have to add the adapter speed in the config file? (Likely C:\Users\<user>\.platformio\packages\tool-openocd-raspberrypi\share\openocd\scripts\interface\cmsis-dap.cfg)

To my knowledge, due to issue Call to configure_debug_options() gone · Issue #4020 · platformio/platformio-core · GitHub, it prevents setting the adapter speed per this code, so you have to do that workaround now…

1 Like

Btw, I have debugging working via a Picoprobe (aka another Pico loaded with a CMSIS-DAP firmware provided by the Raspberry Pi foundation), and it can debug the Arduino-mbed core just fine. Even sees both Cortex-M0+ cores.

That’s using the third environment (pico_standard) in my GitHub - maxgerhardt/pio-pico-core-earlephilhower-test: Test firmware that uses the earlephilhower Arduino core. project. Only works on Windows as of now because of a precompiled OpenOCD version with Picoprobe support.

I tried hard to make your example work on a Windows10 OS with the latest PlatfomIO installed. I have two Picos wired together, one working as picoprobe and with USB driver changed.
Finally I more or less copy-pasted your .ini file, everything got updated and recompiled without a problem. But finally I can’t upload, I always get this error:

Open On-Chip Debugger 0.10.0+dev-g18b4c35 (2021-07-16-01:02)
Licensed under GNU GPL v2
For bug reports, read
debug_level: 1

Warn : Transport “swd” was already selected
adapter speed: 5000 kHz

*** [upload] Error 5

Any ideas? I could connect with openocd on comandline level, maybe it’s a configuration issue?

Do a project tasks → Advanced → Verbose Upload. What’s the output? You used this config right?

Thanks for your time.
I tried all [env] configs, I made a verbose upload with the [pico_standard] config, with this result:

Executing task in folder Pico_Test: C:\Users\Christoph.platformio\penv\Scripts\platformio.exe run --verbose --target upload --environment pico_standard <

Processing pico_standard (platform: GitHub - maxgerhardt/platform-raspberrypi: Raspberry Pi: development platform for PlatformIO; board: pico; framework: arduino; upload_protocol: picoprobe; debug_tool: picoprobe; platform_packages: platformio/tool-openocd-raspberrypi@GitHub - maxgerhardt/pio-openocd-picoprobe: PlatformIO package for a precompiled OpenOCD version with Picoprobe support on Windows.; monitor_speed: 115200)
---------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: Redirecting...
PLATFORM: Raspberry Pi RP2040 (1.2.0+sha.673d327) (git+ > Raspberry Pi Pico
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (picoprobe) External (cmsis-dap, jlink, picoprobe, raspberrypi-swd)

  • framework-arduino-mbed 2.4.1
  • tool-mklittlefs 1.203.210628 (2.3)
  • tool-openocd-raspberrypi 2.1100.0+sha.63d4970 (git+
  • tool-rp2040tools 1.0.2
  • toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Framework incompatible library C:\Users\Christoph.platformio\packages\framework-arduino-mbed@2.4.1\libraries\LittleVGL
    Framework incompatible library C:\Users\Christoph.platformio\packages\framework-arduino-mbed@2.4.1\libraries\Portenta_SDCARD
    Found 30 compatible libraries
    More details about “Library Compatibility Mode”: Redirecting...
    Scanning dependencies…
    No dependencies
    Building in release mode
    ([“checkprogsize”], [“.pio\build\pico_standard\firmware.elf”])
    Flash size: 2.00MB
    Sketch size: 2.00MB
    Filesystem size: 0.00MB
    Maximium size: 2093056 Flash Length: 2093056 EEPROM Start: 270528512 Filesystem start 270528512 Filesystem end 270528512
    MethodWrapper([“checkprogsize”], [“.pio\build\pico_standard\firmware.elf”])
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [== ] 18.6% (used 50240 bytes from 270336 bytes)
    Flash: [ ] 3.5% (used 72664 bytes from 2093056 bytes)
    .pio\build\pico_standard\firmware.elf :

section size addr

.boot2 256 268435456

.text 52400 268435712

.rodata 8884 268488112

.ARM.exidx 8 268496996

.ram_vector_table 192 536870912

.data 11372 536871104

.uninitialized_ram.magic_location 12 536882476

.uninitialized_data 0 536882488

.scratch_x 0 537133056

.scratch_y 0 537137152

.bss 38868 536882488

.heap 210676 536921356

.ARM.attributes 40 0

.comment 132 0

.debug_frame 5284 0

.stab 60 0

.stabstr 118 0

Total 328302
([“upload”], [“.pio\build\pico_standard\firmware.bin”])
AVAILABLE: cmsis-dap, jlink, picoprobe, picotool, raspberrypi-swd
CURRENT: upload_protocol = picoprobe
openocd -d2 -s C:\Users\Christoph.platformio\packages\tool-openocd-raspberrypi/share/openocd/scripts -f interface/picoprobe.cfg -f target/rp2040.cfg -c “program {.pio\build\pico_standard\firmware.bin} 0x10000000 verify reset; shutdown;”
Open On-Chip Debugger 0.10.0+dev-g18b4c35 (2021-07-16-01:02)
Licensed under GNU GPL v2
For bug reports, read
debug_level: 2

Info : only one transport option; autoselect ‘swd’
Warn : Transport “swd” was already selected
adapter speed: 5000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
*** [upload] Error 5
===================================================== [FAILED] Took 3.37 seconds =====================================================

Environment Status Duration

pico_earlephilhower IGNORED
pico_earlephilhower_picoprobe_debugging IGNORED
pico_standard FAILED 00:00:03.370
================================================ 1 failed, 0 succeeded in 00:00:03.370 ================================================The terminal process “C:\Users\Christoph.platformio\penv\Scripts\platformio.exe ‘run’, ‘–verbose’, ‘–target’, ‘upload’, ‘–environment’, ‘pico_standard’” terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Any help/explanation welcome. I am an old-school electronic engineer, but I am new to PlatformIO, so I still have to get used to understand the underlying mecanisms and workflow (and of course the “hidden” options). Thanks a lot.

With Zadig, did you load WinUSB drivers on it or LibUSB? It must be the first one, because the latter will crash. (see Update OpenOCD build instructions for Windows · Issue #178 · raspberrypi/pico-feedback · GitHub).

It works. Thanks a lot, you made my day.

1 Like

Hi Max, I have also managed to get this debugging on the earlephilhower using Picoprobe using your advice in this thread. However, using this core, the debug only seems to work when using Arduino libraries, but when I use the pico sdk libraries such as pico/stdlib.h, it is not debugging correctly. Is this what you have found as well or there something that will make this work? Thanks, Tom

As expected since both the Arduino-mbed core and earlephilhower/arduino-pico use the Pico SDK in a precompiled library form (see libpico.a), so stepping inside Pico SDK functions in source code form won’t work.

1 Like

Thanks Max, that makes sense. Is there currently any method to fully debug the philhower core using the Pico SDK and Arduino libraries? If not, is this something that will likely be included once it becomes supported in PlatformIO?

PlatformIO follows what the Arduino core do regarding the compilation of their core. Since the Arduino cores use pre-compiled libraries, so does PlatformIO, otherwise we can’t necessarily garuantee the same result. So for framework = arduino this will won’t be included since that’s how the cores work.

The SDK sources are still there however, so with some tweaks (adding source paths) it might be possible to step into the code and have it display in the source code, but since it isn’t compiled from source and this optimized precompiled library is used, the debugging experience won’t be good (lots of optimized-away variables, etc.)

If someone wants to work with the Pico-SDK, it would make more sense to add debugging to a platform targeted directly at using the Pico SDK, such as GitHub - Wiz-IO/wizio-pico: Raspberry Pi Pico development platform for PlatformIO.