cancel
Showing results for 
Search instead for 
Did you mean: 

Header files required for programming STM32F446 MCU in C

STehA.1
Associate II

I am new to ARM processor and I need to know what are the header files required in main.c for programming the above MCU in C by just accessing its registers (and manipulating bits) as explained in RM0390 (REFERENCE MANUAL for STM32F446xx) ?

NOTE: I am not interested in using any intermediate framework/API like HAL etc

I am using STM32CubeIDE 1.3.0

2. By the way I have some experience using specifically Atmel ATXMEGA256 MCU where these are just the header files required in my C apps:

// for atxmega256 mcu

#include <avr/io.h>

// for interrupt

#include <avr/interrupt.h>

// handle string in C

#include <string.h>

// library for itoa

#include <stdlib.h>

Thank you

3 REPLIES 3
berendi
Principal

The simplest way is to create a new STM32 project, select your MCU, let it generate code once, then delete what you don't need, i.e. the .ioc file, the Drivers/STM32F4xx_HAL_Driver directory, and all source files except startup_stm32*.s and system_stm32*.c

This would result in an empty project with the MCU, core, and standard C headers, and the minimal startup code (mostly in assembly).

Another possible approach is to download STM32CubeF4 from ST, and extract only the Drivers/CMSIS subdirectory.

As an alternative, CubeF4 can be browsed through at https://github.com/STMicroelectronics/STM32CubeF4 .

ARM headers are at https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Drivers/CMSIS/Include, device headers at https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Drivers/CMSIS/Device/ST/STM32F4xx/Include , startup files https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc .

As an equivalent of <avr/io.h>, here, you'd use stm32f4xx.h, which together with appropriately defined preprocessor macro for the given subfamily (-DSTM32F446xx in command line/makefile) will include the proper header plus also the ARM headers (which then provide the symbols and functions for interrupts and similar processor-level items). stdio.h and string.h are standard C headers, provided by the toolchain, independent from particular target.

I personally throw out calls to SystemInit and __libc_init_array from the startup file, don't use the system_stm32f4xx.c at all and use an empty system_stm32f4xx.h, but you may feel about these otherwise.

You may want to get a linker script from one of the examples at https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects , unless you use some of those IDEs which provide the magic for you.

And I confess to use a makefile adopted from the one from WinAVR/mfile.

JW

TDK
Guru

Even if you don't use the HAL functions, consider still including "stm32f4xx.h" and using the built in defines for the peripheral registers and bits. This makes code so much more readable for anyone who may come across it.

At the end of the day, none of the files are required. But they sure can make the job easier.

If you feel a post has answered your question, please click "Accept as Solution".