-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
67 lines (52 loc) · 1.63 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
FW_VER=3
TOOLCHAIN_DIR ?= ./libopencm3
PREFIX = arm-none-eabi
CC = $(PREFIX)-gcc
LD = $(PREFIX)-gcc
SIZE = $(PREFIX)-size
GDB = $(PREFIX)-gdb
OBJCOPY = $(PREFIX)-objcopy
OOCD = openocd
LDSCRIPT = stm32-mcv4.ld
OOCD_BOARD = oocd/mcv4.cfg
CFLAGS += -mcpu=cortex-m3 -mthumb -msoft-float -DSTM32F1 \
-Wall -Wextra -O0 -std=gnu99 -g -fno-common \
-I$(TOOLCHAIN_DIR)/include -DFW_VER=$(FW_VER)
LDFLAGS += -lc -lm -L$(TOOLCHAIN_DIR)/lib/thumb/cortex-m3 -L$(TOOLCHAIN_DIR)/lib \
-L$(TOOLCHAIN_DIR)/lib/stm32/f1 -lnosys -T$(LDSCRIPT) \
-nostartfiles -Wl,--gc-sections,-Map=mcv4.map -mcpu=cortex-m3 \
-mthumb -march=armv7-m -mfix-cortex-m3-ldrd -msoft-float
O_FILES = main.o led.o output.o usart.o analogue.o fw_ver.o
TEST_O_FILES = test.o led.o output.o
all: mcv4.bin mcv4_test.bin
test: mcv4_test.bin
include depend
mcv4.elf: $(O_FILES) $(LD_SCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f1.a
$(LD) -o $@ $(O_FILES) $(LDFLAGS) -lopencm3_stm32f1
$(SIZE) $@
mcv4_test.elf: $(TEST_O_FILES) $(LD_SCRIPT) $(TOOLCHAIN_DIR)/lib/libopencm3_stm32f1.a
$(LD) -o $@ $(TEST_O_FILES) $(LDFLAGS) -lopencm3_stm32f1
$(SIZE) $@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
depend: *.c
rm -f depend
for file in $^; do \
$(CC) $(CFLAGS) -MM $$file -o - >> $@ ; \
done ;
.PHONY: all test clean flash
flash: mcv4.elf
$(OOCD) -f "$(OOCD_BOARD)" \
-c "init" \
-c "reset init" \
-c "stm32f1x mass_erase 0" \
-c "flash write_image $<" \
-c "reset" \
-c "shutdown"
debug: mcv4.elf
$(OOCD) -f "$(OOCD_BOARD)" \
-c "init" \
# -c "reset halt" &
$(GDB) mcv4.elf
clean:
-rm -f mcv4.elf depend *.o