STM32 — Project Setup with CubeIDE

Image for post

What is STM32 and Why You Should Use It?

STM32 is a family of 32-bit microcontroller developed by STMicroelectronics. They are used widely in applications ranging from home automation to toys to consumer appliances. The STM32 series is based on ARM architecture which is one of the most popular computer architectures in the industry.

The wide variety of microcontrollers offered by the STMicroelectronics, allow developers to find the right microcontroller for their applications. Be it low power applications for hand-held battery operated modules, or to develop modules for computation intensive tasks, there is a chance that what ever a developer needs, he/she will likely find a suitable option.

The biggest benefit of having the same manufacturer develop such variety of microcontrollers, is that their internal structure will follow the same rule set and thus, their firmware will be the same across a variety of devices. This makes it easier to learn a single tool and utilize it across multiple projects, which makes production faster.

STM32 — Cube IDE

Image for post

STM32 Cube IDE is a free IDE developed and maintained by STMicroelectronics. In addition to the basic features of an IDE, Cube IDE also has a project initializer, which is used to select the target device, choose required peripherals and finally to configure GPIO names and configurations. When a new project is created, the IDE will automatically generate the startup code needed to run the device. This includes the code needed to initialize the variety of peripherals chosen by the user. This feature allows developers to focus on writing code for their target applications instead of maintaining large code bases for each device initialization.

Note: STM32 Cube IDE can be downloaded from the following link:

Starting a New Project

Image for post

Each CubeIDE project generates an .ioc file for each project. Starting the new project will open the project configuration editor. The Configurator has the following steps to be taken care:

Target Selection

Image for post

We need to select our target device as the first step. This can either be a microcontroller or a development kit. The difference is that a development kit will have preassigned pins for LEDs, buttons etc. In this guide, I am going to use a STM32F407 — Discovery Kit.

Pin Configuration

The next pop-up is to allow to users to set a project name and choose a directory. Once that is done, the Pin Configurations Window opens up. Since, we open with default pin configurations, we should see something similar to this in on the screen

Image for post

Here, we get the option to set GPIO pins as either (Input/Output/Analog) or to operate in interrupt mode. By default, the SPI and I2C peripherals are activated. To add or remove peripherals, we simple need to select the peripherals needed from the tab on left hand side.

Image for post

Image for post

The adjacent page is the clock configurator. We can set the internal clock to the desired value.

Note: Higher the clock frequency, greater the power consumption when the device is active.

Start Coding…

Under the tab of Core->Src we will find the main.c file. Double clicking that will open the file. We can now start writing our code, without being bothered by the hassles of having to setup peripherals separately.

Test LED Toggle

Scroll down to the while loop in the main function. Write the following lines of code inside the while loop and press F-11 key to start debugging. Make sure your board is connected. You should now see an LED blinking on your board.


This demonstrates the ease with which you can start coding your own firmware.

Note: This will work only on STM32F407 Discovery Kits.

Image for post


By the end of this article, you should have a fully functional project that is initialized correctly. Code for all essential and basic functions is auto-generated. If you scroll down the main.c file, you will see that the file includes function definitions and many more variables that will allow you to directly start developing apps for your projects.