Developing STM32 projects with Visual Studio

This tutorial shows how to create a simple 'Blinking LED' project for the STM32100B-EVAL board using Visual Studio.

Before we begin, ensure that VisualGDB 4.0 or later is installed.

  1. Start Visual Studio. Go to File->New->Project.
  2.  Select VisualGDB -> Embedded Project Wizard. Specify project directory and enter project name.
  3. Select "Embedded binary". If you want VisualGDB to generate a .bin file additionally to an .elf file, ensure that the corresponding checkbox is checked.
  4. On the next page select the arm-eabi toolchain. If it is not installed, VisualGDB will install it automatically.
  5. In order to automatically install support files for STM32 microcontrollers press the "download support for more devices" button. Click "find support packages" to see the list of available device packages. Select "STM32 MCUs" from the list and press "Install selected packages":
  6. VisualGDB will show the list of supported devices. Select your device from the list:
  7. VisualGDB will generate the default 'Blinking LED' sample project. You can select the port number and the blinking delay on the next page:
  8. On the last wizard page you can select a debug method. If you are using Segger J-Link, VisualGDB will configure all command lines automatically. If you are using OpenOCD, refer to its documentation for the command line corresponding to your JTAG debugger, select "Custom GDB stub" and provide the OpenOCD command line.
    In this tutorial we will use Segger J-Link. Click on "Install support for additional debug methods".
  9. Select "Segger J-Link" from the list and press OK.
  10. If you have not installed the Segger software package yet, follow the link in VisualGDB wizard to install it. Once installed, specify its location in the "Segger J-Link directory" field:
  11. Press Finish to complete the wizard. VisualGDB will generate a Visual Studio project for your STM32 device. Press Ctrl-Shift-B to build it:
  12. To start debugging it simply power on your board and connect the JTAG debugger to it. Ensure that Windows recognizes the device and loads the appropriate drivers. Set a breakpoint inside the loop and press F5 to start debugging. You can debug your firmware just like an ordinary Windows program:
  13. Press F10 to step over the line that turns on the LED. You will see the LED turning on:
  14. You can customize various project settings by right-clicking on the project node in Solution Explorer and selecting "VisualGDB Project Properties". E.g. you can specify additional include directories on the "Makefile settings" page. VisualGDB will automatically update your makefile and synchronize IntelliSense settings:

You can also use OpenOCD or Texane/ST-Link tool to debug your STM32 projects. Follow the corresponding tutorials for more details.