{"id":7164,"date":"2021-03-05T18:54:01","date_gmt":"2021-03-06T02:54:01","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7164"},"modified":"2021-03-19T10:20:16","modified_gmt":"2021-03-19T17:20:16","slug":"developing-raspberry-pi-pico-projects-with-visual-studio","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/raspberry\/pico\/","title":{"rendered":"Developing Raspberry Pi Pico Projects with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to create, build and debug a basic project for the Raspberry Pi Pico device (RP2040) using Visual Studio. Before you begin, install VisualGDB 5.6 or later.<\/p>\n<ol>\n<li>Start Visual Studio and locate the VisualGDB Raspberry Pi Pico Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7165\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/01-newprj.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Enter the name and location for the newly created project, then press &#8220;Create&#8221; to open VisualGDB-specific part of the wizard: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/02-prjname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7166\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/02-prjname.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>The Raspberry Pi Pico Project wizard allows creating new projects from scratch, or importing existing projects into Visual Studio. In this tutorial we will simply clone the &#8220;blinky&#8221; example, so proceed with the default settings. If you are missing some of the tools required by the Raspberry Pico SDK, use the buttons at the bottom of the page to automatically install them: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/03-tools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7167\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/03-tools.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>The next page of the wizard allows selecting a toolchain and an SDK version. Unlike the regular Raspberry Pi board that runs Linux, Raspberry Pi Pico (RP2040) does not require any operating system and hence can use the same ARM toolchain that is used for other barebone devices (e.g. STM32). We recommend using our <a href=\"https:\/\/gnutoolchains.com\/arm-eabi\/\">ARM toolchain<\/a> that is based on the official <a href=\"https:\/\/developer.arm.com\/tools-and-software\/open-source-software\/developer-tools\/gnu-toolchain\/gnu-rm\">GNU toolchain from ARM.<\/a> If you have not installed the Pico SDK yet, simply click &#8220;Install Raspberry Pi Pico SDK&#8221; at the bottom of the SDK selector:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/04-getsdk.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7168\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/04-getsdk.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>VisualGDB can download a pre-packaged SDK from our server, or clone the specified git tag from the <a href=\"https:\/\/github.com\/raspberrypi\/pico-sdk\">official SDK repository<\/a>. We advise installing the pre-packaged version, as it has been explicitly tested with VisualGDB: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/05-release.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7169\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/05-release.png\" alt=\"\" width=\"503\" height=\"188\" \/><\/a><\/li>\n<li>Once the SDK has been downloaded and installed, make sure it is selected and click &#8220;Next&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/06-gotrelease.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7170\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/06-gotrelease.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Now we will select the project template to use for the new project. In this tutorial we choose the simplest &#8220;blink&#8221; template:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/07-blink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7171\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/07-blink.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>The last page of the wizard allows configuring the debug settings and typically involves soldering the SWD pins on the board. See <a href=\"https:\/\/visualgdb.com\/documentation\/embedded\/raspberry\/pico\/swd\/\">this page<\/a> for detailed wiring instructions and an overview of supported debug methods. If you are not planning to debug your board, simply choose the simulator or &#8220;custom&#8221; mode here (note that the gdb simulator won&#8217;t work for ARM devices such RP2040): <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/08-oocd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7172\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/08-oocd.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>If you do have a working SWD connection, use the &#8220;test&#8221; button to verify that everything is working: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/09-tested.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7173\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/09-tested.png\" alt=\"\" width=\"786\" height=\"593\" \/><\/a>If RP2040 does not appear in the OpenOCD device list, make sure you have the latest OpenOCD package installed via <strong>Tools-&gt;VisualGDB-&gt;Manage VisualGDB Packages<\/strong>.<\/li>\n<li>Click &#8220;Finish&#8221; to create the project. Once VisualGDB finishes creating it, you can build it by pressing Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/10-built.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7174\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/10-built.png\" alt=\"\" width=\"1190\" height=\"841\" \/><\/a><\/li>\n<li>The Raspberry Pi Pico SDK projects are based on the <a href=\"https:\/\/visualgdb.com\/documentation\/projects\/cmake\/\">Advanced CMake Project Subsystem<\/a>. They conveniently allow defining multiple targets, setting custom target properties and even <a href=\"https:\/\/visualgdb.com\/tutorials\/cmake\/debugger\/\">stepping through the CMake scripts<\/a>. Internally, the use the build scripts that come with the original Pico SDK, so you can always build your project outside Visual Studio as well. Once the project is built, check the Embedded Memory Explorer for a detailed memory utilization report: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/11-mem.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7175\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/11-mem.png\" alt=\"\" width=\"1190\" height=\"841\" \/><\/a><\/li>\n<li>Set a breakpoint on the first call to <strong>gpio_put()<\/strong> and press F5. VisualGDB will automatically program the FLASH memory and begin running the program. The breakpoint will soon get triggered:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/12-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7176\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/12-bkpt.png\" alt=\"\" width=\"1190\" height=\"841\" \/><\/a><\/li>\n<li>Press F10 to step over the <strong>gpio_put()<\/strong> call:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/13-stepped.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7177\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/13-stepped.png\" alt=\"\" width=\"1190\" height=\"841\" \/><\/a><\/li>\n<li>Observe how the on-board LED turns on:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/led.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7181\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/led.jpg\" alt=\"\" width=\"1035\" height=\"366\" \/><\/a><\/li>\n<li>VisualGDB automatically discovers and parses the relevant source and header files inside the Raspberry Pi Pico SDK, so you can use various IntelliSense functionality to navigate it. E.g. try selecting &#8220;Go to definition&#8221; on the <strong>sleep_ms()<\/strong> function and then exploring the call graph on the <strong>sleep_us()<\/strong> called by it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/14-func.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7178\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/14-func.png\" alt=\"\" width=\"1190\" height=\"841\" \/><\/a><\/li>\n<li>Note the &#8220;<strong>#if !PICO_TIME_DEFAULT_ALARM_POOL_DISABLED<\/strong>&#8221; line in <strong>sleep_us()<\/strong>. It changes the behavior of sleep() is based on the <strong>PICO_TIME_DEFAULT_ALARM_POOL_DISABLED<\/strong> configuration variable. The configuration variables supported by the Pico SDK are conveniently annotated inside the source files, so VisualGDB can automatically discover them and let you configure them via VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/15-config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7179\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/15-config.png\" alt=\"\" width=\"1053\" height=\"741\" \/><\/a><\/li>\n<li>Try setting the &#8220;Disable the default alarm pool&#8221; parameter and check how the opposite part of <strong>sleep_us()<\/strong> becomes active:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/16-pool.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7180\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/16-pool.png\" alt=\"\" width=\"1190\" height=\"841\" \/><\/a>The configuration parameters will be stored in the <strong>PicoSDKConfig.cmake<\/strong> file in the project directory. Make sure you check it into source control together with the rest of the project.<\/li>\n<li>You can use the Embedded Memory Explorer to quickly understand impact of changing various parameters. E.g. disabling the default alarm pool considerably reduces the FLASH memory footprint by eliminating multiple alarm-related functions: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/17-changes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7182\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/17-changes.png\" alt=\"\" width=\"1190\" height=\"841\" \/><\/a><\/li>\n<li>If you are using VisualGDB Linux Edition or higher, you can use a regular Raspberry Pi board as a JTAG debugger. Simply choose &#8220;OpenOCD (run remotely)&#8221; as the debug method and point VisualGDB to your Raspberry Pi hostname. VisualGDB will automatically build, install and launch the correct port of OpenOCD on your target:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/rpi.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7243\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/rpi.png\" alt=\"\" width=\"1035\" height=\"784\" \/><\/a>If you are using special scripts, you can modify the OpenOCD command line used by VisualGDB by expanding the &#8220;Advanced Settings&#8221; view at the bottom of the OpenOCD settings.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create, build and debug a basic project for the Raspberry Pi Pico device (RP2040) using<\/p>\n","protected":false},"author":1,"featured_media":7184,"comment_status":"closed","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[231],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7164"}],"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=7164"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7164\/revisions"}],"predecessor-version":[{"id":7244,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7164\/revisions\/7244"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media\/7184"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}