
Cross-Compile Zig for a Cortex-M Target With build.zig
Write a build.zig that targets thumb-freestanding for a Cortex-M4, add a linker script and vector table, and produce a flashable ELF and binary with Zig 0.14.
Tag
20 posts

Write a build.zig that targets thumb-freestanding for a Cortex-M4, add a linker script and vector table, and produce a flashable ELF and binary with Zig 0.14.

Write two GNU linker scripts that share one flash layout file, split flash between bootloader and application, and fail the build when either region overflows.

Hand control from a bootloader to a Cortex-M application safely: validate the vector table, quiesce peripherals, set VTOR and MSP, and avoid the usual crashes.

Replace a busy main loop with __WFI so a Cortex-M sleeps until the next interrupt, and close the lost-wakeup race with a PRIMASK guard.

Sleep, Stop and Standby are the three usual low-power modes on a Cortex-M microcontroller. Learn what each one turns off, what it keeps and how it wakes.

Follow a FreeRTOS context switch on Cortex-M4F from the yield request to the PendSV handler, and see which registers hardware stacks and which software saves.

Copy .data from flash and zero .bss in a Cortex-M reset handler without bugs: alignment, the memset trap, empty sections and a debugger check to run.

Write a complete GNU ld linker script for an STM32F407: MEMORY regions, vector table, .text, .data with AT>, .bss, heap and stack reserve, and link-time checks.

Replace the vendor assembly startup file with one C file for a Cortex-M4: vector table, weak aliases, data copy, bss clear and the GCC flags that keep it safe.

Learn the Cortex-M vector table layout: system entries, device IRQs, the Thumb bit, how VTOR finds the table, and why it must sit at the start of flash.

Follow a Cortex-M core from power-on to main: the two vector table words it fetches, the reset handler, and the C runtime setup that runs before your code.

The AAPCS rules for 32-bit ARM and Cortex-M: argument and result registers, what a callee must preserve, 64-bit pairs, stack alignment and hard-float.