{"id":117,"date":"2014-03-25T20:36:29","date_gmt":"2014-03-25T20:36:29","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=117"},"modified":"2019-01-24T10:36:27","modified_gmt":"2019-01-24T18:36:27","slug":"arm-st-link","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/st-link\/","title":{"rendered":"STM32 debugging with ST-Link, OpenOCD &amp; VisualGDB"},"content":{"rendered":"<p>This tutorial shows how to debug your embedded STM32 projects using ST-Link hardware debugger, OpenOCD and Visual Studio with VisualGDB.<\/p>\n<p>Before proceeding with the tutorial please ensure that <a href=\"\/download\">VisualGDB 4.0<\/a> or later is installed.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Start Visual Studio. Create a new project by selecting File-&gt;New-&gt;Project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-newprj-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4540\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-newprj-1.png\" alt=\"\" width=\"1069\" height=\"713\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-newprj-1.png 1069w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-newprj-1-300x200.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-newprj-1-768x512.png 768w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-newprj-1-1024x683.png 1024w\" sizes=\"(max-width: 1069px) 100vw, 1069px\" \/><\/a><\/li>\n<li>\u00a0Select VisualGDB -&gt; Embedded Project Wizard. Specify project directory and enter project name:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4541\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjname.png\" alt=\"\" width=\"841\" height=\"563\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjname.png 841w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjname-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjname-768x514.png 768w\" sizes=\"(max-width: 841px) 100vw, 841px\" \/><\/a><\/li>\n<li>Select &#8220;Create New Project&#8221; on the first wizard page:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-newbin.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4542\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-newbin.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-newbin.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-newbin-300x235.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-newbin-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>On the toolchain selection page select &#8220;arm-eabi&#8221;. If you don&#8217;t have the arm-eabi toolchain installed, VisualGDB will install it automatically. Then select your device from the list:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/06-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4547\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/06-device.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/06-device.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/06-device-300x235.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/06-device-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>On the next page confirm the &#8220;Blinking LED&#8221; sample by pressing &#8220;next&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-blink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4548\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-blink.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-blink.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-blink-300x235.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-blink-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Connect your ST-Link to the USB port and let VisualGDB detect it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/stlink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4561\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/stlink.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/stlink.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/stlink-300x235.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/stlink-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>VisualGDB will automatically download the latest OpenOCD package and will let you configure most common settings using convenient GUI:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4563\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/config.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/config.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/config-300x235.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/config-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Press &#8220;Test selected OpenOCD settings&#8221; in the VisualGDB project wizard to verify your settings:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4562\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/test.png\" alt=\"\" width=\"786\" height=\"593\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/test.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/test-300x226.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/test-768x579.png 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>If you are familiar with OpenOCD internals and would like to tweak the startup commands or the command line, use the Advanced Settings view to edit them directly:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/advanced.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4564\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/advanced.png\" alt=\"\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/advanced.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/advanced-300x235.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/advanced-768x601.png 768w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Press &#8220;finish&#8221; to close the wizard. VisualGDB will generate a Visual Studio project. Press Ctrl-Shift-B to build it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4552\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/build.png\" alt=\"\" width=\"1069\" height=\"713\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/build.png 1069w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/build-300x200.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/build-768x512.png 768w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/build-1024x683.png 1024w\" sizes=\"(max-width: 1069px) 100vw, 1069px\" \/><\/a><\/li>\n<li>Put a breakpoint on a line that turns on a LED and press F5 to start debugging. Once the breakpoint is hit, press F10 to step over a line:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/bkpt-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4565\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/bkpt-1.png\" alt=\"\" width=\"1069\" height=\"713\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/bkpt-1.png 1069w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/bkpt-1-300x200.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/bkpt-1-768x512.png 768w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/bkpt-1-1024x683.png 1024w\" sizes=\"(max-width: 1069px) 100vw, 1069px\" \/><\/a><\/li>\n<li>Note how the LED on the board turns on and off as you step over the corresponding lines:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/st-link\/13-board.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/st-link\/13-board.png\" alt=\"13-board\" width=\"700\" height=\"460\" \/><\/a><\/li>\n<li>When you are done debugging, you can modify various project properties by right-clicking in the project node in Solution Explorer and selecting &#8220;VisualGDB Project Properties&#8221;.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/debugsettings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4566\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/debugsettings.png\" alt=\"\" width=\"992\" height=\"660\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/debugsettings.png 992w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/debugsettings-300x200.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/debugsettings-768x511.png 768w\" sizes=\"(max-width: 992px) 100vw, 992px\" \/><\/a><\/li>\n<li>VisualGDB will automatically index your sources (and the STM32 package sources) and will let you navigate through them using CodeJumps. Simply click the CodeJumps labels near the function declarations to view references, call trees, functions &#8220;implementing&#8221; specific function pointers and so on:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-calls.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4557\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-calls.png\" alt=\"\" width=\"1069\" height=\"713\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-calls.png 1069w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-calls-300x200.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-calls-768x512.png 768w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/14-calls-1024x683.png 1024w\" sizes=\"(max-width: 1069px) 100vw, 1069px\" \/><\/a><\/li>\n<li>Use the View-&gt;Embedded Memory Explorer to get a detailed report about the structure of your embedded binary, including the locations of sections in memory, sizes of individual functions, their disassembly view and worst-case stack analysis:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/eme.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4558\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/eme.png\" alt=\"\" width=\"1069\" height=\"713\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/eme.png 1069w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/eme-300x200.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/eme-768x512.png 768w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/eme-1024x683.png 1024w\" sizes=\"(max-width: 1069px) 100vw, 1069px\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug your embedded STM32 projects using ST-Link hardware debugger, OpenOCD and Visual Studio with VisualGDB.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[90],"tags":[53,60,61],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/117"}],"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=117"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":4568,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/117\/revisions\/4568"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}