Click here to Skip to main content
Click here to Skip to main content

Tagged as

Creating STM32 Microcontroller Project in Code::Blocks

, 25 Jun 2013
Rate this:
Please Sign up or sign in to vote.
Short guide about how to create STM32 flashing ready project in Code::Blocks

Introduction

For those who have decided to develop STM32 embedded application, but still do not know how to start, now you can get insight. For this purpose, we will use Code::Blocks IDE equipped with Embedded Plugin Suite. The Code::Blocks IDE is an open source free IDE and the Embedded Plugin Suite is a special set of plugins and scripts extending the basic Code::Blocks IDE suite. Embedded Plugin Suite includes GCC ARM toolset for building the projects and also debugger plugin support almost all STM32 devices via ST-Link/V2 in-circuit debug adapter.

Background

You need to install three things to start the development process:

  1. Code::Blocks IDE
  2. Embedded Plugin Suite
  3. ST-Link/V2 driver

Also you need eval board, e.g., STM32 Discovery series will be the best choice for beginners. In this tip, we will use STM32F3Discovery.

The Project Wizard

After launching the Code::Blocks IDE, select File > New > Project ... menu item. This starts showing series of wizard windows guiding you through the project creation process. In the first window, select STM32 Project and confirm your selection.

The second window just shows some welcome message.

In the third window, enter the project title and choose its location.

The fourth allows you to select the target hardware platform and some libraries used in project creation process and also the roamable file format. As mentioned above, our target board now is STM32F3-Discovery. Choosing some eval board gives more options to application skeleton to select from. If you choose Custom design which means project from scratch and then just basic application skeleton will be available.

Fifth window serves for entering of some settings regarding linking. Personally, I recommend not to change these settings if you are not familiar with GNU linker scripts. Values selected or entered here will be reflected in generated linker script. One comment: the linked script name is not target.ld as mentioned in the text at the top, rather <project_name>.ld. All requested changes to final memory layout can be achieved via editing of this file later.

Now select the project skeleton. Here it is better to select some ready made project to avoid trouble with building. Also you can try many of these projects and later customize some of them. The edit box below gives some description of the created project.

If you want not to just build the project but to improve it, test it then selecting the right hardware debugger ensures method how to board into work. Here you can for now just select only the ST-Link/V2.

The final step is the toolset selection and build target selection. To allow to debug our project, check Create "Debug" configuration. After changing preselected toolset (compiler) STM32 GCC Compiler can happen that the project will require some manual adjustments due to different compiler options. Perform them in dialog shown after selecting Project > Build options menu item if necessary. Clicking on Finish button launches project creation project. All files will be copied to the directory selected in the third step.

Building the Project

Now our project is ready for build. Launch compiling and linking by pressing Ctrl-F9 or choosing the menu item shown below. More complex project can consist from more build targets. Each of them is compiled and linked separately but with respect of dependence order. Some of the build targets are so called virtual targets which define this dependence.

After the building process is complete, look at Build log to make sure there are no build errors.

Debugging the Project

Now the project is built. It's time to get it into target board memory. While there can be many different build targets, only some of them embody the complete target code. Others can be some helper or auxiliary build targets. The build targets names entered in final wizard step always meet this requirements. Following explanation describes how to start debugging just shortly.

Activate the connection with ST-Link/V2 in-circuit debug adapter. Do not forget to plug its host USB cable into some of USB ports. Also, you need to connect the target side cable JTAG/SWD cable with target board. This is not the case of STM32 Discovery boards. The new boards has settled jumpers ensuing this at proper position.

Before first time connection, you can observe this dialog requesting to confirm current settings state.
You can keep defaults. Later, you may change this by selecting Debug > Target settings ... menu item.

  • Ano = Yes
  • Ne = No

The EPS Debugger log window collects debugger messages, Here will be logged if some trouble occurs during the connection. Now all is ok.

After successful connection, we can send (download) our project code into target board.

Before resetting our board, look again into EPS Debugger log window to see if no error occurred during the download process. To reset (set PC to default initial address) the board, click Debug > Reset menu item.

Now we can start testing what we created. The yellow line shows the current PC (program counter) location.
Describing debugging techniques is beyond the boundaries of this guide.

STM32F429I-Discovery Project Photo

Since version 1.14.0.0

Points of Interest

It was long inconceivable that I some day will debug the debugger.

History

  • 2013/6/1-1.0

License

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

Share

About the Author

vatai38
Software Developer (Senior)
Slovakia Slovakia
Code::Blocks developer, wxWidgets developer, Debugger developer, Embedded developer, Hardware engineer, Amiga fan, FPGA developer, Video card developer

Comments and Discussions

 
QuestionWhy CodeBlocks + plugin instead of EmBlocks for STM32? [modified] PinmemberEmbedAger21-Jun-14 21:37 
AnswerRe: Why CodeBlocks + plugin instead of EmBlocks for STM32? Pinmembervatai3821-Jun-14 21:59 
GeneralRe: Why CodeBlocks + plugin instead of EmBlocks for STM32? PinmemberEmbedAger21-Jun-14 22:30 
QuestionFree License for EPS Debugger Activation PinmemberMember 1068347920-Mar-14 8:08 
AnswerRe: Free License for EPS Debugger Activation Pinmembervatai3820-Mar-14 8:50 
Questioncan debug with stlink ? Pinmemberdenis ernesto22-Aug-13 7:13 
AnswerRe: can debug with stlink ? Pinmembervatai3822-Aug-13 8:18 
QuestionI can't see STM32 icon in project dialog PinmemberMember 101887924-Aug-13 12:54 
AnswerRe: I can't see STM32 icon in project dialog Pinmembervatai384-Aug-13 21:10 
QuestionI can't see STM32 project PinmemberMember 913924010-Jul-13 19:37 
AnswerRe: I can't see STM32 project Pinmembervatai3810-Jul-13 23:30 
GeneralRe: I can't see STM32 project PinmemberMember 913924011-Jul-13 0:03 
GeneralRe: I can't see STM32 project Pinmembervatai3811-Jul-13 0:17 
QuestionPlease define the Acronym STM32 PinmemberMicroImaging25-Jun-13 5:45 
AnswerRe: Please define the Acronym STM32 PinmemberHardie WLR25-Jun-13 8:19 
AnswerRe: Please define the Acronym STM32 Pinmembervatai3825-Jun-13 9:42 

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 | Mobile
Web01 | 2.8.140814.1 | Last Updated 25 Jun 2013
Article Copyright 2013 by vatai38
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid