-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
205 lines (166 loc) · 7.69 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#****************************************************************************
#*
#* (C) 2023 Andrii Bilynskyi <[email protected]>
#*
#* This code is licensed under the MIT.
#*
#****************************************************************************
TOOLCHAIN_PATH := /opt/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi
CC := ${TOOLCHAIN_PATH}/bin/arm-none-eabi-gcc
CXX := ${TOOLCHAIN_PATH}/bin/arm-none-eabi-g++
AS := ${TOOLCHAIN_PATH}/bin/arm-none-eabi-gcc
LD := ${TOOLCHAIN_PATH}/bin/arm-none-eabi-ld
OBJCPY := ${TOOLCHAIN_PATH}/bin/arm-none-eabi-objcopy
SIZE := ${TOOLCHAIN_PATH}/bin/arm-none-eabi-size
GDB := ${TOOLCHAIN_PATH}/bin/arm-none-eabi-gdb
PROJECT ?= stm32-bl
PROJECT_CSRC := \
${wildcard stm/*.c} \
${wildcard stm/*.s} \
${wildcard stm/STM32F10x_StdPeriph_Driver/src/*.c} \
${wildcard stm/STM32_USB-FS-Device_Driver/src/*.c} \
${wildcard FreeRTOS-Plus-CLI/*.c} \
${wildcard tiny-AES-c/*.c} \
${wildcard hex_parser/*.c} \
${wildcard src/usb/*.c} \
${wildcard src/*.c} \
${wildcard src/*.cpp} \
${wildcard keys/*.bin} \
INCLUDE_PATH := \
cm \
stm \
stm/STM32F10x_StdPeriph_Driver/inc \
stm/STM32_USB-FS-Device_Driver/inc \
FreeRTOS-Plus-CLI \
tiny-AES-c \
hex_parser \
config \
config/stubs \
src/usb \
src \
PROJECT_STYLE := \
${wildcard src/*.[ch]} ${wildcard src/*.cpp} \
${wildcard src/usb/*.[ch]} \
${wildcard hex_parser/*.[ch]} \
${wildcard encrypter/*.[ch]} \
${wildcard test_app/*.[ch]} \
${wildcard config/*.[ch]} \
${wildcard config/stubs/*.[ch]} \
LDLIBS := \
stdc++ \
LD_SCRIPT := linker/stm32_flash.ld
OBJECTS := ${addsuffix .o, ${PROJECT_CSRC}}
CFLAGS := -Wall -std=c99 -fdata-sections -ffunction-sections
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3
CFLAGS += -DSTM32F10X_MD -DHSE_VALUE=8000000u -DUSE_STDPERIPH_DRIVER
ASFLAGS := -Wall -std=c99
ASFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3
ASFLAGS += -DSTM32F10X_MD -DHSE_VALUE=8000000u -DUSE_STDPERIPH_DRIVER
CXXFLAGS := -Wall -fno-exceptions -fdata-sections -ffunction-sections
CXXFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3
CXXFLAGS += -DSTM32F10X_MD -DHSE_VALUE=8000000u -DUSE_STDPERIPH_DRIVER
LDFLAGS := -T${LD_SCRIPT}
LDFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Xlinker -Map=${PROJECT}.map
LDFLAGS += ${addprefix -l, ${LDLIBS}}
BINFLAGS := -r -b binary
ifndef BUILD
BUILD := RELEASE
endif
ifeq ($(BUILD),DEBUG)
CFLAGS += -g3 -O1 -DUSE_FULL_ASSERT -DDEBUG
ASFLAGS += -g3 -O1 -DUSE_FULL_ASSERT -DDEBUG
CXXFLAGS += -g3 -O1 -DUSE_FULL_ASSERT -DDEBUG
LDFLAGS += --specs=rdimon.specs
else ifeq ($(BUILD),RELEASE)
CFLAGS += -g0 -Os
ASFLAGS += -g0 -Os
CXXFLAGS += -g0 -Os
LDFLAGS += --specs=nosys.specs
else
$(error Wrong BUILD '$(BUILD)'! Should be: DEBUG or RELEASE)
endif
CFLAGS += ${addprefix -I, ${INCLUDE_PATH}}
CXXFLAGS += ${addprefix -I, ${INCLUDE_PATH}}
.PHONY: all build clean flash erase debug check style help
all: ${PROJECT}.elf
build: ${PROJECT}.elf
${PROJECT}.elf: ${OBJECTS}
$(info $(BUILD) BUILD)
${CC} $^ -o $@ ${LDFLAGS}
${OBJCPY} -O ihex $@ ${PROJECT}.hex
${SIZE} --format=berkeley $@
%.c.o: %.c
${CC} ${CFLAGS} -MD -c $< -o $@
%.s.o: %.s
${CC} ${ASFLAGS} -MD -c $< -o $@
%.cpp.o: %.cpp
${CXX} ${CXXFLAGS} -MD -c $< -o $@
%.bin.o: %.bin
${LD} ${BINFLAGS} $< -o $@
clean:
rm -f ${OBJECTS} $(OBJECTS:.o=.d) ${PROJECT}.elf ${PROJECT}.hex ${PROJECT}.map
flash:
@if [ -f "${PROJECT}.hex" ] ; \
then \
openocd -f openocd/jlink.cfg -f openocd/stm32f1x.cfg \
-c "init" \
-c "reset init" \
-c "flash write_image erase $(PROJECT).hex" \
-c "reset" \
-c "shutdown"; \
else \
echo "Output .hex file doesn't exist. Run 'make all' before!"; \
fi \
erase:
openocd -f openocd/jlink.cfg -f openocd/stm32f1x.cfg \
-c "init" \
-c "reset init" \
-c "flash protect 0 0 15 off" \
-c "stm32f1x unlock 0" \
-c "reset halt" \
-c "reset init" \
-c "stm32f1x mass_erase 0" \
-c "reset" \
-c "shutdown"; \
debug:
@if [ -f "${PROJECT}.elf" ] ; \
then \
openocd -f openocd/jlink.cfg -f openocd/stm32f1x.cfg & \
ddd "${PROJECT}.elf" --debugger "${GDB} -ex 'target extended-remote :3333' \
-ex 'monitor arm semihosting enable'\
-ex 'monitor reset halt' \
-ex 'load' \
-ex 'monitor reset halt'"; \
kill -9 $$!; \
else \
echo "Output .elf file doesn't exist. Run 'make all' before!"; \
fi \
check:
cppcheck -q --enable=style,performance,portability,information \
--force --inconclusive --inline-suppr ${PROJECT_STYLE} \
--suppress=missingInclude --suppress=ConfigurationNotChecked \
style:
astyle --style=linux --convert-tabs --lineend=linux --suffix=none \
--indent=spaces=4 \
--max-code-length=100 --delete-empty-lines --add-braces \
--unpad-paren --pad-oper --pad-comma --pad-header \
--align-pointer=name --align-reference=name \
${PROJECT_STYLE} \
help:
$(info Help)
$(info ---------------------------------------------------------------------)
$(info make help - this help text)
$(info make BUILD=<build_type> build - create binary files (.elf, .hex))
$(info make BUILD=<build_type> all - create binary files (.elf, .hex). same as build)
$(info make clean - remove generated files)
$(info make flash - flash target)
$(info make erase - flash erase)
$(info make debug - start debugging session DDD(gdb))
$(info make check - static analyse (cppcheck))
$(info make style - format sources (asyle))
$(info ---------------------------------------------------------------------)
$(info Available build_type [DEBUG RELEASE], eg: make BUILD=RELEASE ...)
$(info Default build_type DEBUG)
-include $(OBJECTS:.o=.d)