forked from Laurenceb/STM32-Logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
184 lines (137 loc) · 4.88 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Compile the project
# Uncomment the appropriate device type and startup file
#DEVICE_TYPE = STM32F10X_LD
#STARTUP_FILE = stm32f10x_ld
DEVICE_TYPE = STM32F10X_MD
STARTUP_FILE = stm32f10x_md
#DEVICE_TYPE = STM32F10X_HD
#STARTUP_FILE = stm32f10x_hd
#DEVICE_TYPE = STM32F10X_CL
#STARTUP_FILE = stm32f10x_cl
# Set the external clock frequency
HSE_VALUE = 12000000UL
# Enable debug compilation
DEBUG = 1
# [OPTIONAL] Set the serial details for bootloading
STM32LDR_PORT = /dev/rfcomm0
STM32LDR_BAUD = 115200
# [OPTIONAL] Comment out to disable bootloader verification
STM32LDR_VERIFY = -v
# [OPTIONAL] Uncomment to use the firmware library
FWLIB = lib/STM32F10x_StdPeriph_Driver/libstm32fw.a
# [OPTIONAL] Uncomment to use the USB library
USBLIB = lib/STM32_USB-FS-Device_Driver/libstm32usb.a
# [OPTIONAL] Uncomment to link to maths library libm
LIBM = -lm
export DEBUG
export MESSAGES
TARGET_ARCH = -mcpu=cortex-m3 -mthumb
INCLUDE_DIRS = -I . -I lib/STM32F10x_StdPeriph_Driver/inc\
-I lib/CMSIS_CM3 -I lib/STM32F10x_StdPeriph_Driver\
-I lib/STM32_USB-FS-Device_Driver/inc -I Util -I Sensors -I Util/USB\
-I Util/fat_fs/inc
LIBRARY_DIRS = -L lib/STM32F10x_StdPeriph_Driver/\
-L lib/STM32_USB-FS-Device_Driver
DEFINES = -D$(DEVICE_TYPE) -DHSE_Value=$(HSE_VALUE) -DCRT -DBOARD=3#-DSYSCLK_FREQ_72MHz=72000000
COMPILE_OPTS = $(WARNINGS) $(TARGET_OPTS) $(MESSAGES) $(INCLUDE_DIRS) $(DEFINES)
WARNINGS = -Wall -W -Wshadow -Wcast-qual -Wwrite-strings -Winline
ifdef DEBUG
TARGET_OPTS = -O3 -g3
DEBUG_MACRO = -DDEBUG
else #Changed from O2 - optimisation split between control loop and rest of project, using a seperate makefile
TARGET_OPTS = $(OPTIMISE) -finline -finline-functions-called-once\
-funroll-loops -fno-common -fpromote-loop-indices -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections
endif
CC = ~/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-gcc #this project depends of the CodeSourcery toolchain, defining the exact path forces
CXX = ~/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-g++ #use of the correct toolchain
SIZE = ~/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-size
CFLAGS = -std=gnu99 $(COMPILE_OPTS)
CXXFLAGS = $(COMPILE_OPTS)
AS = $(CC) -x assembler-with-cpp -c $(TARGET_ARCH)
ASFLAGS = $(COMPILE_OPTS)
LD = $(CC)
LDFLAGS = -Wl,--gc-sections,-Map=$(MAIN_MAP),-cref -T lanchon-stm32.ld -L lib\
$(INCLUDE_DIRS) $(LIBRARY_DIRS) $(LIBM) -ffunction-sections #-lstdc++
AR = arm-none-eabi-ar
ARFLAGS = cr
OBJCOPY = arm-none-eabi-objcopy
OBJCOPYFLAGS = -O binary
STARTUP_OBJ = lib/CMSIS_CM3/startup/gcc/startup_$(STARTUP_FILE).o
MAIN_OUT = main.elf
MAIN_MAP = $(MAIN_OUT:%.elf=%.map)
MAIN_BIN = $(MAIN_OUT:%.elf=%.bin)
MAIN_OBJS = $(sort \
$(patsubst %.cpp,%.o,$(wildcard *.cpp)) \
$(patsubst %.cc,%.o,$(wildcard *.cc)) \
$(patsubst %.c,%.o,$(wildcard *.c)) \
$(patsubst %.s,%.o,$(wildcard *.s)) \
$(patsubst %.c,%.o,$(wildcard lib/CMSIS_CM3/*.c)) \
$(patsubst %.c,%.o,$(wildcard Util/*.c)) \
$(patsubst %.c,%.o,$(wildcard Util/USB/*.c)) \
$(patsubst %.c,%.o,$(wildcard Util/fat_fs/src/*.c)) \
$(patsubst %.c,%.o,$(wildcard Util/fat_fs/option/ccsbcs.c)) \
$(patsubst %.c,%.o,$(wildcard Sensors/*.c)) \
$(STARTUP_OBJ))
CONTROL_OBJS = $(sort $(patsubst %.c,%.o,$(wildcard Control/*.c)))
#optimisation
$(MAIN_OBJS): OPTIMISE= -Os
$(CONTROL_OBJS): OPTIMISE= -Os
#all - output the size from the elf
.PHONY: all
all: $(MAIN_BIN)
$(SIZE) $(MAIN_OUT)
# main
$(MAIN_OUT): $(MAIN_OBJS) $(CONTROL_OBJS) $(FWLIB) $(USBLIB)
$(LD) $(TARGET_ARCH) $^ -o $@ $(LDFLAGS)
$(MAIN_OBJS): $(wildcard *.h) $(wildcard lib/STM32F10x_StdPeriph_Driver/*.h)\
$(wildcard lib/STM32F10x_StdPeriph_Driver/inc/*.h)\
$(wildcard lib/CMSIS_CM3/*.h)\
$(wildcard Util*.h)\
$(wildcard Util/USB*.h)\
$(wildcard Util/fat_fs/inc/*.h)\
$(wildcard Sensors*.h)
$(MAIN_BIN): $(MAIN_OUT)
$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
# fwlib
.PHONY: fwlib
fwlib: $(FWLIB)
$(FWLIB): $(wildcard lib/STM32F10x_StdPeriph_Driver/*.h)\
$(wildcard lib/STM32F10x_StdPeriph_Driver/inc/*.h)
@cd lib/STM32F10x_StdPeriph_Driver && $(MAKE)
# usblib
.PHONY: usblib
usblib: $(USBLIB)
$(USBLIB): $(wildcard lib/STM32_USB-FS-Device_Driver/inc*.h)
@cd lib/STM32_USB-FS-Device_Driver && $(MAKE)
#size
.PHONY: size
size: all
@echo "Size:"
$(SIZE) $(MAIN_OUT) $@
@$(CAT) $@
# flash
.PHONY: flash
flash: flash-elf
#flash: flash-bin
.PHONY: flash-elf
flash-elf: all
@cp $(MAIN_OUT) jtag/flash.elf
@cd jtag && openocd -f flash-elf.cfg
@rm jtag/flash.elf
.PHONY: flash-bin
flash-bin: all
@cp $(MAIN_BIN) jtag/flash.bin
@cd jtag && openocd -f flash-bin.cfg
@rm jtag/flash.bin
.PHONY: upload
upload: all
@python jtag/stm32loader.py -p $(STM32LDR_PORT) -b $(STM32LDR_BAUD)\
-e $(STM32LDR_VERIFY) -w main.bin
# clean
.PHONY: clean
clean:
-rm -f $(MAIN_OBJS) $(MAIN_OUT) $(MAIN_MAP) $(MAIN_BIN)
-rm -f $(CONTROL_OBJS)
-rm -f jtag/flash.elf jtag/flash.bin
@cd lib/STM32F10x_StdPeriph_Driver && $(MAKE) clean
@cd lib/STM32_USB-FS-Device_Driver && $(MAKE) clean