{"id":7185,"date":"2021-03-05T20:48:00","date_gmt":"2021-03-06T04:48:00","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7185"},"modified":"2022-08-09T18:11:54","modified_gmt":"2022-08-10T01:11:54","slug":"debugging-raspberry-pi-pico-via-swd","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/embedded\/raspberry\/pico\/swd\/","title":{"rendered":"Debugging Raspberry Pi Pico via SWD"},"content":{"rendered":"<p>This page explains how to prepare the Raspberry Pi Pico for debugging via SWD. Note that the on-board FLASH memory can be programmed via the bootloader and does not require SWD wiring. The steps shown on this page are only needed if you would like to set breakpoints in the code and step through it in a debugger.<\/p>\n<h2>General Setup<\/h2>\n<p>The Raspberry Pi Pico board has the SWD pins conveniently available on one side, however in order to keep the board compact, they are not following the standard JTAG20 pinout. In order to debug the board using a regular SWD debugger, please connect the pins as shown below:<\/p>\n<table style=\"border-collapse: collapse; width: 99.9999%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 33.3333%;\">Pin name on board<\/td>\n<td style=\"width: 33.3333%;\">JTAG\/SWD signal name<\/td>\n<td style=\"width: 33.3333%;\">Pin on JTAG20 cable<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">SWDIO<\/td>\n<td style=\"width: 33.3333%;\">TMS\/SWDIO<\/td>\n<td style=\"width: 33.3333%;\">7<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">GND<\/td>\n<td style=\"width: 33.3333%;\">GND<\/td>\n<td style=\"width: 33.3333%;\">2, 4, 6 or 8<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">SWCLK<\/td>\n<td style=\"width: 33.3333%;\">TCK\/SWCLK<\/td>\n<td style=\"width: 33.3333%;\">9<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">VDD (optional)<\/td>\n<td style=\"width: 33.3333%;\">+3.3V<\/td>\n<td style=\"width: 33.3333%;\">1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Connecting the VDD (+3.3V) to pin 1 of the JTAG2o connector will prevent the &#8220;No target power&#8221; error with some SWD adapters, but is generally optional.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/rpi_swd.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7186\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/rpi_swd.jpg\" alt=\"\" width=\"932\" height=\"334\" \/><\/a>The connection for the Raspberry Pi Pico W board is practically identical: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/picow.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7912\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/picow.jpg\" alt=\"\" width=\"1200\" height=\"404\" \/><\/a><\/p>\n<p>The final setup involving the Raspberry Pi Pico and a JTAG\/SWD adapter should look as shown below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/raspi2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7188\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/raspi2.jpg\" alt=\"\" width=\"1280\" height=\"297\" \/><\/a>We have tested the following SWD adapters with Raspberry Pi Pico using this setup:<\/p>\n<ul>\n<li>Segger J-Link<\/li>\n<li>Olimex ARM-USB-OCD-H (requires ARM-JTAG-SWD module)<\/li>\n<li>Raspberry Pi 4 (see below)<\/li>\n<\/ul>\n<p>If you are using a different SWD adapter based on the FT2232 chip (e.g. Flyswatter 2), it will likely work as well, as long as it supports SWD.<\/p>\n<p><strong>WARNING: The RP2040 chip used by Raspberry Pi Pico requires a <a href=\"https:\/\/github.com\/raspberrypi\/openocd\">special OpenOCD fork<\/a>. VisualGDB will automatically use it when debugging Raspberry Pi Pico. If you are running OpenOCD manually, you can download it <a href=\"https:\/\/gnutoolchains.com\/arm-eabi\/openocd\/\">here<\/a> (use openocd_rpi2040.exe instead of openocd.exe).<\/strong><\/p>\n<h2>Debugging with Regular Raspberry Pi<\/h2>\n<p>You can use the regular Raspberry Pi board to debug Raspberry Pi Pico (or any other device that supports the SWD transport). In order to do that, connect the following signals on the Raspberry Pi:<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 25%;\">Raspberry Pi Signal<\/td>\n<td style=\"width: 25%;\">Raspberry Pi Pin Number<\/td>\n<td style=\"width: 25%;\">JTAG\/SWD signal<\/td>\n<td style=\"width: 25%;\">JTAG20 Pin<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">GPIO24<\/td>\n<td style=\"width: 25%;\">18<\/td>\n<td style=\"width: 25%;\">TMS\/SWDIO<\/td>\n<td style=\"width: 25%;\">7<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">GPIO25<\/td>\n<td style=\"width: 25%;\">22<\/td>\n<td style=\"width: 25%;\">TCK\/SWCLK<\/td>\n<td style=\"width: 25%;\">9<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">GND<\/td>\n<td style=\"width: 25%;\">20<\/td>\n<td style=\"width: 25%;\">GND<\/td>\n<td style=\"width: 25%;\">2, 4, 6 or 8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The final setup using the modular JTAG20 connector is shown below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/rpi_big.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7190\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/03\/rpi_big.jpg\" alt=\"\" width=\"1280\" height=\"571\" \/><\/a>Once the signals have been connected, simply run OpenOCD on Raspberry Pi itself using the <strong>interface\/raspberrypi-swd.cfg<\/strong> script in order to debug your target. If you are using VisualGDB Linux Edition or higher, simply select &#8220;Debug using: OpenOCD (run remotely)&#8221; and VisualGDB will automatically build and launch the correct OpenOCD fork on your Raspberry Pi:<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>See <a href=\"https:\/\/visualgdb.com\/tutorials\/raspberry\/pico\/\">this tutorial<\/a> for detailed step-by-step instructions on building and debugging a Raspberry Pi project with Visual Studio and VisualGDB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page explains how to prepare the Raspberry Pi Pico for debugging via SWD. Note that the on-board FLASH memory<\/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\/7185"}],"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=7185"}],"version-history":[{"count":6,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7185\/revisions"}],"predecessor-version":[{"id":7913,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7185\/revisions\/7913"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}