STM32 Development with CubeMX and Eclipse

lineartestpilot, 123RF

Thrifty & Nifty

The diverse family of STM32 chips from STMicroelectronics are based on a 32 bit ARM processor core. The chips are economical, energy efficient, and suitable for a large variety of projects. This article examines how the STM32 has developed, particularly under Linux.

The 32 Bit micro controllers of the STM32 product line have a small price tag and exceptional performance capabilities. For example, if you go to Amazon's Chinese competitor AliExpress, you will find the STM32F0F4P6 chip clocked at 48 MHz in a solder-ready TSOP package for about 40 cents. For just under US $2.50 , you will also find the STM32F103C8T6 in the form of a compact, Arduino Nano-like module. This chip is clocked at a maximum of 72 MHz and is equipped with USB and CAN support. This very low price tag even includes the costs of delivery

This chip has an additional advantage over the widely distributed 8 bit microcontrollers in its SWD programming interface. This interface requires just three wires for data, clock rate, grounding and if necessary the supply voltage. It also lets you code and test programs easily with the GNU debugger project GDB. Programming adapters are also cheap. AliExpress sells the STLink V2 compatible adapter as a USB stick for under US$3.00.

The hurdles for getting started with this chip are higher than with the Arduino, though. In particular, mobile devices require limited power, meaning you must first activate any components being used such as GPIOs or an A/D converter to supply them with current. The number of lists increases considerably due to the greater functionality.

The more complex internal structures also have an impact on the programming interface. For example, there are numerous functional units connected using bus bars. Some of these units run with a much lower clock rate than the processor core. For instance there's a special list for GPIOs, allowing you to set and switch individual bits. This in turn prevents read-modify-write access.

The industry has agreed upon uniform programming interfaces like CMSIS for ARM based micro controllers, which are designed for standard languages. Once you're familiar with an interface, you can apply this knowledge to another manufacturer's controller.


The abbreviation CMSIS stands for Cortex Microcontroller Software Interface Standard. It is applied across manufacturers to cortex M processors.

This means for example, that programs can be exchanged between STM32Fx controllers without the need for making significant changes to the source text. There is also a great deal of physical compatibility. As a result, an STM32F103C8 has connective compatibility with an STM32F105C8. Previously, the STM32 Standard peripheral library comprised only a uniform abstraction layer. This is supposed to be replaced by the HAL library or Hardware Abstraction Layer in the near future.

The controllers offer a relatively large number of settings for the clock rate source. This is necessary because certain functional units like the USB interface or the A/D converter require input clock rates with fairly exacting specifications. In order to save the user the effort of engaging in complicated planning, ST offers the program CubeMX. This program configures all of the resources graphically and then creates a C program project together with the necessary initialization.

Even so, CubeMX only creates projects for commercial development environments. This article describes how you use this program in order to create and program a project for Eclipse, and then debug it with OpenOCD.

Programs & Devices

The STM32VTL Discovery Evaluation Platform is the target platform. It's available from numerous online stores. Alternatively, you can order an STLinkV2 programming adapter directly from China on AliExpress for about US$ 2.50 and an STM32F103C8T6 board for around US$2.00 .

If you first want to try and get by without buying any new hardware, you can use QEMU emulator to carry out these instructions [1]. You will also need a USB serial adapter based on something like FT232. If you're a Linux user check carefully to make sure your chip is supported.


On the application side, you will need the arm-none-eabi development tools for GCC (Version 4.9+) and GDB. Linux users can typically install both of these with their package manager. These tools are also available for other systems on the project page [2]. The website for GNU ARM Eclipse [3] provides a description of how to install the tools on common operating systems.

For purposes of this article, we are working with an automatically generated makefile. Therefore, in spite of the recommendation at the end of these instructions, make sure you are able to call the compiler from the shell with


If you are unable to do so, then modify either the $PATH variable or, in each case, the relevant makefile.

You will need Git and Python (for the converter), a Java runtime environment (for CubeMX and Eclipse), OpenOCD, Eclipse 4.5+ with a CDT plugin already installed. If you're using a serial interface, you'll also need a program for this such as Gtkterm or Screen.

The following steps describe installing a development environment, focusing on Linux. These steps include installing the STLink adapter and then configuring it for Udev. To do this, set up a /etc/udev/rules.d/99-stlink.rules file with administrative rights and suitable Udev rules (Listing 1). Have the system read these as shown in Listing 2.

Listing 1


:ATTRSidVendor=="0483", ATTRSidProduct=="3744", MODE="0666"

Listing 2

Loading udev rules

$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

Buy this article as PDF

Express-Checkout as PDF

Pages: 7

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content