1 # Copyright 2019 - Robin Krens
3 # TODO: Somehow integrate this assembly start.asm (start.o)
6 # Cross compilers links
10 MKIMG=arm-none-eabi-objcopy
13 # TODO:Cortex-m3 or Cortex-m0?
14 LDFLAGS+= -mthumb -mcpu=cortex-m3
15 ASFLAGS+= -mcpu=cortex-m3 -mthumb -g
16 CFLAGS+= -mcpu=cortex-m3 -mthumb -g -ffreestanding
19 _OBJ = main.o uart.o ivt.o systick.o sysinfo.o lib.o regf.o pool.o
20 OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
23 $(ODIR)/%.o: %.c $(DEPS)
25 $(CC) -c $< $(CFLAGS) -I./include -o $@
27 # Start up machine assembly
29 $(AS) $(ASFLAGS) -o start.o start.asm
31 # Compile and link all
33 $(AS) $(ASFLAGS) -o start.o start.asm
34 $(LD) -nostartfiles -Map $@.MAP -T link.ld -o $@.ELF start.o $^ --print-memory-usage
35 @echo "Creating binary..."
36 $(MKIMG) -Obinary -R .data $@.ELF $@.bin
38 # Run in Qemu; note this is a patched version for stm32-f103c8
40 /usr/local/bin/qemu-system-arm -serial stdio -M stm32-f103c8 -kernel kernel.bin
42 # Examine all sections
44 arm-none-eabi-objdump -D kernel.ELF | less
46 # Examine just headers
48 arm-none-eabi-objdump -x kernel.ELF | less
50 # Flash kernel to board
52 stm32flash -w kernel.bin -v /dev/ttyUSB0
57 rm -rf $(ODIR)/*.o start.o kernel.*
59 # Altijd handig deze template
61 # $(CC) -c $(CFLAGS) $< -o $@
62 # $(CC) -MM $(CFLAGS) $< > $*.d
65 # $(CC) -c $(CFLAGS) $< -o $@