Lesson 49 of 50
cCross‑Compilation – Building for Embedded Targets
13 mins
Course progress98%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 49 of 50
c13 mins
Keep these ideas in mind as you work through the lesson.
Cross‑compilation allows you to build a binary on a host machine for a different architecture (e.g., ARM Cortex‑M, AVR).
Typical toolchain prefix: arm-none-eabi- or avr-.
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O2 -c main.c -o main.o
arm-none-eabi-ld -T stm32.ld main.o -o firmware.elf
arm-none-eabi-objcopy -O binary firmware.elf firmware.bin
Key steps:
*-gcc)..ld) to place sections (.text, .data, .bss) at correct addresses.Reset_Handler).openocd or vendor‑specific utilities.CC=avr-gcc
CFLAGS=-mmcu=atmega328p -Os -Wall
OBJ=main.o
all: main.hex
main.elf: $(OBJ)
$(CC) $(CFLAGS) -o $@ $^
main.hex: main.elf
avr-objcopy -O ihex -R .eeprom $< $@
clean:
rm -f *.o *.elf *.hex