|
Last modified on Sat Jul 22 11:30:02 2023 UTC. | Improve this page |
STM32CubeMX is a graphical tool provided by ST Microelectronics, that allows a very easy configuration of STM32 microcontrollers, as well as the generation of the corresponding initialization C code for the Arm® Cortex-M.
This page documents the procedure to create the initialisation code for the NUCLEO-F411RE blinky projects.
For other boards/devices, adjust the steps accordingly.
Note: STM32CubeMX has a very weird implementation, and you may face many small issues with the interface;
The application requires Java. The more recent CubeMX releases include a Java JRE; if this is not enough, install a recent Java distribution.
Register to the STM site and download the latest version.
The result is a file like en.stm32cubemx-*-v6-8-1.zip
. Unpack it and follow
the instructions.
Note: for macOS, if the user account has no administrative rights (as it should not have!), run the install manually, with sudo:
sudo xattr -cr ~/Downloads/en.stm32cubemx-mac-v6-8-1
sudo open ~/Downloads/en.stm32cubemx-mac-v6-8-1/SetupSTM32CubeMX.app
Install in ~/Applications/STMicroelectronics/STM32CubeMX.app
On macOS, the packages repository is stored at ${HOME}/STM32Cube/Repository
Start the application. The current top window looks like:
STM provides separate packages for each family. Install the F7 package.
Before creating a new project, create a new folder in the project,
for example stm32f411cubemx
.
To create a new project, start by selecting the board:
<project>/platform-nucleo-f411re/stm32f411cubemx
), Save
stm32f411cubemx.ioc
was created in the
destination folder.c/.h
files per peripheral
Click the top right GENERATE CODE button.
The result is a file system hierarchy like:
ilg@wks % tree stm32f411cubemx
stm32f411cubemx
├── Core
│ ├── Inc
│ │ ├── gpio.h
│ │ ├── main.h
│ │ ├── stm32f4xx_hal_conf.h
│ │ └── stm32f4xx_it.h
│ └── Src
│ ├── gpio.c
│ ├── main.c
│ ├── stm32f4xx_hal_msp.c
│ ├── stm32f4xx_it.c
│ └── system_stm32f4xx.c
├── Drivers
│ ├── CMSIS
│ │ ├── Device
│ │ │ └── ST
│ │ │ └── STM32F4xx
│ │ │ ├── Include
│ │ │ │ ├── stm32f411xe.h
│ │ │ │ ├── stm32f4xx.h
│ │ │ │ └── system_stm32f4xx.h
│ │ │ ├── LICENSE.txt
│ │ │ └── Source
│ │ │ └── Templates
│ │ ├── Include
│ │ │ ├── cmsis_armcc.h
│ │ │ ├── cmsis_armclang.h
│ │ │ ├── cmsis_compiler.h
│ │ │ ├── cmsis_gcc.h
│ │ │ ├── cmsis_iccarm.h
│ │ │ ├── cmsis_version.h
│ │ │ ├── core_armv8mbl.h
│ │ │ ├── core_armv8mml.h
│ │ │ ├── core_cm0.h
│ │ │ ├── core_cm0plus.h
│ │ │ ├── core_cm1.h
│ │ │ ├── core_cm23.h
│ │ │ ├── core_cm3.h
│ │ │ ├── core_cm33.h
│ │ │ ├── core_cm4.h
│ │ │ ├── core_cm7.h
│ │ │ ├── core_sc000.h
│ │ │ ├── core_sc300.h
│ │ │ ├── mpu_armv7.h
│ │ │ ├── mpu_armv8.h
│ │ │ └── tz_context.h
│ │ └── LICENSE.txt
│ └── STM32F4xx_HAL_Driver
│ ├── Inc
│ │ ├── Legacy
│ │ │ └── stm32_hal_legacy.h
│ │ ├── stm32f4xx_hal.h
│ │ ├── stm32f4xx_hal_cortex.h
│ │ ├── stm32f4xx_hal_def.h
│ │ ├── stm32f4xx_hal_dma.h
│ │ ├── stm32f4xx_hal_dma_ex.h
│ │ ├── stm32f4xx_hal_exti.h
│ │ ├── stm32f4xx_hal_flash.h
│ │ ├── stm32f4xx_hal_flash_ex.h
│ │ ├── stm32f4xx_hal_flash_ramfunc.h
│ │ ├── stm32f4xx_hal_gpio.h
│ │ ├── stm32f4xx_hal_gpio_ex.h
│ │ ├── stm32f4xx_hal_pwr.h
│ │ ├── stm32f4xx_hal_pwr_ex.h
│ │ ├── stm32f4xx_hal_rcc.h
│ │ ├── stm32f4xx_hal_rcc_ex.h
│ │ ├── stm32f4xx_hal_tim.h
│ │ ├── stm32f4xx_hal_tim_ex.h
│ │ ├── stm32f4xx_ll_bus.h
│ │ ├── stm32f4xx_ll_cortex.h
│ │ ├── stm32f4xx_ll_dma.h
│ │ ├── stm32f4xx_ll_exti.h
│ │ ├── stm32f4xx_ll_gpio.h
│ │ ├── stm32f4xx_ll_pwr.h
│ │ ├── stm32f4xx_ll_rcc.h
│ │ ├── stm32f4xx_ll_system.h
│ │ └── stm32f4xx_ll_utils.h
│ ├── LICENSE.txt
│ └── Src
│ ├── stm32f4xx_hal.c
│ ├── stm32f4xx_hal_cortex.c
│ ├── stm32f4xx_hal_dma.c
│ ├── stm32f4xx_hal_dma_ex.c
│ ├── stm32f4xx_hal_exti.c
│ ├── stm32f4xx_hal_flash.c
│ ├── stm32f4xx_hal_flash_ex.c
│ ├── stm32f4xx_hal_flash_ramfunc.c
│ ├── stm32f4xx_hal_gpio.c
│ ├── stm32f4xx_hal_pwr.c
│ ├── stm32f4xx_hal_pwr_ex.c
│ ├── stm32f4xx_hal_rcc.c
│ ├── stm32f4xx_hal_rcc_ex.c
│ ├── stm32f4xx_hal_tim.c
│ └── stm32f4xx_hal_tim_ex.c
├── Makefile
├── STM32F411RETx_FLASH.ld
├── startup_stm32f411xe.s
└── stm32f411cubemx.ioc
16 directories, 83 files
Add the following source folders to the build:
stm32f411cubemx/Core/Src
stm32f411cubemx/Drivers/STM32F7xx_HAL_Driver/Src
Add the following include folders to the build:
stm32f411cubemx/Core/Inc
stm32f411cubemx/Drivers/CMSIS/Device/ST/STM32F4xx/Include
stm32f411cubemx/Drivers/CMSIS/Include
stm32f411cubemx/Drivers/STM32F4xx_HAL_Driver/Inc
Although not critical, for a better error reporting, some small changes
can be performed to the stm32f411cubemx/Core/Src/main.c
file.
Being braced by the special comments, these changes survive regenerations with CubeMX.
/* USER CODE BEGIN Includes */
#if defined(OS_INCLUDE_MICRO_OS_PLUS_DIAG_TRACE)
#include <micro-os-plus/diag/trace.h>
#endif
/* USER CODE END Includes */
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
#if defined(OS_INCLUDE_MICRO_OS_PLUS_DIAG_TRACE)
trace_printf("Error_Handler()\r\n");
#endif
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
#if defined(OS_INCLUDE_MICRO_OS_PLUS_DIAG_TRACE)
trace_printf("Wrong parameters value: file %s on line %d\r\n", file, line);
#endif
while(1) {}
/* USER CODE END 6 */