{"id":7283,"date":"2021-06-18T15:28:05","date_gmt":"2021-06-18T22:28:05","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7283"},"modified":"2025-12-11T14:20:13","modified_gmt":"2025-12-11T22:20:13","slug":"preparing-picosdk-projects-for-pio-debugging","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/picosdk\/patching\/","title":{"rendered":"Preparing PicoSDK projects for PIO debugging"},"content":{"rendered":"<p>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.<\/p>\n<h3>Patch the PicoSDK to report the additional PIO file information.<\/h3>\n<p>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 <strong>&lt;SDK path&gt;\\tools\\CMakeLists.txt<\/strong> file, and locate the following line:<\/p>\n<pre class=\"\">add_custom_target(${HEADER_GEN_TARGET} DEPENDS ${HEADER})<\/pre>\n<p>Add the following lines after that line:<\/p>\n<pre class=\"\">set(${HEADER_GEN_TARGET}_INPUT_FILE \"${PIO}\" CACHE INTERNAL \"\")\r\nset(${HEADER_GEN_TARGET}_OUTPUT_FILE \"${HEADER_DIR}\/${PIO_NAME}.h\" CACHE INTERNAL \"\")\r\nset(${HEADER_GEN_TARGET}_CONTAINING_TARGET \"${TARGET}\" CACHE INTERNAL \"\")<\/pre>\n<p>If you reload the project now, the PIO files will appear directly under the target nodes in Solution Explorer, together with sources and headers:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/06\/01-piofiles.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7284\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/06\/01-piofiles.png\" alt=\"\" width=\"1229\" height=\"798\" \/><\/a><\/p>\n<h3>Patch the _pio_add_program_at_offset() function<\/h3>\n<p>VisualGDB can automatically translate PIO instruction pointers to the locations in the PIO files. In order to enable this, the function responsible for loading PIO programs in <strong>pio.c<\/strong> file inside the SDK needs to be modified as shown below:<\/p>\n<pre class=\"\">void __attribute__((weak)) SysprogsDebugger_PIOProgramLoaded(PIO pio, const pio_program_t *program, uint offset)\r\n{\r\n}\r\n\r\nstatic void _pio_add_program_at_offset(PIO pio, const pio_program_t *program, uint offset) {\r\n    SysprogsDebugger_PIOProgramLoaded(pio, program, offset);\r\n    \/* ... *\/\r\n}<\/pre>\n<p>The function name depends on the PicoSDK version:<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\">PicoSDK 1.x<\/td>\n<td style=\"width: 50%;\"><strong>_pio_add_program_at_offset()<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">PicoSDK 2.x<\/td>\n<td style=\"width: 50%;\"><strong>add_program_at_offset()<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This will have minimal performance overhead (calling one empty function when loading PIO programs) normally,\u00a0 but when you reference the <strong>Fast Semihosting and Profiler framework<\/strong>, VisualGDB will be able to track what code got loaded into the PIO program memory, and will automatically map it to the original <strong>.pio<\/strong> files:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/06\/02-program.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7285\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/06\/02-program.png\" alt=\"\" width=\"1229\" height=\"798\" \/><\/a><\/p>\n<p>Now that you have successfully patched the Pico SDK, you will be able to use the VisualGDB&#8217;s PIO debugger to debug the PIO programs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page describes the changes that need to be applied to the Raspberry Pi Pico SDK project in order to<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[197],"tags":[231],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7283"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=7283"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7283\/revisions"}],"predecessor-version":[{"id":9078,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7283\/revisions\/9078"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}