Preparing PicoSDK projects for PIO debugging

This page describes the changes that need to be applied to the Raspberry Pi Pico SDK project in order to enable debugging the PIO hardware with VisualGDB.

Patch the PicoSDK to report the additional PIO file information.

VisualGDB can show the PIO files used by the targets in Solution Explorer, as long the SDK is patched to report them. To patch the SDK, open the <SDK path>\tools\CMakeLists.txt file, and locate the following line:

Add the following lines after that line:

If you reload the project now, the PIO files will appear directly under the target nodes in Solution Explorer, together with sources and headers:

Patch the _pio_add_program_at_offset() function

VisualGDB can automatically translate PIO instruction pointers to the locations in the PIO files. In order to enable this, the _pio_add_program_at_offset() function in pio.c file inside the SDK needs to be modified as shown below:

This will have minimal performance overhead (calling one empty function when loading PIO programs) normally,  but when you reference the Fast Semihosting and Profiler framework, VisualGDB will be able to track what code got loaded into the PIO program memory, and will automatically map it to the original .pio files:

Now that you have successfully patched the Pico SDK, you will be able to use the VisualGDB’s PIO debugger to debug the PIO programs.