Bare Metal Programming
with C in STM32CubeIDE
MOHD RIDZUAN BIN AHMAD
INTRODUCTION
• Bare Metal Programming in STM32CubeIDE
means not using the HAL library.
• The default setting in STM32CubeIDE
utilizes the HAL library.
• Therefore, to write a pure C program, this
default setting must be changed.
STEP 1: Create a Project
• Start a New Project in STM32CubeIDE:
Open STM32CubeIDE and select File >
New > STM32 Project.
• Choose your STM32F411 microcontroller
and proceed.
• Write the project’s name and select the
default setting in the Options. Click Next,
then click Finish.
STEP 2: IOC Setting
• Select Project Manager Tab: Under Code
Generator, locate the checkbox that says
"Generate peripheral initialization as a
pair of .c/.h files per peripheral". Uncheck
this box to avoid automatic initialization
of peripherals with the HAL library.
• The IOC page can be closed.
STEP 3: Project Explorer Setting
• In the Project Explorer, locate and delete files:
Core/Src/stm32f4xx_hal*.c
Core/Inc/stm32f4xx_hal*.h
Drivers/STM32F4xx_HAL_Driver
• You’ll need to retain the startup file and linker
script (*.ld) generated by STM32CubeIDE, as
they handle memory layout and vector table
settings.
STEP 3: Project Explorer Setting
• Go to Project > Properties.
• Under C/C++ Build > Settings, find Tool
Settings.
• Locate the GCC Compiler -> Preprocessor
options. Remove USE_HAL_DRIVER if it’s
defined, as it tells the compiler to include
HAL.
STEP 3: Project Explorer Setting
• Open file Inc/main.h:
Replace any line contains #include
“stm32f4xx_hal.h” with #include
“stm32f411xe.h”
• Open file Src/stm32f4xx_it.c:
Write volatile uint32_t tick_count = 0; after
line /* USER CODE BEGIN PV */
Replace HAL_IncTick(); in SysTick_Handler()
with tick_count++;
STEP 4: Main() Setting
• Clear the auto-generated code.
• Write the following basic structure:
#include "stm32f411xe.h" // Device header for STM32F411
int main(void) {
// Configuration codes
while (1) {
// Your codes
}
}
THE END