mk450: x and y axis basic implementation
[cortex-from-scratch] / Makefile
index d7e1652..3eb5eed 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,17 +10,36 @@ AS=arm-none-eabi-as
 MKIMG=arm-none-eabi-objcopy
 
 # Compiler flags
-# TODO:Cortex-m3 or Cortex-m0?
 LDFLAGS+= -mthumb -mcpu=cortex-m3 
 ASFLAGS+= -mcpu=cortex-m3 -mthumb -g
 CFLAGS+= -mcpu=cortex-m3 -mthumb -g -ffreestanding 
 
+# Include directory
+INCLUDE+= -Iinclude 
+
+BIN = bin
+
 ODIR = obj
-_OBJ = main.o uart.o ivt.o systick.o sysinfo.o lib.o regf.o pool.o
+_OBJ = ivt.o systick.o sysinfo.o term.o main.o clock.o rtc.o 
 OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
 
+DDIR = obj/drivers
+_DRIVERS = uart.o tm1637.o led.o tsensor.o at24c.o mk450_joystick.o
+DRIVERS = $(patsubst %, $(DDIR)/%,$(_DRIVERS))
+
+LDIR = obj/lib
+_LIBS = string.o stdio.o regfunc.o pool.o tinyprintf.o 
+LIBS = $(patsubst %, $(LDIR)/%,$(_LIBS))
+
+$(DDIR)/%.o: drivers/%.c
+       @mkdir -p $(@D) 
+       $(CC) -c $< $(CFLAGS) $(INCLUDE) -o $@
+
+$(ODIR)/%.o: %.c 
+       @mkdir -p $(@D)
+       $(CC) -c $< $(CFLAGS) -I./include -o $@
 
-$(ODIR)/%.o: %.c $(DEPS)
+$(LDIR)/%.o: lib/%.c 
        @mkdir -p $(@D)
        $(CC) -c $< $(CFLAGS) -I./include -o $@
 
@@ -29,32 +48,33 @@ as:
        $(AS) $(ASFLAGS) -o start.o start.asm
 
 # Compile and link all
-kernel: $(OBJ)
+kernel: $(OBJ) $(DRIVERS) $(LIBS) 
        $(AS) $(ASFLAGS) -o start.o start.asm
-       $(LD) -nostartfiles -Map $@.MAP -T link.ld -o $@.ELF start.o $^ --print-memory-usage
+       $(LD) -nostartfiles -Map $(BIN)/$@.MAP -T link.ld -o $(BIN)/$@.ELF start.o $^ --print-memory-usage
        @echo "Creating binary..."
-       $(MKIMG) -Obinary -R .data $@.ELF $@.bin
+       @mkdir -p $(BIN)
+       $(MKIMG) -Obinary -R .data $(BIN)/$@.ELF  $(BIN)/$@.bin
 
 # Run in Qemu; note this is a patched version for stm32-f103c8
 run:
-       /usr/local/bin/qemu-system-arm -serial stdio  -M stm32-f103c8 -kernel kernel.bin
+       /usr/local/bin/qemu-system-arm -serial stdio  -M stm32-f103c8 -kernel $(BIN)/kernel.bin
 
 # Examine all sections
 examine-all:
-       arm-none-eabi-objdump -D kernel.ELF | less
+       arm-none-eabi-objdump -D $(BIN)/kernel.ELF | less
 
 # Examine just headers
 examine-header:
-       arm-none-eabi-objdump -x kernel.ELF | less
+       arm-none-eabi-objdump -x $(BIN)/kernel.ELF | less
 
 # Flash kernel to board
 flash:
-       stm32flash -w kernel.bin -v /dev/ttyUSB0
+       stm32flash -w $(BIN)/kernel.bin -v /dev/ttyUSB0
 
 .PHONY: clean
 
 clean:
-       rm -rf $(ODIR)/*.o start.o kernel.*
+       rm -rf $(ODIR)/* start.o $(BIN)/kernel.*
 
 # Altijd handig deze template
 #%.o: %.c