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!
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!!)
Here are some 'pro-tips' to help you with your debugging once you get the above guide going.
- 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!
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)
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!