This repository was archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
377 lines (306 loc) · 11.1 KB
/
Makefile
File metadata and controls
377 lines (306 loc) · 11.1 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ------------------------------------------------
-include printing.mk
######################################
# Options
######################################
#use stml073 µc and board
BOARD_L073 = 1
######################################
# target names
######################################
TARGET_MODEM_2_4 = soft_modem_2g4
######################################
# building variables
######################################
# optimization
OPT = -Os -g
# testbench compilation specificity
TESTBENCH := $(if $(filter testbench,$(MAKECMDGOALS)),1,0)
# get hw_modem compile option
HW_MODEM := $(if $(filter hard_modem,$(MAKECMDGOALS)),1,0)
PERF_TEST := $(if $(filter perf_test,$(MAKECMDGOALS)),1,0)
#######################################
# Git information
# Thanks to https://nullpointer.io/post/easily-embed-version-information-in-software-releases/
#######################################
ifneq (, $(shell which git))
GIT_VERSION := $(shell git --no-pager describe --tags --always)
GIT_COMMIT := $(shell git rev-parse --verify HEAD)
GIT_DATE := $(firstword $(shell git --no-pager show --date=iso-strict --format="%ad" --name-only))
BUILD_DATE := $(shell date --iso=seconds)
# If working tree is dirty, append dirty flag
ifneq ($(strip $(shell git status --porcelain 2>/dev/null)),)
GIT_VERSION := $(GIT_VERSION)--dirty
endif
endif
#######################################
# paths
#######################################
# Build path
BUILD_DIR_MODEM_2_4 = build_modem_2_4
######################################
# source
######################################
# Version source - always recompiled to have the correct timestamp
C_SOURCE_VERSION = user_app/git_version.c
# Common C sources
COMMON_C_SOURCES = \
user_app/main.c \
user_app/main_exti.c \
user_app/main_alarm_file_upload.c \
$(C_SOURCE_VERSION) \
smtc_modem_core/modem_api.c\
smtc_modem_core/lorawan_api/lorawan_api.c\
smtc_modem_core/device_management/dm_downlink.c \
smtc_modem_core/device_management/modem_context.c\
smtc_modem_core/modem_services/file_upload.c\
smtc_modem_core/modem_services/modem_utilities.c \
smtc_modem_core/modem_supervisor/modem_supervisor.c\
smtc_modem_core/test_mode/test_mode.c\
lr1mac/src/lr1_stack_mac_layer.c\
lr1mac/src/lr1mac_core.c\
lr1mac/src/lr1mac_utilities.c\
lr1mac/src/smtc_real/src/smtc_real.c\
smtc_crypto/src/aes.c\
smtc_crypto/src/cmac.c\
smtc_crypto/src/crypto.c\
smtc_ral/src/ral.c\
radio_planner/src/radio_planner.c
ifeq ($(HW_MODEM),1)
COMMON_C_SOURCES += \
user_app/hw_modem.c\
user_app/cmd_parser.c
endif
ifeq ($(TESTBENCH),1)
COMMON_C_SOURCES += \
user_app/hw_modem.c\
user_app/cmd_parser.c
endif
ifeq ($(BOARD_L073),1)
COMMON_C_SOURCES += \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rng.c\
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_i2c.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_i2c_ex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_lptim.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rtc.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rtc_ex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_spi.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_tim.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_tim_ex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart_ex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_wwdg.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rcc.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rcc_ex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash_ex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash_ramfunc.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_gpio.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_dma.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_pwr.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_pwr_ex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_cortex.c \
smtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_adc.c \
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_gpio.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_nvm.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_rng.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_rtc.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_adc.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_spi.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_tmr.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_uart.c\
smtc_bsp/arm/stm32/stm32l0xx/smtc_bsp_watchdog.c\
user_app/bsp_specific/bsp_radio_planner.c\
user_app/bsp_specific/ral_hal.c\
user_app/bsp_specific/smtc_bsp_mcu.c\
user_app/mcu_core/system_stm32l0xx.c
endif
# Region specific C sources
MODEM_2_4_C_SOURCES += \
sx1280_driver/src/sx1280.c\
smtc_ral/src/ral_sx1280.c\
user_app/bsp_specific/sx1280_hal.c\
lr1mac/src/smtc_real/src/region_ww2g4.c
# Common ASM sources
ifeq ($(BOARD_L073),1)
ASM_SOURCES = \
user_app/mcu_core/startup_stm32l073xx.s
endif
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
CPP = $(GCC_PATH)/$(PREFIX)g++
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
CPP = $(PREFIX)g++
AS = $(PREFIX)g++ -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
ifeq ($(BOARD_L073),1)
CPU = -mcpu=cortex-m0plus
endif
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# common C defines
ifeq ($(BOARD_L073),1)
COMMON_C_DEFS = \
-DUSE_HAL_DRIVER \
-DBOARD_L0\
-DSTM32L073xx
endif
COMMON_C_DEFS += \
-DGIT_VERSION=\"$(GIT_VERSION)\" \
-DGIT_COMMIT=\"$(GIT_COMMIT)\" \
-DGIT_DATE=\"$(GIT_DATE)\" \
-DBUILD_DATE=\"$(BUILD_DATE)\"
ifeq ($(HW_MODEM),1)
COMMON_C_DEFS += \
-DHW_MODEM_ENABLED
endif
ifeq ($(TESTBENCH),1)
COMMON_C_DEFS += \
-DHW_MODEM_ENABLED\
-DTEST_BYPASS_JOIN_DUTY_CYCLE
endif
ifeq ($(PERF_TEST),1)
COMMON_C_DEFS += \
-DPERF_TEST_ENABLED
endif
# region specific C defines
MODEM_2_4_C_DEFS += \
-DSX1280 \
-DREGION_WW2G4
vpath %.c $(sort $(dir $(C_SOURCES)))
vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
# common C includes
ifeq ($(BOARD_L073),1)
COMMON_C_INCLUDES = \
-Ismtc_bsp/arm/cmsis\
-Ismtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Inc\
-Ismtc_bsp/arm/stm32/stm32_hal/STM32L0xx_HAL_Driver/Inc/Legacy\
-Ismtc_bsp/arm/stm32/stm32l0xx\
-Ismtc_bsp\
-Iuser_app\
-Iuser_app/mcu_core\
-Iuser_app/bsp_specific\
-Ismtc_modem_core\
-Ismtc_modem_core/modem_supervisor\
-Ismtc_modem_core/device_management\
-Ismtc_modem_core/modem_services\
-Ismtc_modem_core/lorawan_api\
-Ismtc_modem_core/test_mode\
-Ismtc_ral/src\
-Ilr1mac\
-Ilr1mac/src\
-Iradio_planner/src\
-Ismtc_crypto/src\
-Ilorawan_api\
-Ilr1mac/src/smtc_real/src\
-Isx1280_driver/src
endif
# region specific C includes
MODEM_2_4_C_INCLUDES = \
-Isx1280_driver/src
# compile gcc flags
WFLAG = -Wall -Wextra -Wno-unused-parameter -Wpedantic -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize $(BYPASS_FLAGS)
ASFLAGS = -fno-builtin $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) $(WFLAG)
#######################################
# LDFLAGS
#######################################
# link script
ifeq ($(BOARD_L073),1)
LDSCRIPT = user_app/mcu_core/stm32l073xx_flash.ld
endif
# libraries
LIBS = -lstdc++ -lsupc++ -lm -lc -lnosys
LIBDIR =
LDFLAGS = $(MCU) --specs=nano.specs --specs=nosys.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,--cref -Wl,--gc-sections
# default action: build all
all: modem_2_4
modem_2_4: $(BUILD_DIR_MODEM_2_4)/$(TARGET_MODEM_2_4).elf $(BUILD_DIR_MODEM_2_4)/$(TARGET_MODEM_2_4).hex $(BUILD_DIR_MODEM_2_4)/$(TARGET_MODEM_2_4).bin
$(call success,$@)
#######################################
# build the TARGET_MODEM_2_4 application
#######################################
SOURCES_2_4 = $(COMMON_C_SOURCES) $(MODEM_2_4_C_SOURCES)
CFLAGS_2_4 = -fno-builtin $(MCU) $(COMMON_C_DEFS) $(MODEM_2_4_C_DEFS) $(COMMON_C_INCLUDES) $(MODEM_2_4_C_INCLUDES) $(OPT) $(WFLAG) -MMD -MP -MF"$(@:%.o=%.d)"
# list of C objects
OBJECTS_2_4 = $(addprefix $(BUILD_DIR_MODEM_2_4)/,$(notdir $(SOURCES_2_4:.c=.o)))
vpath %.c $(sort $(dir $(SOURCES_2_4)))
# list of ASM program objects
OBJECTS_2_4 += $(addprefix $(BUILD_DIR_MODEM_2_4)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR_MODEM_2_4)/%.o: %.c Makefile | $(BUILD_DIR_MODEM_2_4)
$(call build,'CC',$<)
$(SILENT)$(CC) -c $(CFLAGS_2_4) -Wa,-a,-ad,-alms=$(BUILD_DIR_MODEM_2_4)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR_MODEM_2_4)/%.o: %.s Makefile | $(BUILD_DIR_MODEM_2_4)
$(call build,'AS',$<)
$(SILENT)$(AS) -c $(ASFLAGS) $< -o $@
$(BUILD_DIR_MODEM_2_4)/$(TARGET_MODEM_2_4).elf: $(OBJECTS_2_4) Makefile
$(call build,'CC',$<)
$(SILENT)$(CC) $(OBJECTS_2_4) $(LDFLAGS),-Map=$(BUILD_DIR_MODEM_2_4)/$(TARGET_MODEM_2_4).map -o $@
$(SZ) $@
$(BUILD_DIR_MODEM_2_4)/%.hex: $(BUILD_DIR_MODEM_2_4)/%.elf | $(BUILD_DIR_MODEM_2_4)
$(call build,'HEX',$@)
$(SILENT)$(HEX) $< $@
$(BUILD_DIR_MODEM_2_4)/%.bin: $(BUILD_DIR_MODEM_2_4)/%.elf | $(BUILD_DIR_MODEM_2_4)
$(call build,'BIN',$@)
$(SILENT)$(BIN) $< $@
$(BUILD_DIR_MODEM_2_4):
$(SILENT)mkdir $@
.PHONY: clean all test
.PHONY: flash
.PHONY: FORCE
FORCE:
#######################################
# Unit tests
#######################################
test:
cd tests && ./run_tests.sh
#######################################
# Enable LoraWan bypass functionality
#######################################
hard_modem:
$(call warn,"Building HW Modem")
testbench:
$(call warn,"Building Modem for testbench")
perf_test:
$(call warn,"Enabled perf test features")
#######################################
# Flash by copying on ST-Link mounted on WSL
#######################################
DEBUG_DRIVE_LETTER = e
DEBUG_DRIVE = /mnt/$(DEBUG_DRIVE_LETTER)
DEBUG_DRIVE_PRESENT = $(DEBUG_DRIVE)/DETAILS.TXT
$(DEBUG_DRIVE_PRESENT):
#sudo mkdir -p $(DEBUG_DRIVE)
sudo mount -t drvfs $(DEBUG_DRIVE_LETTER): $(DEBUG_DRIVE)
flash: $(DEBUG_DRIVE_PRESENT) $(BUILD_DIR_MODEM_2_4)/$(TARGET_MODEM_2_4).bin
cp $(BUILD_DIR_MODEM_2_4)/$(TARGET_MODEM_2_4).bin $(DEBUG_DRIVE)/
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR_MODEM_2_4)
# *** EOF ***