[STM32] - part 1 - Cortex what...?

Recently I wrote a short article about setting up an environment for programming STM32 microcontrollers with the libopencm3 library. You can read it here.

I wanted to write the second part as soon as possible but I found out that even though I could, I didn’t understand everything well enough. I just didn’t feel comfortable with the subject. That’s why I started this series. I want to explore what actually happens when you program a STM32 microcontroller.


STM32 is a family of 32-bit microcontrollers based on the ARM Cortex-M architecture. The fact that they are ARM-based is really important and a lot of concepts stem from that fact. What does it actually mean for you? The architecture defines how the processor is built and, as a result of this, defines a set of instructions the processor understands.

Programming languages, like C, allow developers to write code which can be compiled for different platforms. Compilers take the burden of translating the code to platform specific instructions on themselves. These platform specific instructions can also be directly written in Assembly language. You might have heard about Assembly in a sentence like:

No one programs in Assembly anymore!

Which is mostly true. Assembly is too granulary, because it deals with the operations on the specific registers of the processor - it describes what the processor actually does, step by step. It isn’t easy to write in Assembly if you don’t know how the processor works. Assembly targets a specific architecture, thus it’s not easy to port that code to a different processor.

Reading and learning about Assembly for a specific architecture, can be really beneficial to understand what actually happens inside the processor, and I strongly encourage you to do so. One of the more interesting articles on this topic can be found here.

Lets get back to ARM. Saying something uses an ARM-based architecture, does not tell you a lot. If you talk about specific processor you should also know if it’s Cortex-R, Cortex-A or Cortex-M. Those are the three main series of processors using ARM architecture. Since we are here to program microcontrollers, only Cortex-M cores are of interest for us. Cortex-R are used for hard real-time applications. Cortex-A are for application use (lets say small Linux computers, like Raspberry Pi). Cortex-M? Well… Microcontrollers! You can find links to the official pages of those series at the end of this article.

The instructions Cortex-M processors support are called thumb-v1 and thumb-v2. Depending on the Cortex-M processor version you might find that it might also support floating point math, DSP or SIMD instructions. That’s an additional complexity but that’s where the impressive processing power of these small devices come from.

But don’t worry. You won’t be writing Assembly (unless you really want to). You just have to understand that the architecture of the processor matters. It tells you what the processor can do and with what it might struggle. It’s more beneficial to be able to read Assembly than it is to write it.

Everything written above is important because it influences the way the STM32’s libraries are written and distributed. Before going into the libraries I will delve into the memory of a typical STM32 microcontroller in part 2.

Cortex series pages:

STM32 Explained part 2