Setup Environment
π Installation
π§© 1. Install Arm GNU Toolchain
SourceοΌ π Arm Developer β GNU Arm Embedded Toolchain
β Version Suggestion (Windows)
Windows x86_64 hosted cross compiler for Arm Cortex-M and Cortex-R processors (bare-metal target)
choose .exe, and tick
add to env pathafter installation completed.
π§ 2. CMD
| CMD | Function | Note |
| ββββββββ | βββββ- | βββββββ |
| arm-none-eabi-gcc | C/C++ Compiler | For ARM Cortex-M (baremetal) |
| arm-none-eabi-as | assembler | .s file |
| arm-none-eabi-ld | linker | linker script |
| arm-none-eabi-objcopy | ELF β BIN/HEX | Build Programmable file |
| arm-none-eabi-size | Display section size | text/data/bss size |
| arm-none-eabi-gdb | Debugger | Connect ST-LINK/OpenOCD |
π§βπ» 3. Simple Code Example
A minimal bareβmetal template targeting STM32F072 (CortexβM0). No HAL, no CMSIS pack required.
128 KB Flash and 16 KB RAM (STM32F072VBT6).
π Directory layout
STM32_baremetal/
ββ inc/
β ββ device.h
ββ src/
β ββ main.c
β ββ startup_stm32f072.s
ββ linker.ld
ββ Makefile
π 4. Makefile
# === Makefile (part A) ===
# Toolchain (bareβmetal ARM)
CC := arm-none-eabi-gcc
OBJCOPY := arm-none-eabi-objcopy
OBJDUMP := arm-none-eabi-objdump
SIZE := arm-none-eabi-size
# Target CPU: CortexβM0 (STM32F072)
MCUFLAGS := -mcpu=cortex-m0 -mthumb -mfloat-abi=soft
# Common compile options (no stdlib; freestanding)
CFLAGS := $(MCUFLAGS) -O0 -g3 -ffreestanding -fno-builtin -Wall -Wextra -Werror
ASFLAGS := $(MCUFLAGS) -g3
LDFLAGS := $(MCUFLAGS) -Wl,-Map=build.map -nostartfiles -Wl,--gc-sections -T linker.ld
# Include path (we will add headers later)
INCLUDES := -Iinc
# For now, do NOT add build rules. We will append them after.
# Try: `make` now β it should fail with "No rule to make target" (expected).
choose .exe, and tick