STM32 debugging with ST-Link, OpenOCD & VisualGDB

This tutorial shows how to debug your embedded STM32 projects using ST-Link hardware debugger, OpenOCD and Visual Studio with VisualGDB.

Before proceeding with the tutorial please ensure that VisualGDB 4.0 or later is installed.

  1. Start Visual Studio. Create a new project by selecting File->New->Project: 01-newproj
  2.  Select VisualGDB -> Embedded Project Wizard.
    Specify project directory and enter project name.
  3. Select “Create New Project” on the first wizard page:04-binary
  4. On the toolchain selection page select “arm-eabi”. If you don’t have the arm-eabi toolchain installed, VisualGDB will install it automatically. Click “download support for more devices” and select “STM32 devices”. Finally, select your device from the list:05-stm32
  5. On the next page confirm the “Blinking LED” sample by pressing “next”:06-ledblink
  6. In order to use ST-Link with VisualGDB, you will need to configure OpenOCD. VisualGDB Project Wizard will assist you in configuring it. Select “OpenOCD” in the debug method list. If it is not shown, click “Install support for additional debug methods”. Select “ST-Link v2” as the interface or press “Detect” to find it automatically:07a-stlinkauto
  7. Press “Test selected OpenOCD settings” in the VisualGDB project wizard to verify your settings:10a-verified
  8. You can also switch to the manual mode and customize OpenOCD initialization scripts:09a-advanced
  9. Press “finish” to close the wizard. VisualGDB will generate a Visual Studio project. Press Ctrl-Shift-B to build it:11-build
  10. Put a breakpoint on a line that turns on a LED and press F5 to start debugging. Once the breakpoint is hit, press F10 to step over a line:12-breakpoint
  11. Note how the LED on the board turns on and off as you step over the corresponding lines:13-board
  12. When you are done debugging, you can modify various project properties by right-clicking in the project node in Solution Explorer and selecting “VisualGDB Project Properties”.14-projectprops

You can also use the Texane/ST-Link tool to debug your STM32 boards. Follow this tutorial for details.