Bare Metal Programming with
Assembly in STM32CubeIDE
MOHD RIDZUAN BIN AHMAD
INTRODUCTION
• By default, STM32CubeIDE does not
provide a built-in option specifically for
writing assembly programs.
• However, it is still possible to write, build,
debug, and upload assembly code to a
targeted board in STM32CubeIDE by
following a few steps.
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, go to the Core
folder and locate a Src sub-folder:
Delete main.c file
Right click the Src folder and select >
New > File and name it (e.g.,
my_assembly.s). Ensure the file
extension is .s for assembly
language.
STEP 4: Add a Library in the Src folder
• Create a new file and name the file
STM32Fxxx.s
• Copy and paste these library codes to the
STM32Fxxx.s file. Save the file.
• The STM32Fxxx.s page can be closed.
STEP 5: Code Structure for my_assembly.s
• Write the following basic structure:
.cpu cortex-m4 // Set CPU to Cortex-M4
.thumb // Enable Thumb mode (uses Thumb-2 for Cortex-M4)
.syntax unified // Use unified syntax for compatibility
// assembler directives as necessary. Normally just:
.section .text
.global main
main:
// Configuration codes
loop:
// Your codes
THE END