{"id":108,"date":"2018-11-18T09:48:47","date_gmt":"2018-11-18T17:48:47","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=108"},"modified":"2023-09-20T21:52:58","modified_gmt":"2023-09-21T04:52:58","slug":"arm-keil","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/keil\/","title":{"rendered":"Developing Keil MDK-ARM Projects with VisualGDB"},"content":{"rendered":"<p>This tutorial shows how to use VisualGDB to create, build and debug an MSBuild-based project using the Keil MDK-ARM compiler.<\/p>\n<p>Starting from VisualGDB 5.4 Preview 10, the Keil compiler is fully supported on par with the GCC compiler, so you can use the regular VisualGDB\u00a0GUI to create your projects and manage their settings.<\/p>\n<ol>\n<li>Open Visual Studio and begin creating a new Embedded VisualGDB project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/01-prjname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4368\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/01-prjname.png\" alt=\"01-prjname\" width=\"941\" height=\"653\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/01-prjname.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/01-prjname-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/01-prjname-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/01-prjname-130x90.png 130w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>Select &#8220;Create a new project&#8221; -&gt; &#8220;MSBuild&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/02-msbuild.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4369\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/02-msbuild.png\" alt=\"02-msbuild\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/02-msbuild.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/02-msbuild-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a>VisualGDB\u00a0can also create\u00a0GNU Make-based projects using the Keil compiler, however the MSBuild-based projects\u00a0provide better GUI integration and build faster.<\/li>\n<li>Select your Keil toolchain on the <strong>Device Selection<\/strong> page. Note that VisualGDB supports both the classic ARMCC compiler (V5) and the newer Clang-based compiler (V6):<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/03-armclang1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4382\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/03-armclang1.png\" alt=\"03-armclang\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/03-armclang1.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/03-armclang1-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a>If the Keil compilers don&#8217;t appear in the toolchain list, see <a href=\"https:\/\/visualgdb.com\/documentation\/toolchains\/keil\/\">this page<\/a> for troubleshooting instructions.<\/li>\n<li>Once the toolchain is selected, pick your device from the list. When using the Keil toolchains, VisualGDB will automatically load device lists from the Keil packs, so you\u00a0will be able to target any device supported by the Keil\u00a0environment even if it&#8217;s not directly supported by VisualGDB:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/04-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4371\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/04-device.png\" alt=\"04-device\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/04-device.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/04-device-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a>If no devices appear in the list when you select the Keil compiler, you might be missing the Keil device packs, or have them installed in an unexpected location. If you enable the <strong>View-&gt;Other Windows-&gt;VisualGDB Diagnostics Console<\/strong> prior to opening the wizard, VisualGDB will print a verbose log from looking up the Keil packs there. If your pack directory is not listed, you can specify it via <span id=\"FullSettingPath\"><strong>Tools-&gt;Options-&gt;VisualGDB-&gt;Embedded-&gt;Keil-&gt;Extra Pack Directories<\/strong>.<\/span><\/li>\n<li>Projects\u00a0created using the Keil toolchain always start empty, so simply press &#8220;Next&#8221; on the Sample Selection page:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/05-sample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4372\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/05-sample.png\" alt=\"05-sample\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/05-sample.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/05-sample-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Finally select\u00a0the debug method for your device and press &#8220;Finish&#8221; to create the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/06-debug1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4373\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/06-debug1.png\" alt=\"06-debug\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/06-debug1.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/06-debug1-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>VisualGDB will create an empty project with no source files that will target the selected device:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/empty.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4383\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/empty.png\" alt=\"empty\" width=\"1353\" height=\"863\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/empty.png 1353w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/empty-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/empty-1024x653.png 1024w\" sizes=\"(max-width: 1353px) 100vw, 1353px\" \/><\/a><\/li>\n<li>If you are using the Custom edition of VisualGDB or higher, right-click on the project in Solution Explorer,\u00a0click &#8220;VisualGDB Project Properties&#8221; and go to the &#8220;Keil Components&#8221; page.\u00a0Ensure that the &#8220;Automatically\u00a0manage RTE_Components&#8221; flag is set:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/07-packs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4374\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/07-packs.png\" alt=\"07-packs\" width=\"1114\" height=\"722\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/07-packs.png 1114w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/07-packs-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/07-packs-1024x664.png 1024w\" sizes=\"(max-width: 1114px) 100vw, 1114px\" \/><\/a>For lower editions of VisualGDB, use the regular <strong>Add-&gt;Existing Item<\/strong> menu to manually adds sources and headers to the project.<\/li>\n<li>Check the &#8220;Device-&gt;Startup&#8221; and &#8220;Device-&gt;STM32Cube HAL-&gt;GPIO&#8221; components. VisualGDB will automatically detect their dependencies and suggest adding them as well:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/08-getpack.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4375\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/08-getpack.png\" alt=\"08-getpack\" width=\"1353\" height=\"863\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/08-getpack.png 1353w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/08-getpack-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/08-getpack-1024x653.png 1024w\" sizes=\"(max-width: 1353px) 100vw, 1353px\" \/><\/a><\/li>\n<li>Click &#8220;OK&#8221; to proceed. VisualGDB will\u00a0show a list of file templates\u00a0offered by the selected components. Check the &#8220;main module for STM32Cube HAL&#8221; template and click &#8220;OK&#8221;: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/09-template.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4376\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/09-template.png\" alt=\"09-template\" width=\"586\" height=\"243\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/09-template.png 586w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/09-template-300x124.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/a><\/li>\n<li>VisualGDB will\u00a0automatically\u00a0add files from the selected components (including a copy of the main.c file) to your project, allowing you to build it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/10-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4377\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/10-build.png\" alt=\"10-build\" width=\"1353\" height=\"863\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/10-build.png 1353w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/10-build-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/10-build-1024x653.png 1024w\" sizes=\"(max-width: 1353px) 100vw, 1353px\" \/><\/a><\/li>\n<li>Open the regular VS Project Properties. Note that the properties reflect the Keil-specific flags (e.g. allowing you to use scatter files instead of linker scripts):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/11-props.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4378\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/11-props.png\" alt=\"11-props\" width=\"838\" height=\"597\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/11-props.png 838w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/11-props-300x214.png 300w\" sizes=\"(max-width: 838px) 100vw, 838px\" \/><\/a><\/li>\n<li>Open the Keil Components page of VisualGDB Project Properties again, pick your development board from the list and check the &#8220;LED&#8221;\u00a0component:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/12-led.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4379\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/12-led.png\" alt=\"12-led\" width=\"1353\" height=\"863\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/12-led.png 1353w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/12-led-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/12-led-1024x653.png 1024w\" sizes=\"(max-width: 1353px) 100vw, 1353px\" \/><\/a><\/li>\n<li>Include the\u00a0<strong>&lt;Board_LED.h&gt;<\/strong> file from your main file and add the following code to the end of main():\n<pre class=\"\">LED_Initialize();\r\nfor (;;)\r\n{\r\n    LED_On(0);\r\n    HAL_Delay(100);\r\n    LED_Off(0);\r\n    HAL_Delay(100);\r\n}<\/pre>\n<p>Also add a basic SysTick_handler implementation:<\/p>\n<pre class=\"\">void SysTick_Handler(void)\r\n{\r\n    HAL_IncTick();\r\n}<\/pre>\n<\/li>\n<li>Press F5 to\u00a0begin debugging. Once the on-board LED starts blinking, set a breakpoint in the main loop and wait for it to trigger:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/13-blink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4380\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/13-blink.png\" alt=\"13-blink\" width=\"1353\" height=\"863\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/13-blink.png 1353w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/13-blink-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/13-blink-1024x653.png 1024w\" sizes=\"(max-width: 1353px) 100vw, 1353px\" \/><\/a><strong>Warning:<\/strong> if the breakpoint never hits and the target appears stuck in the initialization code, try settings the <strong>VisualGDB Project Properties -&gt; Debug Settings -&gt; Reset Device -&gt; After Programming<\/strong> checkbox. It will ensure that the device is in the correct state after the FLASH memory programming is completed.<\/li>\n<li>Note that VisualGDB will automatically load the memory layout and the hardware register definitions from the Keil packs, so you\u00a0won&#8217;t need to specify them manually:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/14-regs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4381\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/14-regs.png\" alt=\"14-regs\" width=\"1353\" height=\"863\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/14-regs.png 1353w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/14-regs-300x191.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/05\/14-regs-1024x653.png 1024w\" sizes=\"(max-width: 1353px) 100vw, 1353px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use VisualGDB to create, build and debug an MSBuild-based project using the Keil MDK-ARM compiler.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[53,147],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/108"}],"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=108"}],"version-history":[{"count":7,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":8418,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/108\/revisions\/8418"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}