Clion Raspberry Pi Pico Pro-Tips while Debugging...

In this short guide we go over some attention to details required when step-debugging the raspberry pi-pico!

Clion Raspberry Pi Pico Pro-Tips while Debugging...
Photo by Guillaume Coupy / Unsplash

Music of the Day: Music Lab Dark Music for Work

  • I have not seen a guide on the internet that properly shows step-debugging for Clion for the Raspberry Pi-Pico except here at hotconfig.com (especially with a $25 CMSIS-DAP Probe!!)
CLion Support for Step-Debugging w/ Raspberry Pi-Pico
In this guide we get stepper-debugging to work for the Raspberry Pi Pico with a $25 CMSIS probe!

Here are some 'pro-tips' to help you with your debugging once you get the above guide going.

  1. Add CMakeLists.txt compiler option to reduce optimizations:

It was found that the code was heavily optimized to the point it was difficult to debug.  By adding:

add_compile_options("-O0")  // Or -Og

Some other possibilities (wrap your function in #pragmas)

#pragma optimize( "", off )
.
.  << your function in here >>
.
#pragma optimize( "", on ) 

Also one can use -Og (Optimized for Debugging)

NOTE! -0g did actually still give me issues optimizing away some variables that were required for full debugging...

All your options for optimization thanks to the host for putting this up and being descript!

Optimize Options (Using the GNU Compiler Collection (GCC))
Optimize Options (Using the GNU Compiler Collection (GCC))

A working example CMakeLists.txt

2. Watch your Breakpoint Count.

  • If you have more than 4 it will break.
  • You will get the following mystic error on the CMSIS-DAP yet it will still compile:

This can oft be forgotten in your debug trails typically programmers will leave behind a trail of break points as they run the debug 'gauntlet'

3. Openocd config can run fast.  As in:

source [find interface/cmsis-dap.cfg]
transport select swd
adapter speed 5000
source [find target/rp2040.cfg]

4. Do not forget if you modify your CMakeLists.txt it will show an update button you need to press:

5. Here is example screenshots of configurations for you reference of what worked in this example:

  • Full debugging example:
  • Build / Execution  Enviroment Settings:
  • CMake Settings
  • Run / Debug Configuration.
  • Note a local file named openocd.cfg was created instead of selecting one of the standard boards.

Inside the openocd.cfg one can put:

source [find interface/cmsis-dap.cfg]
transport select swd
adapter speed 5000
source [find target/rp2040.cfg]

6. It should be noted that in this configuration fairly large .elf files will be pushed to your Raspberry Pi - Pico (in this case even a 'small' appplication of only 300 lines was producing a 400kb .elf file as in:

It should be noted that with 2MB of space the file still fit comfortably.

  • Once you turn off all debugging symbols your file will get dramatically smaller.
  • One can expand the filespace with RTOS and littleFS (an excellent article)
Add extra Storage to the Raspberry Pi Pico with W25Q128 and LittleFS
The Raspberry Pi Pico comes with 2 MByte FLASH. If more is needed for example to store data or for a data logger, this article shows how it can be extended with a 16 MByte serial flash using the Li…

7. Be Patient.

  • Really patient.
  • It is often the intended goals are simply too giant of leaps.  Start with small stuff and slowly work your way up, adding a function or two here and there until you get to your systems.

8. Good luck!

Linux Rocks Every Day