πŸ“Œ 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) alt text choose .exe, and tick add to env path after 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).