Using STM32CubeMX Startup Code Generator with VisualGDB

This tutorial shows how to use the STM32CubeMX startup code generator with VisualGDB version 5.3 or later. We will use the STM32CubeMX tool to generate a basic project and then import it into VisualGDB to build and debug it.

Before you begin, ensure you are using VisualGDB 5.3 Preview 6 or later as it supports importing STM32CubeMX projects automatically.

  1. Start the STM32CubeMX tool and click on “New Project”:01-cubeprj
  2. Select your device in the device list and click “Start Project”. In this tutorial we will use the STM32F4Discovery board with the STM32F407VG device:02-device
  3. STM32CubeMX will create a new basic project template. Before we can import it into VisualGDB, we need to generate the actual project. Click the “Generate source code” button:03-generate
  4. In the project settings select enter the location where you want to save the project and select “Other Toolchains (GPDSC)” as the toolchain/IDE:04-gensettings
  5. Start Visual Studio and open VisualGDB Embedded Project Wizard:05-newvsprj
  6. On the first page of the wizard select Automatically import a project in a different format -> Import an existing STM32CubeMX Project and enter the location of the gpdsc file generated by STM32CubeMX:06-importcubeWe recommend checking the “Move Visual Studio project to the imported project directory” checkbox to create your VS project into the directory containing the rest of the files generated by STM32CubeMX:
  7. Click “Next”. VisualGDB will automatically pick up the device type from the generated project, so simply click “Next” again to confirm it:07-device
  8. Ensure your board is connected to your computer. VisualGDB will automatically locate the on-board ST-Link debug interface and will install the necessary drivers if they are missing. Click “Finish” to create the project:08-debug
  9. Press F10 to build the project and step into it. Ensure that you can debug it:09-debugging
  10. Now we will modify the project settings in the STM32CubeMX tool. Enable the external clock, specify the input frequency to match the oscillator on your board and ensure all the generated clocks have correct values (STM32CubeMX will highlight the incorrect values if it finds any):10-clock
  11. We will also show how to quickly enable FreeRTOS. Click the “Enabled” checkbox under MiddleWares -> FreeRTOS:11-freertos
  12. Click “Generate Code” to generate the project again:12-regen
  13. Close the Visual Studio solution and re-open it. VisualGDB will detect that the gpdsc file has changed and will suggest updating the project:13-updatevsClick “Yes”. VisualGDB will automatically detect the changes between the old and the new configuration and will apply them. Any files or settings that were previously a part of the STM32CubeMX project, but are no longer referenced, will be removed. Any files that were previously not referenced and were added now will be added. This will ensure that any changes made by you to the Visual Studio project (e.g. extra source files or include directories) will be preserved.
  14. If you try building the project now, you will get several build errors related to FreeRTOS. This happens because FreeRTOS expects the hardware floating point support, while VisualGDB uses software FP by default. Open VisualGDB Project Properties to change it:14-hardwarefp
  15. Now the project should build and you should be able to debug it:15-thread
  16. VisualGDB automatically detects the build settings (e.g. include directories) from the STM32CubeMX project. If you want to change them, simply use the Visual Studio project properties (or VisualGDB Project Properties). VisualGDB will preserve any manually made changes when updating the project next time:16-dirs
  17. The VisualGDB framework for importing 3rd-party projects is open-source and extremely easy to use. If you would like to import a project in a format that is not directly supported by VisualGDB, you can use our STM32CubeMX importer source as a reference. Simply place your plugin under <VisualGDB>\ProjectImporters directory and VisualGDB will show it in the Embedded Project Wizard.