{"id":127,"date":"2017-08-06T20:44:47","date_gmt":"2017-08-07T03:44:47","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=127"},"modified":"2017-08-07T12:44:46","modified_gmt":"2017-08-07T19:44:46","slug":"arm-stm32-f4_discovery","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/stm32\/f4_discovery\/","title":{"rendered":"STM32F4-Discovery tutorial with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to create a simple project for the STM32F4-Discovery board with Visual Studio.<\/p>\n<p>You will need the following hardware and software to follow this tutorial:<\/p>\n<ul>\n<li>Microsoft Visual Studio<\/li>\n<li><a href=\"\/download\">VisualGDB<\/a><\/li>\n<li><a href=\"http:\/\/www.st.com\/web\/catalog\/tools\/FM116\/SC959\/SS1532\/PF252419\"> STM32F4-Discovery<\/a> board<\/li>\n<\/ul>\n<p>We will create a simple &#8216;blinking LED&#8217; project, build it and step through it in debugger.<\/p>\n<ol>\n<li>Start Visual Studio. Select File-&gt;New-&gt;Project. <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3008\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/01-newprj.png\" alt=\"01-newprj\" width=\"941\" height=\"636\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/01-newprj.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/01-newprj-300x203.png 300w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>\u00a0Select VisualGDB -&gt; Embedded Project Wizard. Pick a directory and a project name:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/02-blink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3009\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/02-blink.png\" alt=\"02-blink\" width=\"786\" height=\"502\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/02-blink.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/02-blink-300x192.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>As we are creating a firmware file without any static libraries, continue with the &#8220;embedded binary&#8221; option. We recommend choosing &#8220;MSBuild&#8221; as the build subsystem: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/03-msbuild.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3010\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/03-msbuild.png\" alt=\"03-msbuild\" width=\"822\" height=\"641\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/03-msbuild.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/03-msbuild-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>As we are building firmware for the STM32F4-Discovery board that contains ARM-based STM32F407VG microcontroller, select &#8220;ARM&#8221; on the toolchain selection page. If the ARM toolchain is not installed yet, select &#8220;(download toolchain for arm-eabi)&#8221; instead and VisualGDB will install it automatically:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/04-getarm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3011\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/04-getarm.png\" alt=\"04-getarm\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/04-getarm.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/04-getarm-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Once the toolchain is selected, you will see the list of supported devices. Select <strong>STM32F407VG<\/strong> from the list:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/05-dev.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3012\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/05-dev.png\" alt=\"05-dev\" width=\"822\" height=\"641\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/05-dev.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/05-dev-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>The STM32F4-Discovery board contains 4 LEDs connected to PD12-PD15 pins (see <a href=\"http:\/\/www.st.com\/st-web-ui\/static\/active\/en\/resource\/technical\/layouts_and_diagrams\/schematic_pack\/stm32f4discovery_sch.zip\"> board schematics <\/a>for more details):<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/stm32\/f4_discovery\/leds.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/stm32\/f4_discovery\/leds.png\" alt=\"leds\" width=\"460\" height=\"368\" \/><\/a>To make a project that will blink the green LED connected to PD12 select &#8220;GPIOD&#8221; and &#8220;12&#8221; as the port group and number:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/06-sample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3013\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/06-sample.png\" alt=\"06-sample\" width=\"822\" height=\"641\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/06-sample.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/06-sample-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>The STM32F4-Discovery board includes an on-board ST-Link programmer. Simply plug it into the USB port and VisualGDB will automatically detect it. Select it from the list and click &#8220;Test&#8221; to automatically install the needed drivers and verify that the debug connection works:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/07-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3014\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/07-device.png\" alt=\"07-device\" width=\"822\" height=\"641\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/07-device.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/07-device-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>VisualGDB will try running OpenOCD and will connect to it to verify that the debugging is possible:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/08-test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3015\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/08-test.png\" alt=\"08-test\" width=\"909\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/08-test.png 909w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/08-test-300x212.png 300w\" sizes=\"(max-width: 909px) 100vw, 909px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; in the wizard to complete it. Once the project is created, press Ctrl-Shift-B to build it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/09-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3016\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/09-build.png\" alt=\"09-build\" width=\"1117\" height=\"748\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/09-build.png 1117w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/09-build-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/09-build-1024x686.png 1024w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/a><\/li>\n<li>Press F5 to start debugging. Note how the LED turns on and off. Now put a breakpoint on the first <strong> GPIO_WriteBit()<\/strong> line. The breakpoint will be triggered immediately and the LED will be off:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/stm32\/f4_discovery\/led_off.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/stm32\/f4_discovery\/led_off.png\" alt=\"led_off\" width=\"700\" height=\"466\" \/><\/a><\/li>\n<li>Open the Registers window by pressing Ctrl-Alt-G or selecting Debug-&gt;Windows-&gt;Registers. Right-click inside it and ensure that &#8216;All Registers&#8217; is enabled:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/10-pc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3017\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/10-pc.png\" alt=\"10-pc\" width=\"1117\" height=\"748\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/10-pc.png 1117w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/10-pc-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/10-pc-1024x686.png 1024w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/a><\/li>\n<li>Note the value of the PC register. A value in the 0x80xxxxxx range indicates that the program is running from FLASH memory. We will change it to SRAM later. Press F10 to step over one line of code. Notice how the LED turns on:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/stm32\/f4_discovery\/led_on.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/stm32\/f4_discovery\/led_on.png\" alt=\"led_on\" width=\"700\" height=\"466\" \/><\/a><\/li>\n<li>Exit debugging by pressing Shift-F5. Right-click on the project node in Solution Explorer and select &#8220;VisualGDB Project Properties&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/11-projprops.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3018\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/11-projprops.png\" alt=\"11-projprops\" width=\"1117\" height=\"748\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/11-projprops.png 1117w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/11-projprops-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/11-projprops-1024x686.png 1024w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/a><\/li>\n<li>Click &#8220;Change settings&#8221; and select SRAM instead of FLASH:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/12-sram.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3019\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/12-sram.png\" alt=\"12-sram\" width=\"903\" height=\"726\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/12-sram.png 903w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/12-sram-300x241.png 300w\" sizes=\"(max-width: 903px) 100vw, 903px\" \/><\/a><\/li>\n<li>The previous binary build for FLASH mode won&#8217;t run from SRAM. Rebuild the project to fix this:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/13-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3020\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/13-build.png\" alt=\"13-build\" width=\"1117\" height=\"748\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/13-build.png 1117w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/13-build-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/13-build-1024x686.png 1024w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/a><\/li>\n<li>Start debugging and wait until the breakpoint is hit. Note that the pc register now contains a value in the 0x20xxxxxx range that indicates running from SRAM:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/14-pc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3021\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/14-pc.png\" alt=\"14-pc\" width=\"1117\" height=\"748\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/14-pc.png 1117w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/14-pc-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/14-pc-1024x686.png 1024w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/a>Making your program run from SRAM does not consume FLASH rewrite cycles when downloading the program or setting breakpoints. However, it has the disadvantage over FLASH mode: your entire program including all code and constants should fit in the SRAM, so it may not work for large programs.<\/li>\n<li>You can use the View-&gt;Embedded Memory Explorer to see which exact functions are responsible for the memory usage:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/15-memexp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3022\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/15-memexp.png\" alt=\"15-memexp\" width=\"1117\" height=\"748\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/15-memexp.png 1117w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/15-memexp-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/15-memexp-1024x686.png 1024w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create a simple project for the STM32F4-Discovery board with Visual Studio. You will need the<\/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,59,61],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/127"}],"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=127"}],"version-history":[{"count":3,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":3023,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/127\/revisions\/3023"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}