{"id":6206,"date":"2020-06-22T09:08:03","date_gmt":"2020-06-22T16:08:03","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=6206"},"modified":"2020-06-22T09:08:03","modified_gmt":"2020-06-22T16:08:03","slug":"using-olimex-arm-jtag-swd-to-debug-devices-via-swd","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/olimex\/arm-jtag-swd\/","title":{"rendered":"Using Olimex ARM-JTAG-SWD to Debug Devices via SWD"},"content":{"rendered":"<p>This tutorial shows how to use the <a href=\"https:\/\/www.olimex.com\/Products\/ARM\/JTAG\/ARM-JTAG-SWD\/\">Olimex ARM-JTAG-SWD adapter<\/a> with VisualGDB and OpenOCD to debug the devices that do not support the JTAG transport.<\/p>\n<p>We will use the nRF9160-DK board that includes 2 ARM microcontrollers (nRF52840 and nRF9160) and includes an integrated J-Link probe that can be used to debug one chip at a time. In this tutorial we will show how to debug the second chip using an external Olimex ARM-USB-OCD probe with the ARM-JTAG-SWD adapter, while the on-board J-Link is used to debug the primary nRF9160 chip.<\/p>\n<ol>\n<li>Start Visual Studio and open VisualGDB Embedded Project Wizard (most regular devices) or NRFConnect Project Wizard (Nordic nRF5x devices):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-new.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6207\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-new.png\" alt=\"\" width=\"966\" height=\"624\" \/><\/a><\/li>\n<li>Pick a name and location for the project: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-name-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6208\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-name-3.png\" alt=\"\" width=\"966\" height=\"624\" \/><\/a><\/li>\n<li>Proceed with the default project type setting (create a new project): <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-new.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6209\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-new.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Select the toolchain and the target. In this tutorial we will use the <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/nrfconnect\/nrf9160\/\">nRFConnect SDK<\/a>, however the debug setup shown here will work for the regular Embedded projects as well:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/04-target-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6210\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/04-target-2.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>As of version 1.2.0, the none of the nRFConnect SDK samples are explicitly marked compatible with the nRF52 on the PCA10090 board (nRF91-DK), however many of the regular nRF52 samples might work. Check the &#8220;Show incompatible samples&#8221; checkbox and pick the <strong>peripheral_hids_mouse<\/strong> sample:\u00a0 <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/05-mouse.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6211\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/05-mouse.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a>If you are using the regular Embedded Project Wizard instead, simply proceed with the LEDBlink sample.<\/li>\n<li>Switch the on-board J-Link target selector to target the nRF91 chip and connect the Olimex ARM-USB-OCD-H debugger to the nRF52 debug port as shown below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/layout.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6221\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/layout.jpg\" alt=\"\" width=\"1280\" height=\"820\" \/><\/a><\/li>\n<li>Go to the Debug Settings page of the wizard and try testing the settings. If you try testing the default settings, you will see the following error:\n<pre class=\"\">target\/swj-dp.tcl:30: Error: newtap: nrf52.cpu missing IR length<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/06-nojtag.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6212\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/06-nojtag.png\" alt=\"\" width=\"786\" height=\"593\" \/><\/a><\/li>\n<li>This happens because the OpenOCD definitions for the nRF52 chip only work with the SWD transport. Select SWD explicitly in the Debug Settings and make sure VisualGDB picks up the <strong>transport\/olimex-arm-jtag-swd.cfg<\/strong> script: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/07-olimex.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6213\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/07-olimex.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Now you will be able to debug the chip successfully: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08-tested.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6215\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08-tested.png\" alt=\"\" width=\"786\" height=\"593\" \/><\/a><\/li>\n<li>Click &#8220;Finish&#8221; to complete creating the project. Then go to VisualGDB Project Properties and make sure the debug optimization level is set to &#8220;Optimize for debugging&#8221; and not &#8220;Disable completely&#8221;, as otherwise nRF52 will run out of stack space:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08a-optimize.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6214\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08a-optimize.png\" alt=\"\" width=\"1055\" height=\"726\" \/><\/a><\/li>\n<li>Press Ctrl-Shift-B to build the project: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/09-main-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6216\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/09-main-2.png\" alt=\"\" width=\"1180\" height=\"805\" \/><\/a><\/li>\n<li>You can now start another debug session on the nRF91 chip (e.g. by following <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/nrfconnect\/nrf9160\/\">this tutorial<\/a>). As the Olimex debug probe is completely separate from the on-board J-Link, our nRF52 debug session will not interfere with nRF91. If you are using the Custom edition, you can configure VisualGDB to connect to one of the COM ports provided by the on-board J-Link (it will also not interfere with the regular J-Link debug session): <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/10-com.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6217\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/10-com.png\" alt=\"\" width=\"1180\" height=\"805\" \/><\/a><\/li>\n<li>To avoid stopping the program at breakpoints, we advise adding a counter to the loop inside <strong>main()<\/strong> and observing its value via <strong>Debug-&gt;Windows-&gt;Live Watch<\/strong>: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/11-live.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6218\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/11-live.png\" alt=\"\" width=\"1180\" height=\"805\" \/><\/a><\/li>\n<li>Try scanning for nearby Bluetooth LE devices with a Bluetooth-capable phone or a laptop. The <strong>Nordic_HIDS_Mouse<\/strong> device will appear in the list:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/0.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6222\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/0.png\" alt=\"\" width=\"400\" height=\"359\" \/><\/a><\/li>\n<li>If you try pairing the mobile device with the example project running on the nRF52 chip, it would normally expect a confirmation by pressing one the on-board buttons, that are typically used by the nRF91 chip:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/12-confirm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6219\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/12-confirm.png\" alt=\"\" width=\"1180\" height=\"805\" \/><\/a><\/li>\n<li>You can modify the <strong>pairing_process()<\/strong> function in <strong>main.c<\/strong> to call <strong>num_comp_reply(true)<\/strong> directly instead of asking for the confirmation. Now you will be able to pair your device with the example program and debug it with the Olimex debugger:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/13-autoconfirm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6220\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/13-autoconfirm.png\" alt=\"\" width=\"1180\" height=\"805\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use the Olimex ARM-JTAG-SWD adapter with VisualGDB and OpenOCD to debug the devices that do<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[53,56,210,60],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6206"}],"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=6206"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6206\/revisions"}],"predecessor-version":[{"id":6223,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6206\/revisions\/6223"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=6206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=6206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=6206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}