Intro in STM32F4CubeMX

STM32CubeMX is a graphical tool for 32-bit ARM® Cortex® STM32 microcontrollers. It is part of STM32Cube initiative which provides two main components:

  • STM32F4CubeMX: A graphical software configuration tool that generates the initialization code for STM32 peripherals.
  • STM32F4Cube HAL: A software abstraction layer for STM32 peripherals.


In this tutorial it will be explained how to create basic project for STM32F429DISCOVERY development kit in STM32CubeMX development tool. If you don’t have Keil MDK-ARM µVision5 installed go back and check out last post.

Download CubeMX from ST official page. Once downloaded navigate to Help->Install New Libraries->STM32CubeF4 Releases->Select latest version. 


CubeMX Update Screen
CubeMX Update Screen

After download is complete navigate to start screen and select New Project.

MCU Selection
MCU Selection

On top of the starting screen are placed MCU and Board selectors. There are two ways of creating a project. Both will be explained but for first time go with second option.

The MCU selector tab offers a list of target processors.

Board selector tab shows a list of STMicroelectronics boards.


Creation of project by Board Selection

Board selection allows filtering by Vendor, Type of Board and Microcontroller (MCU) series. Select Discovery Board, STM32F4 and choose STM32F429ZITx MCU.

On the left mark: Initialize all IP in their default Mode. It will automatically set both the pinout and the default modes for the peripherals available on the board. This means that STM32CubeMX will generate the C initialization code for all the peripherals available on the board and not only for those relevant to the user application. It is good configuration if you don’t plan on building a specific application.

Board Selection
Board Selection

Creation of project by MCU Selection

MCU selection allows filtering on various criteria:

  • Series: STM32Fx series are selectable
  • Lines: All lines of products of selected series
  • Package: Describes with which package MCU comes

And additional MCU characteristics such as memory size or number of I/O’s.

Select right MCU, in our case it is STM32F429ZITx with LQFP144 package.

MCU Selector
MCU Selector
STM32CubeMX Pinout view
STM32CubeMX Pinout view

To the left is IP tree where are placed all the peripherals, services… and to the right is Chip view where IP’s can be modified by clicking on it. As it can be seen on the picture above, STM32F4 got two integrated LEDs which we will use now to test this project. Configure LED pins as GPIO_Output and PA0 as GPIO_EXTI0.

Red LED is connected to PG14 and green one to PG13.

USER (Blue button): User and Wake-Up button is connected to the I/O PA0.


Clock Configuration

Go to clock configuration window and set HCLK(MHz) to 180, Cube will automatically set values of the rest variables.

Clock configuration
Clock configuration
  1.  Selectable HSI or HSE as PPL clock source
  2. Selectable HSI, HSE or PLL as system source

HSI: High Speed Internal Clock

HSE: High Speed External Clock

LSI: Low Speed Internal Clock

LSE: Low Speed External Clock

PLL: Phase Locked Loop Configuration

The rest of clock configuration options aren’t important for now. To enable EXTI0 navigate to Configuration and double click on Nested Vector Interrupt Controller (NVIC).

Nested Vector Interrupt Controller Configuration
Nested Vector Interrupt Controller Configuration

Enable EXTI line0 interrupt and click Ok. Navigate to Project->Settings and create project for MDK_ARM V5. Generate code and open project.

In main.c between /* USER CODE BEGIN 4 */ and /* USER CODE END 4 */ tags add:

and compile. By pressing USER (blue button) red LED should be going ON/OFF.

Congratulations on creating Your first project in CubeMX graphical tool, by modifying: Pinout, Clock and Peripherals/Middlewares Configuration of IP’s it is easily achievable to customize STM32Fxx to your needs.

Related posts