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.
- Start Visual Studio. Create a new project by selecting File->New->Project:
- Select VisualGDB -> Embedded Project Wizard.
Specify project directory and enter project name.
- Select “Create New Project” on the first wizard page:
- 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:
- On the next page confirm the “Blinking LED” sample by pressing “next”:
- 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:
- Press “Test selected OpenOCD settings” in the VisualGDB project wizard to verify your settings:
- You can also switch to the manual mode and customize OpenOCD initialization scripts:
- Press “finish” to close the wizard. VisualGDB will generate a Visual Studio project. Press Ctrl-Shift-B to build it:
- 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:
- Note how the LED on the board turns on and off as you step over the corresponding lines:
- 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”.
You can also use the Texane/ST-Link tool to debug your STM32 boards. Follow this tutorial for details.