Developing Keil MDK-ARM Projects with VisualGDB

This tutorial shows how to use VisualGDB to create, build and debug an MSBuild-based project using the Keil MDK-ARM compiler.

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 GUI to create your projects and manage their settings.

  1. Open Visual Studio and begin creating a new Embedded VisualGDB project:01-prjname
  2. Select “Create a new project” -> “MSBuild”:02-msbuildVisualGDB can also create GNU Make-based projects using the Keil compiler, however the MSBuild-based projects provide better GUI integration and build faster.
  3. Select your Keil toolchain on the Device Selection page. Note that VisualGDB supports both the classic ARMCC compiler (V5) and the newer Clang-based compiler (V6):
    03-armclangIf the Keil compilers don’t appear in the toolchain list, double-check the Keil installation path in registry (HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Keil\Products\MDK\Path).
  4. Once the toolchain is selected, pick your
  5. device from the list. When using the Keil toolchains, VisualGDB will automatically load device lists from the Keil packs, so you will be able to target any device supported by the Keil environment even if it’s not directly supported by VisualGDB:04-device
  6. Projects created using the Keil toolchain always start empty, so simply press “Next” on the Sample Selection page:
    05-sample
  7. Finally select the debug method for your device and press “Finish” to create the project:06-debug
  8. VisualGDB will create an empty project with no source files that will target the selected device:
    empty
  9. If you are using the Custom edition of VisualGDB or higher, right-click on the project in Solution Explorer, click “VisualGDB Project Properties” and go to the “Keil Components” page. Ensure that the “Automatically manage RTE_Components” flag is set:07-packsFor lower editions of VisualGDB, use the regular Add->Existing Item menu to manually adds sources and headers to the project.
  10. Check the “Device->Startup” and “Device->STM32Cube HAL->GPIO” components. VisualGDB will automatically detect their dependencies and suggest adding them as well:08-getpack
  11. Click “OK” to proceed. VisualGDB will show a list of file templates offered by the selected components. Check the “main module for STM32Cube HAL” template and click “OK”: 09-template
  12. VisualGDB will automatically add files from the selected components (including a copy of the main.c file) to your project, allowing you to build it:10-build
  13. 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):11-props
  14. Open the Keil Components page of VisualGDB Project Properties again, pick your development board from the list and check the “LED” component:12-led
  15. Include the <Board_LED.h> file from your main file and add the following code to the end of main():

    Also add a basic SysTick_handler implementation:
  16. Press F5 to begin debugging. Once the on-board LED starts blinking, set a breakpoint in the main loop and wait for it to trigger:
    13-blink
  17. Note that VisualGDB will automatically load the memory layout and the hardware register definitions from the Keil packs, so you won’t need to specify them manually:
    14-regs