Debugging RTX-based projects with VisualGDB

This tutorial shows how to create a basic project using the Keil compiler and the RTX OS using VisualGDB. We will create a basic “Blinking LED” project for the STM32F4Discovery board and will show to to view the state of the threads using the RTX thread plugin. Before you begin, install VisualGDB 5.4 Preview 10 or later.

  1. Start Visual Studio and open the VisualGDB Embedded Project Wizard:01-prjname
  2. Proceed with the default settings on the first page:02-msbuild
  3. On the next page select your Keil toolchain and the device you want to target:02-deviceIf the toolchain does not appear, follow this tutorial to create a basic project first.
  4. Keil-based projects are always created empty, so press “Next” in the Sample Selection page:03-sample
  5. On the Debug Method page select the debug method you want to use with your board:04-debug
  6. Press “Finish” to create the project. VisualGDB will create an empty MSBuild-based project using the selected Keil compiler:05-empty
  7. If you are using the Custom edition of VisualGDB or higher, you can automatically add the RTX project template and all necessary components from the Keil packs using the Keil Components page of VisualGDB Project Properties. Select your board in the “Board Support” field, then check the following components:
    • Board Support -> LED
    • CMSIS -> RTOS -> Keil RTX5
    • CMSIS -> RTOS2 -> Source
    • Device->STN32Cuce HAL -> GPIO

    06-componentsOnce you select the components listed above, VisualGDB will automatically discover their dependencies and will suggest referencing them automatically.

  8. Press “OK”. VisualGDB will check the newly referenced packages for template files and will suggest copying them to the project. Select the templates shown below and click “OK”:07-templates
  9. VisualGDB will add the necessary files to your project, so you will be able to build it:08-project
  10. Replace the contents of the main.c file with this. It will create 2 parallel threads, each one controlling one on-board LED. Build the project and press F5 to start debugging:09-run
  11. Check that both on-board LEDs are blinking and set a breakpoint in one of the thread functions. Once the breakpoint triggers, open the Debug->Windows->Threads window:
  12. Visual Studio will display the currently running RTX threads in the Threads window. Switch to the other thread to see that it is waiting in the osDelay() function:11-thread2