Click here to Skip to main content
15,504,830 members
Articles / Microcontroller
Posted 1 Jun 2013

Tagged as


12 bookmarked

Creating STM32 Microcontroller Project in Code::Blocks

Rate me:
Please Sign up or sign in to vote.
4.80/5 (4 votes)
25 Jun 2013CPOL4 min read
Short guide about how to create STM32 flashing ready project in Code::Blocks


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.


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.

Image 1

The second window just shows some welcome message.

Image 2

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

Image 3

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.

Image 4

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.

Image 5

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.

Image 6

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.

Image 7

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.

Image 8

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.

Image 9

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

Image 10

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.

Image 11

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.

Image 12

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

Image 13

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

Image 14

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

Image 15

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.

Image 16

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.

Image 17

STM32F429I-Discovery Project Photo

Since version

Image 18

Points of Interest

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


  • 2013/6/1-1.0


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

Written By
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

QuestionDownload STM32 EPS for Code::Blocks Pin
Member 116460393-Jul-20 20:46
Member 116460393-Jul-20 20:46 
QuestionExample Code Failed - File Too Large (36864 Bytes > 32kB max) Pin
Member 1308704227-Mar-17 3:45
Member 1308704227-Mar-17 3:45 
QuestionWhy CodeBlocks + plugin instead of EmBlocks for STM32? Pin
EmbedAger21-Jun-14 22:37
EmbedAger21-Jun-14 22:37 
AnswerRe: Why CodeBlocks + plugin instead of EmBlocks for STM32? Pin
vatai3821-Jun-14 22:59
vatai3821-Jun-14 22:59 
GeneralRe: Why CodeBlocks + plugin instead of EmBlocks for STM32? Pin
EmbedAger21-Jun-14 23:30
EmbedAger21-Jun-14 23:30 
QuestionFree License for EPS Debugger Activation Pin
Member 1068347920-Mar-14 9:08
Member 1068347920-Mar-14 9:08 
AnswerRe: Free License for EPS Debugger Activation Pin
vatai3820-Mar-14 9:50
vatai3820-Mar-14 9:50 
Questioncan debug with stlink ? Pin
denis ernesto22-Aug-13 8:13
denis ernesto22-Aug-13 8:13 
AnswerRe: can debug with stlink ? Pin
vatai3822-Aug-13 9:18
vatai3822-Aug-13 9:18 
QuestionI can't see STM32 icon in project dialog Pin
Member 101887924-Aug-13 13:54
Member 101887924-Aug-13 13:54 
AnswerRe: I can't see STM32 icon in project dialog Pin
vatai384-Aug-13 22:10
vatai384-Aug-13 22:10 
QuestionI can't see STM32 project Pin
KnightKjt10-Jul-13 20:37
KnightKjt10-Jul-13 20:37 
AnswerRe: I can't see STM32 project Pin
vatai3811-Jul-13 0:30
vatai3811-Jul-13 0:30 
GeneralRe: I can't see STM32 project Pin
KnightKjt11-Jul-13 1:03
KnightKjt11-Jul-13 1:03 
GeneralRe: I can't see STM32 project Pin
vatai3811-Jul-13 1:17
vatai3811-Jul-13 1:17 
QuestionPlease define the Acronym STM32 Pin
MicroImaging25-Jun-13 6:45
MicroImaging25-Jun-13 6:45 
AnswerRe: Please define the Acronym STM32 Pin
Hardie WLR25-Jun-13 9:19
Hardie WLR25-Jun-13 9:19 
AnswerRe: Please define the Acronym STM32 Pin
vatai3825-Jun-13 10:42
vatai3825-Jun-13 10:42 

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

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