Creating STM32 project in Code::Blocks

Embedded Plugin Suite  Stm32 project For those who decided to develop STM32 embedded application but still do not know how to start now can get insight. For this purpose we will use Code::Blocks IDE equipped with Embedded Plugin Suite. The Code::Blocks IDE is 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 and Embedded Plugin Suite or Code::Blocks (EPS Edition)
2. ST-Link/V2 driver

Also you need eval board e.g. STM32 Discovery series will be the best choice for beginners. In this article 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.

Embedded Plugin Suite  Stm32 project wizard

The second window just showing some welcome message.

Embedded Plugin Suite  Stm32 project wizard

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

Embedded Plugin Suite  Stm32 project wizard

The fourth allows you to select the target hardware platform and some libraries used in project creation  process and also the romable file format. As mention above our target board now is STM32F3-Discovery. Choosing some eval board gives a 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.

Embedded Plugin Suite  Stm32 project wizard

Fifth window serves for entering of some settings regarding to linking. Personally I recommend not to change these settings if 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 text at the top rather <project_name>.ld . All requested changes to final memory layout can be achieved via editing of this file later.

Embedded Plugin Suite  Stm32 project wizard

Now select the project skeleton. Here 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.

Embedded Plugin Suite  Stm32 project wizard

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

Embedded Plugin Suite  Stm32 project wizard

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 third step.

Embedded Plugin Suite  Stm32 project wizard

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 build targets are so called virtual targets which defining this dependence.

Embedded Plugin Suite  Stm32 building project

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

Embedded Plugin Suite  Stm32 building project

Debugging the project

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

Embedded Plugin Suite  Stm32 debugging project

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 connect the target side cable JTAG/SWD cable with target board. This is not case of STM32 Discovery boards. The new boards has settled jumpers ensuing this at proper  position.

Embedded Plugin Suite  Stm32 debugging project

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

Ano = Yes

Ne = No

Embedded Plugin Suite  Stm32 debugging project

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

Embedded Plugin Suite  Stm32 debugging project

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

Embedded Plugin Suite  Stm32 debugging project

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

Embedded Plugin Suite  Stm32 debugging project

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

Embedded Plugin Suite  Stm32 debugging project