forked from fishpepper/OpenGround
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.board
142 lines (107 loc) · 3.9 KB
/
Makefile.board
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# object files
SYSTEM_SRCS = system_stm32f0xx.c
DRIVER_SRCS = stm32f0xx_gpio.c stm32f0xx_rcc.c stm32f0xx_adc.c stm32f0xx_dma.c stm32f0xx_tim.c stm32f0xx_i2c.c
DRIVER_SRCS += stm32f0xx_exti.c stm32f0xx_syscfg.c stm32f0xx_misc.c stm32f0xx_spi.c stm32f0xx_iwdg.c stm32f0xx_flash.c
EXTERNAL_SRCS = st_eeprom.c
BOARD_SRCS = $(GENERIC_SRCS)
BOARD_SRCS += $(SYSTEM_SRCS:%.c=device/%.c)
BOARD_SRCS += $(DRIVER_SRCS:%.c=peripheral_lib/src/%.c)
BOARD_SRCS += $(EXTERNAL_SRCS:%.c=peripheral_lib/eeprom_emulation/src/%.c)
DFU_UTIL ?= dfu-util
#crystal frequency
CRYSTAL_FREQ = 12000000
#name of executable
RESULT ?= openground
#faster build
#MAKEFLAGS+="-j6 "
# include path
CFLAGS += -I./
# Tool path, only override if not set
TOOLROOT ?= /usr/bin
# Tools
CC=$(TOOLROOT)/arm-none-eabi-gcc
LD=$(TOOLROOT)/arm-none-eabi-gcc
AR=$(TOOLROOT)/arm-none-eabi-ar
AS=$(TOOLROOT)/arm-none-eabi-as
SIZE=$(TOOLROOT)/arm-none-eabi-size
OBJ=$(TOOLROOT)/arm-none-eabi-objcopy
OBJDUMP=$(TOOLROOT)/arm-none-eabi-objdump
# Code Paths
DEVICE=device
CORE =core
LINK =linker
PERIPH=peripheral_lib
# Search path for standard files
vpath %.c ./
vpath %.c $(SELF_DIR)
# Search path for peripheral library
vpath %.c $(CORE)
vpath %.c $(PERIPH)/src
vpath %.c $(PERIPH)/eeprom_emulation/src
vpath %.c $(DEVICE)
vpath %.s $(DEVICE)
# Processor specific
PTYPE = STM32F072
LDSCRIPT = $(LINK)/STM32F072VB_FLASH.ld
STARTUP = device/startup_stm32f072.s
STARTUP_OBJS=$(STARTUP:%.s=%.o)
# Compilation Flags
FULLASSERT = -DUSE_FULL_ASSERT
LDFLAGS+= -T$(LDSCRIPT) -mthumb -mcpu=cortex-m0
CFLAGS+= -mcpu=cortex-m0 -mthumb -Wl,-Map,$(RESULT).map
CFLAGS+= -DHSE_VALUE=$(CRYSTAL_FREQ)
CFLAGS+= -I$(DEVICE) -I$(CORE) -I$(PERIPH)/inc -I$(PERIPH)/eeprom_emulation/inc -I./src
CFLAGS+= -D$(PTYPE) -DUSE_STDPERIPH_DRIVER $(FULLASSERT) -DBUILD_TARGET=$(TARGET)
OPENOCD_PIDFILE = /tmp/openocd_opensky.pid
LINK_OBJS=$(BOARD_SRCS:%.c=%.o)
HEADER_FILES = $(wildcard $(SELF_DIR)/*.h)
HEADER_FILES += $(wildcard src/*.h)
# Build executable
board: size stylecheck $(RESULT).elf
$(STARTUP_OBJS): $(STARTUP)
$(AS) -I $(DEVICE) -o $@ $<
$(RESULT).elf: $(LINK_OBJS) $(STARTUP_OBJS)
@echo $(LINK_OBJS)
@echo prereqs that are newer than test: $?
$(LD) $(LDFLAGS) -o $@ $(LINK_OBJS) $(STARTUP_OBJS) $(LDLIBS) --specs=nosys.specs
$(OBJDUMP) -D $(RESULT).elf > $(RESULT).lst
%.bin: %.elf
$(OBJ) -O binary $< $@
# pull in dependencies
# this includes all .d files produced along when building .o.
# On the first build there are not going to be any .d files.
# Hence, ignore include errors with -.
ALL_DEPS := $(patsubst %.c,%.d,$(BOARD_SRCS))
-include $(ALL_DEPS)
src/hoptable.h:
python ./scripts/generate_hoptable.py > src/hoptable.h
# compile and generate dependency info
%.o: %.c $(HEADER_FILES) src/hoptable.h
$(CC) -c $(CFLAGS) $< -o $@
$(CC) -MM -MP $(CFLAGS) $< > [email protected]
%.o: %.s
$(CC) -c $(CFLAGS) $(DEPFLAGS) $< -o $@
stylecheck: $(HEADER_FILES) $(GENERIC_SRCS)
./stylecheck/cpplint.py --filter=-build/include,-build/storage_class,-readability/casting,-runtime/arrays --extensions="h,c" --root=src --linelength=100 $(HEADER_FILES) $(GENERIC_SRCS) || true
size: $(RESULT).elf
@echo
@echo Memory usage:
@$(SIZE) $(RESULT).elf
@echo
clean:
rm -f src/*.o src/*.d *.o *.d $(RESULT).elf $(RESULT).bin
debug: $(RESULT).elf
openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg & echo $$! > $(OPENOCD_PIDFILE)
sleep 1
arm-none-eabi-gdb --eval-command="target remote localhost:3333" $(RESULT).elf
if [ -a $(OPENOCD_PIDFILE) ]; then kill `cat $(OPENOCD_PIDFILE)`; fi;
erase :
st-flash erase
flasherase : erase flash
flash : $(RESULT).bin
#if [ -a $(OPENOCD_PIDFILE) ]; then kill `cat $(OPENOCD_PIDFILE)`; fi;
#st-flash write $(RESULT).bin 0x8000000
st-flash --reset write $(RESULT).bin 0x8000000
dfu : $(RESULT).bin
$(DFU_UTIL) -a 0 -D $(RESULT).bin -s 0x08000000:leave -R
.PHONY: board clean flash debug flasherase stylecheck size