Click here to Skip to main content
11,712,802 members (79,859 online)
Click here to Skip to main content

Tagged as

Creating an STM32 Embedded Project in Visual Studio

, 22 Jul 2013 CPOL 15.2K 8
Rate this:
Please Sign up or sign in to vote.
This tip shows how to create a project for STM32 microcontrollers in Visual Studio.

Introduction

STM32 is a popular family of embedded microcontrollers. They are based on the ARM core that allows using various ARM-based tools to develop and debug them once the tools are properly configured. This tip shows how to setup a basic "Blinking LED" project for the STM32100B-EVAL board using Visual Studio, GCC toolchain and OpenOCD debugger.

How the Compilation Works

The STM32 microcontrollers are based on the ARM core. It means they can execute normal instructions supported by the ARM core, i.e., run programs compiled by the ARM compiler. However, simply running instructions is not enough to get even a simple solution working: consider a simple line of code:

GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_SET); 

The ARM compiler will transform it to something like this:

mov.w r4, #4096
movt r4, #16385
movw r2, #16960
str r5, [r4, #16] 

In order to be able to do it, it should know various information about your STM32 device: which ARM core it has, what peripherals it contains (e.g. what is GPIOC) and what are the memory addresses (where the code and variables will go). This information is contained in a board support package - a collection of .C and .H files providing all the necessary information. In order to get our STM32 project working, we will install and configure a board support package.

Before We Begin

Ensure that you have Microsoft Visual Studio and VisualGDB installed. During our project setup, we will install and configure the following tools:

  • GCC compiler for ARM
  • GDB debugger for ARM
  • OpenOCD tool that allows debugging embedded boards via JTAG with GDB

Creating the Project

  1. First of all, start Visual Studio and select File->New->Project:

  2. Select VisualGDB->Embedded Project Wizard:

  3. Select "Create New Project":

  4. As the STM32 devices are based on the ARM toolchain, select the 'arm-eabi' on the next page. Then select your device. This will select the correct board support package so that the ARM GCC compiler will know all it needs to know about the layout of your device:

  5. On the 'debug method' page, select 'OpenOCD' and specify interface and target scripts accordingly:

  6. Press "Finish" to end the wizard. Once the project is generated, Press F5 to build and start debugging your project:

Under the Hood

So how does Visual Studio know how to build and debug your STM32 project? Very easy: the generated project pretends to be a Makefile project supported by Visual Studio:

  • When you build your project, Visual Studio runs GNU Make.
  • GNU Make invokes GCC with all the necessary flags.
  • All the settings specific to your device, such as the corresponding GCC flags are stored in the Makefile.
  • The sources and headers from ST describing the peripherals are mentioned in the Makefile as well.
  • The device memory layout is specified in the linker script that is also mentioned in the Makefile.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ivan Shcherbakov
Founder Sysprogs UG (haftungsbescrhänkt)
Germany Germany
Ivan Shcherbakov is a cofounder of the Sysprogs UG (haftungsbeschränkt), the company developing custom software, drivers and firmware and delivering VisualGDB - a Visual Studio plugin that allows using Visual Studio to build applications with GCC and debug them with GDB.

The main goal of VisualGDB is to combine the time-saving Visual Studio debugging experience with the wide application range of GDB, such as Linux applications and Embeddeed firmware.

A special Android Edition of VisualGDB allows building and debugging native Android code with Visual Studio easily and smoothly.

You may also be interested in...

Comments and Discussions

 
QuestionAny Solution without VisualGDB? Pin
gilgamash10-Jan-14 6:10
membergilgamash10-Jan-14 6:10 
Generalcool Pin
lovewubo25-Aug-13 15:58
memberlovewubo25-Aug-13 15:58 
GeneralRealy nice Pin
rayman223-Jul-13 4:02
memberrayman223-Jul-13 4:02 
GeneralMy vote of 5 Pin
sam.hill22-Jul-13 17:54
membersam.hill22-Jul-13 17:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 22 Jul 2013
Article Copyright 2013 by Ivan Shcherbakov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid