6

Disclaimer: This is my first time using OpenOCD and programming ARM microcontroller, so I really don’t know what I am doing.

I’m trying to program Raspberry Pi Pico (RP2040) board using ST-LINK/V2 (mini) from Waveshare and OpenOCD. This programmer officially doesn’t support OpenOCD, but since OpenOCD support ST_LINK/V2 and it has SWDIO and SWCLK pins I think it should be okay. When I’m trying to use latest OpenOCD from git I got:

$ openocd -f interface/stlink.cfg -f target/rp2040-core0.cfg -c "program ~/git/pico-examples/build/blink/blink.elf verify reset exit"
Open On-Chip Debugger 0.11.0+dev-00433-g97db87c22 (2021-10-31-14:55)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Error: Debug adapter doesn't support 'swd' transport
/usr/bin/../share/openocd/scripts/target/rp2040-core0.cfg:3: Error: 
in procedure 'script' 
at file "embedded:startup.tcl", line 26
at file "/usr/bin/../share/openocd/scripts/target/rp2040-core0.cfg", line 3

So apparently official OpenOCD doesn’t want to work with my programmer. There is a STMicroelectronics fork of OpenOCD made for ST-LINK, but it doesn’t support RP2040, but when I’m trying to pass rp2040-core0.cfg from official OpenOCD I got same error:

$ ../src/openocd -f interface/stlink.cfg -f /usr/share/openocd/scripts/target/rp2040-core0.cfg -c "program ~/git/pico-examples/build/blink/blink.elf verify reset exit"
Open On-Chip Debugger 0.11.0-rc2+dev-gff701ce (2021-10-31-15:03)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Error: Debug adapter doesn't support 'swd' transport
/usr/share/openocd/scripts/target/rp2040-core0.cfg:3: Error: 
in procedure 'script' 
at file "embedded:startup.tcl", line 26
at file "/usr/share/openocd/scripts/target/rp2040-core0.cfg", line 3

And at last, fork of OpenOCD from Raspberry Pi gave me best result:

$ ../src/openocd -f interface/stlink-dap.cfg -c "transport select dapdirect_swd" -f target/rp2040.cfg -c "program ~/git/pico-examples/build/blink/blink.elf verify reset exit"
Open On-Chip Debugger 0.10.0+dev-g71510a7 (2021-10-31-15:11)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
dapdirect_swd
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : STLINK V2J27S6 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.261252
Error: init mode failed (unable to connect to the target)
Error: No Valid JTAG Interface Configured.

I checked many times connection between boards and they are fine. I tried to plug in RP2040’s USB while holding BOOTSEL then program it and same result. What am I doing wrong?

DamienD
  • 3,093
  • 1
  • 14
  • 23
urhen
  • 411
  • 4
  • 8
  • Does your Pico module show up as a USB drive when you power it up with the button pushed? If it does, then you just copy your UF2 file to it to program it. No programmer required. – crj11 Oct 31 '21 at 15:18
  • Yes, also there is currently a "Hello world" programmed in it and it's still working. I know about programming via USB, but plugging USB while holding BOOTSEL every time is not very comfortable for me, at least compared to Arduino. – urhen Oct 31 '21 at 15:24
  • Are you aware that you are using a cloned product instead of real ST-Link/V2? Maybe that is the only reason it does not work? The programming software might work with a real product, do you have access to a genuine ST-Link? – Justme Oct 31 '21 at 16:41
  • Yes, I'm aware, but since firmware for ST-LINK was reverse engineered from the firmware update I thought it will be working like original programmer. – urhen Oct 31 '21 at 19:15
  • @urhen The firmware version, or clone of it, dates back to 2016. It's rather old. Are you sure that firmware version can work with modern tools from 2021? Tried updating the firmware? Why would you expect a cheap clone to work like the original product? – Justme Oct 31 '21 at 21:04
  • Google 'usb hub with power switches' if you want to avoid plugging and unplugging to reprogram. You can get a 4 port one for less than $10. – crj11 Nov 02 '21 at 00:59

2 Answers2

9

It's true that the original ST-LINK firmware does not support multi-drop SWD debug protocol. RP2040 has two CPU cores, and multi-drop SWD support seems to be required even when you only want to connect to one of them.

The open source BlackMagic Probe firmware supports ST-LINK V2 hardware and adds the RP2040 support. The full installation instructions are here, summarized below:

  1. Build blackmagic firmware with make PROBE_HOST=stlink ST_BOOTLOADER=1
  2. Upload firmware to ST-LINK board with stlink-tool src/blackmagic.bin
  3. The device should appear as two serial ports, you can connect to the first one with gdb using command target ext /dev/ttyACM0.
  4. Using mon s will list available CPUs on the SWD bus, and attach 1 will connect to the first one.
texruska
  • 3
  • 2
jpa
  • 6,804
  • 17
  • 32
2

You can't use a ST-LINK/V2 (or a clone) as SWD probe for a RP2040 in OpenOCD because it's what OpenOCD calls a high level interface with its own firmware running on a STM32F103 (clone). This firmware limits is written to only work with supported chips. The RP2040 isn't on the list, but you don't have to buy an expensive debug probe. Instead you can flash the picoprobe firmware on a second Raspberry Pico and use it with OpenOCD. The picoprobe also acts as USB to serial adapter (just RX/TX with no flow control). It supports higher SWD clock frequencies than the STLINK thanks to the RP2040 PIO blocks and I've found the firmware more reliable than the buggy STLINK 2.1 firmware with Virtual COM port (the older STLINK firmware shipped with most clones is pretty reliable as well).

Crest
  • 21
  • 3
  • buggy st link firmware? I've been using it every day for years, and it's much more comfortable than connecting 7 external cables to the pico ... raspberry pi pico is garbage – Ricardo Casimiro Dec 25 '21 at 16:39
  • 1
    Buggy firmware. I've had the STLINK adapters in discovery and nucleo boards crash or fail to reset a locked up chip and don't get me started on the virtual COM port. – Crest Dec 25 '21 at 20:52