-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile.STM32FX
214 lines (182 loc) · 6.91 KB
/
Makefile.STM32FX
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
206
207
208
209
210
211
212
213
214
# STM32 library paths
F1_LIB_PATH=./STM32F10X_Platform
F4_LIB_PATH=./STM32F4XX_Platform
# MCU external clock frequency (Hz)
CLK_PI_F4=12000000
CLK_DEF=8000000
# Directory Structure
BINDIR=.
OBJDIR_F1=obj_f1
OBJDIR_F4=obj_f4
# Output files
BINELF_F1=dvm-firmware-hs_f1.elf
BINHEX_F1=dvm-firmware-hs_f1.hex
BINBIN_F1=dvm-firmware-hs_f1.bin
BINELF_F4=dvm-firwmare-hs_f4.elf
BINHEX_F4=dvm-firmware-hs_f4.hex
BINBIN_F4=dvm-firmware-hs_f4.bin
# Header directories
INC_F1= . $(F1_LIB_PATH)/CMSIS/ $(F1_LIB_PATH)/Device/ $(F1_LIB_PATH)/STM32F10x_StdPeriph_Driver/inc/ $(F1_LIB_PATH)/usb/inc/
INCLUDES_F1=$(INC_F1:%=-I%)
INC_F4= . $(F4_LIB_PATH)/CMSIS/Include/ $(F4_LIB_PATH)/Device/ $(F4_LIB_PATH)/STM32F4xx_StdPeriph_Driver/include/
INCLUDES_F4=$(INC_F4:%=-I%)
# CMSIS libraries
INCLUDES_LIBS_F1=
INCLUDES_LIBS_F4=$(F4_LIB_PATH)/CMSIS/Lib/GCC/libarm_cortexM4lf_math.a
# STM32F1 Standard Peripheral Libraries source path
STD_LIB_F1=$(F1_LIB_PATH)/STM32F10x_StdPeriph_Driver/src
# STM32F1 USB support source path
USB_F1=$(F1_LIB_PATH)/usb
# STM32F4 Standard Peripheral Libraries source path
STD_LIB_F4=$(F4_LIB_PATH)/STM32F4xx_StdPeriph_Driver/source
# STM32F1 system source path
SYS_DIR_F1=$(F1_LIB_PATH)/Device
STARTUP_DIR_F1=$(F1_LIB_PATH)/Device/startup
# STM32F4 system source path
SYS_DIR_F4=$(F4_LIB_PATH)/Device
STARTUP_DIR_F4=$(F4_LIB_PATH)/Device/startup
# GNU ARM Embedded Toolchain
CC=arm-none-eabi-gcc
CXX=arm-none-eabi-g++
LD=arm-none-eabi-ld
AR=arm-none-eabi-ar
AS=arm-none-eabi-as
CP=arm-none-eabi-objcopy
OD=arm-none-eabi-objdump
NM=arm-none-eabi-nm
SIZE=arm-none-eabi-size
A2L=arm-none-eabi-addr2line
# Default reference oscillator frequencies
ifndef $(OSC)
ifeq ($(MAKECMDGOALS),pi-f4)
OSC=$(CLK_PI_F4)
else
OSC=$(CLK_DEF)
endif
endif
# Build object lists
CXXSRC=$(wildcard ./*.cpp) $(wildcard ./dmr/*.cpp) $(wildcard ./p25/*.cpp) $(wildcard ./nxdn/*.cpp)
CSRC_STD_F1=$(wildcard $(STD_LIB_F1)/*.c)
SYS_F1=$(wildcard $(SYS_DIR_F1)/*.c)
STARTUP_F1=$(wildcard $(STARTUP_DIR_F1)/*.c)
CXX_USB_F1=$(wildcard $(USB_F1)/*.cpp)
C_USB_F1=$(wildcard $(USB_F1)/*.c)
CSRC_STD_F4=$(wildcard $(STD_LIB_F4)/*.c)
SYS_F4=$(wildcard $(SYS_DIR_F4)/*.c)
STARTUP_F4=$(wildcard $(STARTUP_DIR_F4)/*.c)
OBJ_F1=$(CXXSRC:./%.cpp=$(OBJDIR_F1)/%.o) $(CSRC_STD_F1:$(STD_LIB_F1)/%.c=$(OBJDIR_F1)/%.o) $(SYS_F1:$(SYS_DIR_F1)/%.c=$(OBJDIR_F1)/%.o) $(STARTUP_F1:$(STARTUP_DIR_F1)/%.c=$(OBJDIR_F1)/%.o)
OBJ_F4=$(CXXSRC:./%.cpp=$(OBJDIR_F4)/%.o) $(CSRC_STD_F4:$(STD_LIB_F4)/%.c=$(OBJDIR_F4)/%.o) $(SYS_F4:$(SYS_DIR_F4)/%.c=$(OBJDIR_F4)/%.o) $(STARTUP_F4:$(STARTUP_DIR_F4)/%.c=$(OBJDIR_F4)/%.o)
# MCU flags
MCFLAGS_F1=-mcpu=cortex-m3 -march=armv7-m -mthumb
MCFLAGS_F4=-mcpu=cortex-m4 -mthumb -mlittle-endian -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb-interwork
# Compile flags
DEFS_F1_HS=-DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -DHSE_VALUE=$(OSC) -DVECT_TAB_OFFSET=0x0 -DMADEBYMAKEFILE
# STM32F446 Pi-Hat board:
DEFS_PI_F4=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_PI -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
# STM32F4 Nucleo-64 F446RE board:
DEFS_F446=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
# Build compiler flags
CFLAGS_F1=-c $(MCFLAGS_F1) $(INCLUDES_F1)
CXXFLAGS_F1=-c $(MCFLAGS_F1) $(INCLUDES_F1)
CFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4)
CXXFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4)
# Linker flags
LDFLAGS_F1_N =-T stm32f10x_normal.ld $(MCFLAGS_F1) $(INCLUDES_LIBS_F1)
LDFLAGS_F1_D =-T stm32f10x_debug.ld $(MCFLAGS_F1) $(INCLUDES_LIBS_F1)
LDFLAGS_F4 =-T stm32f4xx_link.ld $(MCFLAGS_F4) $(INCLUDES_LIBS_F4)
LDFLAGS_F4_D =-T stm32f4xx_link_debug.ld $(MCFLAGS_F4) $(INCLUDES_LIBS_F4)
# Common flags
CFLAGS=-Os -g -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS
CXXFLAGS=-Os -g -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS
LDFLAGS=-Os -g --specs=nano.specs --specs=nosys.specs
# Build Rules
.PHONY: all release_f1 release_f4 hs pi-f4 f446 clean
all: hs
#error "Either PI_HAT_7021_REV_02, ZUMSPOT_ADF7021, LONESTAR_USB, MMDVM_HS_HAT_REV12, MMDVM_HS_DUAL_HAT_REV10, NANO_HOTSPOT, NANO_DV_REV11, or SKYBRIDGE_HS
zumspot-adf7021: CFLAGS+=-DZUMSPOT_ADF7021 -DSTM32_USART1_HOST
zumspot-adf7021: CXXFLAGS+=-DZUMSPOT_ADF7021 -DSTM32_USART1_HOST
zumspot-adf7021: hs
zumspot-adf7021-duplex: CFLAGS+=-DDUPLEX
zumspot-adf7021-duplex: CXXFLAGS+=-DDUPLEX
zumspot-adf7021-duplex: zumspot-adf7021
pihat-7021-r2: CFLAGS+=-DPI_HAT_7021_REV_02 -DSTM32_USART1_HOST
pihat-7021-r2: CXXFLAGS+=-DZUMSPOT_ADF7021 -DSTM32_USART1_HOST
pihat-7021-r2: hs
pihat-7021-r2-duplex: CFLAGS+=-DDUPLEX
pihat-7021-r2-duplex: CXXFLAGS+=-DDUPLEX
pihat-7021-r2-duplex: pihat-7021-r2
mmdvm-hs-hat: CFLAGS+=-DMMDVM_HS_HAT_REV12 -DSTM32_USART1_HOST
mmdvm-hs-hat: CXXFLAGS+=-DMMDVM_HS_HAT_REV12 -DSTM32_USART1_HOST
mmdvm-hs-hat: hs
mmdvm-hs-hat-debug: CFLAGS+=-DMMDVM_HS_HAT_REV12 -DSTM32_USART1_HOST
mmdvm-hs-hat-debug: CXXFLAGS+=-DMMDVM_HS_HAT_REV12 -DSTM32_USART1_HOST
mmdvm-hs-hat-debug: hs-debug
mmdvm-hs-hat-dual: CFLAGS+=-DDUPLEX
mmdvm-hs-hat-dual: CXXFLAGS+=-DDUPLEX
mmdvm-hs-hat-dual: mmdvm-hs-hat
mmdvm-hs-hat-dual-debug: CFLAGS+=-DDUPLEX
mmdvm-hs-hat-dual-debug: CXXFLAGS+=-DDUPLEX
mmdvm-hs-hat-dual-debug: mmdvm-hs-hat-debug
hs: CFLAGS+=$(CFLAGS_F1) $(DEFS_F1_HS)
hs: CXXFLAGS+=$(CXXFLAGS_F1) $(DEFS_F1_HS)
hs: LDFLAGS+=$(LDFLAGS_F1_N)
hs: release_f1
hs-debug: CFLAGS+=$(CFLAGS_F1) $(DEFS_F1_HS)
hs-debug: CXXFLAGS+=$(CXXFLAGS_F1) $(DEFS_F1_HS)
hs-debug: LDFLAGS+=$(LDFLAGS_F1_D)
hs-debug: release_f1
release_f1: $(BINDIR)
release_f1: $(OBJDIR_F1)
release_f1: $(BINDIR)/$(BINBIN_F1)
release_f4: $(BINDIR)
release_f4: $(OBJDIR_F4)
release_f4: $(BINDIR)/$(BINBIN_F4)
$(BINDIR):
mkdir $@
$(OBJDIR_F1):
mkdir $@
mkdir $@/dmr
mkdir $@/p25
mkdir $@/nxdn
$(OBJDIR_F4):
mkdir $@
mkdir $@/dmr
mkdir $@/p25
mkdir $@/nxdn
$(BINDIR)/$(BINBIN_F1): $(BINDIR)/$(BINELF_F1)
$(CP) -O binary $< $@
$(BINDIR)/$(BINELF_F1): $(OBJ_F1)
$(CXX) $(OBJ_F1) $(LDFLAGS) -o $@
$(SIZE) $(BINDIR)/$(BINELF_F1)
$(BINDIR)/$(BINBIN_F4): $(BINDIR)/$(BINELF_F4)
$(CP) -O binary $< $@
$(BINDIR)/$(BINELF_F4): $(OBJ_F4)
$(CXX) $(OBJ_F4) $(LDFLAGS) -o $@
$(SIZE) $(BINDIR)/$(BINELF_F4)
$(OBJDIR_F1)/%.o: ./%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(OBJDIR_F4)/%.o: ./%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(OBJDIR_F1)/%.o: $(STD_LIB_F1)/%.c
$(CC) $(CFLAGS) $< -o $@
$(OBJDIR_F4)/%.o: $(STD_LIB_F4)/%.c
$(CC) $(CFLAGS) $< -o $@
$(OBJDIR_F1)/%.o: $(SYS_DIR_F1)/%.c
$(CC) $(CFLAGS) $< -o $@
$(OBJDIR_F1)/%.o: $(STARTUP_DIR_F1)/%.c
$(CC) $(CFLAGS) $< -o $@
$(OBJDIR_F4)/%.o: $(SYS_DIR_F4)/%.c
$(CC) $(CFLAGS) $< -o $@
$(OBJDIR_F4)/%.o: $(STARTUP_DIR_F4)/%.c
$(CC) $(CFLAGS) $< -o $@
$(OBJDIR_F1)/%.o: $(USB_F1)/%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(OBJDIR_F1)/%.o: $(USB_F1)/%.c
$(CC) $(CFLAGS) $< -o $@
clean-objs:
test ! -d $(OBJDIR_F1) || rm -rf $(OBJDIR_F1)
test ! -d $(OBJDIR_F4) || rm -rf $(OBJDIR_F4)
clean:
test ! -d $(OBJDIR_F1) || rm -rf $(OBJDIR_F1)
test ! -d $(OBJDIR_F4) || rm -rf $(OBJDIR_F4)
rm -f $(BINDIR)/*.bin $(BINDIR)/*.elf