Skip to content

Instantly share code, notes, and snippets.

@atoktoto
Last active December 25, 2023 20:57
Show Gist options
  • Save atoktoto/34cbad0556c4088eecc9eaa4b9fc9f05 to your computer and use it in GitHub Desktop.
Save atoktoto/34cbad0556c4088eecc9eaa4b9fc9f05 to your computer and use it in GitHub Desktop.
Debugging RP2040 (Rasbperry Pi Pico SDK) using CLion on Windows

Debugging RP2040 (Rasbperry Pi Pico SDK)

Using: Windows, Clion, Picoprobe & OpenOCD

  1. Go through all the steps necessery to build from command line, as described in "Getting started with Raspberry Pi Pico".
  2. Add MinGW toolchain to CLion: obraz
  3. Add CMake profiles using the MinGW toolchain, specify the Pico SDK path as an environment variable: obraz

At this stage the project should build.

  1. Build OpenOCD with picoprobe support as described in "Getting started..."
  2. Download libusb binary from here
  3. Take the dll libusb-1.0.26-binaries\VS2015-x64\dll\libusb-1.0.dll and put it in the OpenOCD directory openocd\tcl\

You should be now able to debug from command line as described in "Getting started..." section 6.3.

  1. Add "Embedded GDB Server" run configuration in CLion: obraz

There are a couple tricky things here:

  • we are using the bundled version of GDB (it's multiarch so it's OK)
  • we are connecting to localhost:3333 (make sure that the port is not in use)
  • the GDB Server args are: -f interface/picoprobe.cfg -f target/rp2040.cfg
  • the Working directory is set to tcl in the OpenOCD directory - this way OpenOCD will find the cfg files and the libusb dll will load.
  • the reset command is set to monitor reset halt
  1. Create a .gdbinit in your windows home directory C:\Users\[your username] with the contents:
define target remote
target extended-remote $arg0
monitor reset halt
break main
end

This redefines the target remote GDB command as target extended-remote and makes GDB to break just before your main().

This is a workaround for: https://youtrack.jetbrains.com/issue/CPP-7322

Now you should be able to start the debugger from CLion and step through the code.

  1. (extra) Add rp2040.svd file to CLion debugger tab to get a nice overview off all registers. The file is located in pico-sdk\src\rp2040\hardware_regs\rp2040.svd. obraz

  2. (also extra) Add set(PICO_DEOPTIMIZED_DEBUG 1) to your CMakeLists.txt before initializing the Pico SDK to stop the compiler from inling method calls (and make it easier to debug).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment