Use em::Blocks with the STM32F4-Discovery

After trying several IDE to program the STM32F4-Discovery card, I have selected the em::Blocks solution.

This is a free environment without code size limitation (unlike the free version of commecrial EDI). It is a fork of code::Blocks dedicated to embedded code generation. It manage out of the box numerous evaluation boards, including the STM32F4-Discovery card.

This software can be found in the download page of the site em::Blocks.



– em:Blocks downloaded and installed  😉  The version used for this article is the V2.30

– STM32F4 drivers installed : can be downloaded on the ST Page ( and search the STSW-LINK reference (stsw-link008 for Windows 7 driver).

– Firmware for the STM32F4-Discovery card : on the same ST page, search for the STSW-STM32068 reference to download file.

– Create a new working directory named “C:\STM32F4” and unzip file inside. The result must be:


New project creation


Creation of the base cade

1) Launch em::Blocks. Open the menu “File / New / Project…”
2) Select “STmicro-ARM”


3) Enter the project name and the path


4) keep the default options


5) Select Cortex M4 (F3xx-F4xx)


6) Select STM32F4xx


7) Select STM32F407VG


8) Keep the default configuration


9) Select “Target settings” tab and check “Run to main()”. It allows the debugger to stop on the frist program line instead of the first assembler line of the loader.

==> The code is now generated.


Adaptation for the STM32F4-Discovery

1) Copy the firmware in the project directory :
copy c:\STM32F4\STM32F4-Discovery_FW_V1.1.0\Utilities\STM32F4-Discovery
to c:\STM32F4\Test


2) Import modifications in the projet


In the left window (project structure), right click on the project name. In the contetual menu select “Add files recusrsively”.

3) Sélect the new directory (we have just copied) to add it in the project


4) Validate the 2 dialog boxes that indicate the files to import

2015-01-03_173859 2014-12-31_101723

5) To avoid to include other dependencies, we need to remove the “audio” management files



Open the STM32F4-Discovery directory in the project window (left window).
Right click on the “”stm32f4_discovery_audio_codec.c” file and select “Remove file from project” to remove it (the file can also be deleted from the disc, but not mandatory).


5) Take in account the 8Mhz quartz

In the src directory, edit the file system_stm32f4xx.c

It is a configuration file that is automatically called during the boot phase. Contrary to what is indicated in the comment line 59, the crystal frequency is 8MHz. We need to change the PLL_M value to 8.

Edit the line 156 (or search the PLL_M constant) and change the value to 8:

#define PLL_M   8


6) The projet is now ready to compile.

For tests, I suggest you the following code for the main.c :

#include “stm32f4_discovery.h”

int main(void)
while(1) ;

In case of compil error related to the “audio” file, juste delete the “c:\STM32F4\Test\obj\Debug” rirectory and relaunch the compilation.


 Template generation

In order to redo this work for each new project, it is possible to create a project template.
By using this project that is correctly configurated, open the “File / Save project as template…” menu and just select a name for this template.


For new projects, just use the menu “File / New / From Template…” and select your template in order to have the default configuration applied. 🙂

Comments are closed.