2573 |
povik |
1 |
BINARY = rtdriver |
|
|
2 |
OBJS = obj/rtdriver.o |
|
|
3 |
|
|
|
4 |
PREFIX ?= arm-none-eabi |
|
|
5 |
CC = $(PREFIX)-gcc |
|
|
6 |
LD = $(PREFIX)-gcc |
|
|
7 |
OBJCOPY = $(PREFIX)-objcopy |
|
|
8 |
OBJDUMP = $(PREFIX)-objdump |
|
|
9 |
GDB = $(PREFIX)-gdb |
|
|
10 |
|
|
|
11 |
TOOLCHAIN_DIR = `dirname \`which $(CC)\``/../$(PREFIX) |
|
|
12 |
|
|
|
13 |
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float |
|
|
14 |
CFLAGS += -Os -g -Wall -Wextra -I inc -I$(TOOLCHAIN_DIR)/include \ |
|
|
15 |
-fno-common $(ARCH_FLAGS) -MD -DSTM32F1 |
|
|
16 |
LDSCRIPT = linker.ld |
|
|
17 |
LDFLAGS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ |
|
|
18 |
-L$(TOOLCHAIN_DIR)/lib/stm32/f1/ \ |
|
|
19 |
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \ |
|
|
20 |
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd |
|
|
21 |
|
|
|
22 |
ifneq ($(V),1) |
|
|
23 |
Q := @ |
|
|
24 |
NULL := 2>/dev/null |
|
|
25 |
else |
|
|
26 |
LDFLAGS += -Wl,--print-gc-sections |
|
|
27 |
endif |
|
|
28 |
|
|
|
29 |
.SUFFIXES: .elf .bin .hex .srec .list .images |
|
|
30 |
.SECONDEXPANSION: |
|
|
31 |
.SECONDARY: |
|
|
32 |
|
|
|
33 |
all: images |
|
|
34 |
|
|
|
35 |
gdb: images |
|
|
36 |
$(GDB) bin/$(BINARY).elf |
|
|
37 |
|
|
|
38 |
upload: images |
|
|
39 |
stm32flash -k -w bin/$(BINARY).bin /dev/ttyUSB0 |
|
|
40 |
|
|
|
41 |
images: $(OBJS) bin/$(BINARY).elf bin/$(BINARY).bin bin/$(BINARY).hex bin/$(BINARY).srec bin/$(BINARY).list |
|
|
42 |
|
|
|
43 |
bin/%.bin: bin/%.elf |
|
|
44 |
@echo " OBJCOPY $@" |
|
|
45 |
$(Q)$(OBJCOPY) -Obinary $< $@ |
|
|
46 |
|
|
|
47 |
bin/%.hex: bin/%.elf |
|
|
48 |
@echo " OBJCOPY $@" |
|
|
49 |
$(Q)$(OBJCOPY) -Oihex $< $@ |
|
|
50 |
|
|
|
51 |
bin/%.srec: bin/%.elf |
|
|
52 |
@echo " OBJCOPY $@" |
|
|
53 |
$(Q)$(OBJCOPY) -Osrec $< $@ |
|
|
54 |
|
|
|
55 |
bin/%.list: bin/%.elf |
|
|
56 |
@echo " OBJDUMP $@" |
|
|
57 |
$(Q)$(OBJDUMP) -S $< > $@ |
|
|
58 |
|
|
|
59 |
bin/%.elf: $(OBJS) $(LDSCRIPT) |
|
|
60 |
@echo " LD $@" |
|
|
61 |
$(Q)$(LD) -o $@ $(OBJS) -lopencm3_stm32f1 $(LDFLAGS) |
|
|
62 |
|
|
|
63 |
|
|
|
64 |
obj/%.o: src/%.c Makefile |
|
|
65 |
@echo " CC $@" |
|
|
66 |
$(Q)$(CC) $(CFLAGS) -o $@ -c $< |
|
|
67 |
|
|
|
68 |
|
|
|
69 |
obj/%.o: src/%.s Makefile |
|
|
70 |
@echo " ASM $@" |
|
|
71 |
$(Q)$(CC) $(CFLAGS) -o $@ -c $< |
|
|
72 |
|
|
|
73 |
clean: |
|
|
74 |
$(Q)rm -f obj/* |
|
|
75 |
$(Q)rm -f bin/* |
|
|
76 |
|
|
|
77 |
.PHONY: all clean images upload gdb |