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:
    2.  Select VisualGDB -> Embedded Project Wizard. Specify project directory and enter project name:
    3. Select “Create New Project” on the first wizard page:
    4. On the toolchain selection page select “arm-eabi”. If you don’t have the arm-eabi toolchain installed, VisualGDB will install it automatically. Then select your device from the list:
    5. On the next page confirm the “Blinking LED” sample by pressing “next”:
    6. Connect your ST-Link to the USB port and let VisualGDB detect it:
    7. VisualGDB will automatically download the latest OpenOCD package and will let you configure most common settings using convenient GUI:
    8. Press “Test selected OpenOCD settings” in the VisualGDB project wizard to verify your settings:
    9. If you are familiar with OpenOCD internals and would like to tweak the startup commands or the command line, use the Advanced Settings view to edit them directly:
    10. Press “finish” to close the wizard. VisualGDB will generate a Visual Studio project. Press Ctrl-Shift-B to build it:
    11. 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. Note how the LED on the board turns on and off as you step over the corresponding lines:13-board
    13. 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. VisualGDB will automatically index your sources (and the STM32 package sources) and will let you navigate through them using CodeJumps. Simply click the CodeJumps labels near the function declarations to view references, call trees, functions “implementing” specific function pointers and so on:
    15. Use the View->Embedded Memory Explorer to get a detailed report about the structure of your embedded binary, including the locations of sections in memory, sizes of individual functions, their disassembly view and worst-case stack analysis: