Compiling STM32 examples in Linux

ST has quite a lot of source code examples for their evaluation boards introducing about all features of the boards. The downside is they support only commercial compilation environments, like IAR EWARM, MDK-ARM, RIDE, TASKING and TrueSTUDIO.

The examples can also be compiled in Linux with relatively little effort: add a Makefile, C library stubs and fix the case sensitivity issues in the filenames. This blog post is about compiling STM32 USB device/host library for an STM32 F2 board although the instructions hopefully apply to other examples as well.

To get started, git clone the example Makefile and stubs file from our Github repository and unzip the STM32 USB device/host library under the cloned tree:

git clone git://
cd stm32-examples

Fixes needed to unbreak the ST code:

  • Remove one extra white space from an #include in STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F2xx/stm32f2xx.h line 6832.
  • Make a symbolic link from STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Utilities/STM32_EVAL/STM322xG_EVAL to stm322xg_eval to match some of the include paths.

One thing missing from the example is the stubs and implementations for certain C library functions not provided in the toolchain. I’ve taken them from The STM32 Discovery Scrapbook from Nano Age and it’s already included in the STM32-examples with the Makefile.

I’m using Mentor Graphics’ (formerly Code Sourcery) toolchain because of old habits. You can get the EABI toolchain from here. I’ve used the IA32 GNU/Linux TAR package since it’s easy to take into use, just untar it and you are done. I’ll probably start using upstream GNU GCC releases some day.

The Makefile in the cloned STM32-examples compiles the USB Host example for the STM3220G-EVAL evaluation board. See the comments in the Makefile to change them.

To compile the project, run make:

make CROSS_COMPILE=/path/to/arm-2011.03/bin/arm-none-eabi-

To program the software to the chip, see our last post about OpenOCD and GDB or use e.g. STM32flash to program the flash over serial.

This entry was posted in Tools and tagged , . Bookmark the permalink.

Comments are closed.