{"id":3780,"date":"2018-03-18T17:55:54","date_gmt":"2018-03-19T00:55:54","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=3780"},"modified":"2018-03-18T17:55:54","modified_gmt":"2018-03-19T00:55:54","slug":"debugging-embedded-projects-with-pyocd","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/pyocd\/","title":{"rendered":"Debugging Embedded projects with PyOCD"},"content":{"rendered":"<p>This tutorial shows how to debug embedded projects\u00a0using the PyOCD tool and VisualGDB.\u00a0PyOCD is significantly less functional than <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/openocd\/\">OpenOCD<\/a>, however it is better integrated with mbed-specific boards, so we recommend using it as a fallback if OpenOCD doesn&#8217;t work with your board. Before you begin, install VisualGDB 5.3 or later.<\/p>\n<ol>\n<li>Download and install Python 2.7 for Windows. Then open a command-line Python prompt and\u00a0install PyOCD by running &#8220;pip install pyocd&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/01-get.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3791\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/01-get.png\" alt=\"01-get\" width=\"979\" height=\"514\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/01-get.png 979w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/01-get-300x158.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/01-get-390x205.png 390w\" sizes=\"(max-width: 979px) 100vw, 979px\" \/><\/a><\/li>\n<li>You can quickly check that PyOCD works by connecting your board\u00a0to the USB port and running &#8220;pyocd-gdbserver -t &lt;target name&gt;&#8221;:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/02-pyocd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3790\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/02-pyocd.png\" alt=\"02-pyocd\" width=\"979\" height=\"514\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/02-pyocd.png 979w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/02-pyocd-300x158.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/02-pyocd-390x205.png 390w\" sizes=\"(max-width: 979px) 100vw, 979px\" \/><\/a><\/li>\n<li>Now we will create a project with VisualGDB. Start Visual Studio and select the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/03-prj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3789\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/03-prj.png\" alt=\"03-prj\" width=\"941\" height=\"653\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/03-prj.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/03-prj-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/03-prj-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/03-prj-130x90.png 130w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>Select &#8220;Create a new project with MSBuild -&gt; Embedded Binary&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/04-msb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3788\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/04-msb.png\" alt=\"04-msb\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/04-msb.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/04-msb-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>As PyOCD is typically\u00a0used with mbed-based projects, we will demonstrate its use for the <a href=\"https:\/\/os.mbed.com\/users\/wim\/notebook\/lpc812-lpcxpresso-board\/\">LPC812 mbed\/Xpresso board,<\/a>\u00a0however any other board supported by PyOCD will work as well.\u00a0 Select &#8220;use ARM mbed&#8221; and pick your board in the list:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/05-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3787\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/05-device.png\" alt=\"05-device\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/05-device.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/05-device-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>On the next page proceed with the default &#8220;LEDBlink&#8221; example:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/06-sample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3786\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/06-sample.png\" alt=\"06-sample\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/06-sample.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/06-sample-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>On the last page of the wizard switch\u00a0to &#8220;Debug Methods&#8221; instead of &#8220;USB Devices&#8221; and locate &#8220;PyOCD there&#8221;. If it is not shown, click the download button and install the PyOCD package:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/07-methods.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3785\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/07-methods.png\" alt=\"07-methods\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/07-methods.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/07-methods-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Once\u00a0PyOCD is selected, specify the\u00a0full path to the pyocd-gdbserver.exe executable (normally located in the &lt;Python&gt;\\scripts directory) and choose your target:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/08-target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3784\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/08-target.png\" alt=\"08-target\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/08-target.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/08-target-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a>Note that as PyOCD support\u00a0is more basic compared to OpenOCD, so it won&#8217;t automatically\u00a0recognize\/fix driver\u00a0issues and won&#8217;t support live variables, profiling and other features that require background memory reads.<\/li>\n<li>Press &#8220;Finish&#8221; to create the project. Build it with\u00a0Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/09-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3783\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/09-build.png\" alt=\"09-build\" width=\"1055\" height=\"733\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/09-build.png 1055w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/09-build-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/09-build-1024x711.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/09-build-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/09-build-130x90.png 130w\" sizes=\"(max-width: 1055px) 100vw, 1055px\" \/><\/a><\/li>\n<li>Now you can set a breakpoint in main() and press F5 to start debugging. Your breakpoint will hit as soon as the code reaches that point:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/10-step.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3782\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/10-step.png\" alt=\"10-step\" width=\"1055\" height=\"733\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/10-step.png 1055w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/10-step-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/10-step-1024x711.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/10-step-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/10-step-130x90.png 130w\" sizes=\"(max-width: 1055px) 100vw, 1055px\" \/><\/a><\/li>\n<li>The PyOCD output will be displayed in the &#8220;VisualGDB\u00a0Program Output&#8221; pane, so you can use it to diagnose PyOCD issues.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/11-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3781\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/11-output.png\" alt=\"11-output\" width=\"1055\" height=\"733\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/11-output.png 1055w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/11-output-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/11-output-1024x711.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/11-output-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/03\/11-output-130x90.png 130w\" sizes=\"(max-width: 1055px) 100vw, 1055px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug embedded projects\u00a0using the PyOCD tool and VisualGDB.\u00a0PyOCD is significantly less functional than OpenOCD, however<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[53,115,159],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3780"}],"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=3780"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3780\/revisions"}],"predecessor-version":[{"id":3792,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3780\/revisions\/3792"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=3780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=3780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=3780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}