-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
291 lines (231 loc) · 8.47 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
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
#------------------------------------------------------------------------------
# CONFIGURE
# - SDK_PATH : path to SDK directory
#
# - SD_NAME : e.g s132, s140
# - SD_VERSION : SoftDevice version e.g 6.0.0
# - SD_HEX : to bootloader hex binary
#------------------------------------------------------------------------------
SDK_PATH = lib/sdk/components
SDK11_PATH = lib/sdk11/components
TUSB_PATH = lib/tinyusb/src
NRFX_PATH = lib/nrfx
SD_PATH = lib/softdevice/$(SD_FILENAME)
GIT_VERSION = $(shell git describe --dirty --always --tags)
GIT_SUBMODULE_VERSIONS = $(shell git submodule status | cut -d' ' -f3,4 | paste -s -d" " -)
#------------------------------------------------------------------------------
# Tool configure
#------------------------------------------------------------------------------
# Toolchain commands
# Should be added to your PATH
CROSS_COMPILE ?= arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)as
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
GDB = $(CROSS_COMPILE)gdb
MK = mkdir -p
RM = rm -rf
# auto-detect BMP on macOS, otherwise have to specify
BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1)
GDB_BMP = $(GDB) -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1'
#---------------------------------
# Select the board to build
#---------------------------------
BOARD ?= simmel
# Build directory
BUILD = _build
# Board specific
-include src/boards/$(BOARD)/board.mk
SD_NAME = s140
DFU_DEV_REV = 52840
CFLAGS += -DNRF52833_XXAA -DS140 -DCFG_TUSB_MCU=OPT_MCU_NRF5X
SD_VERSION = 7.0.1
SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
# linker by MCU and SoftDevice eg. nrf52840_s140_v6.ld
LD_FILE = linker/$(MCU_SUB_VARIANT)_$(SD_NAME)_v$(word 1, $(subst ., ,$(SD_VERSION))).ld
# compiled file name
OUT_FILE = nus-test
#------------------------------------------------------------------------------
# SOURCE FILES
#------------------------------------------------------------------------------
# all files in src
C_SRC += $(wildcard src/*.c)
C_SRC += $(wildcard src/afsk/*.c)
# all sources files in specific board
C_SRC += $(wildcard src/boards/$(BOARD)/*.c)
# nrfx
C_SRC += $(NRFX_PATH)/drivers/src/nrfx_power.c
C_SRC += $(NRFX_PATH)/drivers/src/nrfx_nvmc.c
C_SRC += $(NRFX_PATH)/mdk/system_$(MCU_SUB_VARIANT).c
# tinyusb
C_SRC += $(TUSB_PATH)/tusb.c
C_SRC += $(TUSB_PATH)/common/tusb_fifo.c
C_SRC += $(TUSB_PATH)/device/usbd.c
C_SRC += $(TUSB_PATH)/device/usbd_control.c
C_SRC += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c
C_SRC += $(TUSB_PATH)/class/cdc/cdc_device.c
IPATH += lib/tinyusb/hw/mcu/nordic/nrf5x/s140_nrf52_6.1.1_API/include/nrf52
IPATH += lib/tinyusb/hw/mcu/nordic/nrf5x/s140_nrf52_6.1.1_API/include
#------------------------------------------------------------------------------
# Assembly Files
#------------------------------------------------------------------------------
ASM_SRC ?= $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S
#------------------------------------------------------------------------------
# INCLUDE PATH
#------------------------------------------------------------------------------
# src
IPATH += src
IPATH += src/boards/$(BOARD)
IPATH += src/cmsis/include
IPATH += src/afsk
IPATH += src/boards
IPATH += $(TUSB_PATH)
# nrfx
IPATH += $(NRFX_PATH)
IPATH += $(NRFX_PATH)/mdk
IPATH += $(NRFX_PATH)/hal
IPATH += $(NRFX_PATH)/drivers/include
IPATH += $(NRFX_PATH)/drivers/src
IPATH += $(SDK11_PATH)/libraries/bootloader_dfu/hci_transport
IPATH += $(SDK11_PATH)/libraries/bootloader_dfu
IPATH += $(SDK11_PATH)/drivers_nrf/pstorage
IPATH += $(SDK11_PATH)/ble/common
IPATH += $(SDK11_PATH)/ble/ble_services/ble_dfu
IPATH += $(SDK11_PATH)/ble/ble_services/ble_dis
IPATH += $(SDK_PATH)/libraries/timer
IPATH += $(SDK_PATH)/libraries/scheduler
IPATH += $(SDK_PATH)/libraries/crc16
IPATH += $(SDK_PATH)/libraries/util
IPATH += $(SDK_PATH)/libraries/hci/config
IPATH += $(SDK_PATH)/libraries/uart
IPATH += $(SDK_PATH)/libraries/hci
IPATH += $(SDK_PATH)/drivers_nrf/delay
# Softdevice
IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include
IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52
INC_PATHS = $(addprefix -I,$(IPATH))
#------------------------------------------------------------------------------
# Compiler Flags
#------------------------------------------------------------------------------
# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -O2 -ggdb3
else
CFLAGS += -O2 -ggdb3
endif
#flags common to all targets
CFLAGS += \
-mthumb \
-mabi=aapcs \
-mcpu=cortex-m4 \
-mfloat-abi=hard \
-mfpu=fpv4-sp-d16 \
-ffunction-sections \
-fdata-sections \
-fno-builtin \
-fshort-enums \
-fstack-usage \
-fno-strict-aliasing \
-Wall \
-Wextra \
-Werror \
-Wfatal-errors \
-Werror-implicit-function-declaration \
-Wundef \
-Wshadow \
-Wwrite-strings \
-Wsign-compare \
-Wmissing-format-attribute \
-Wno-endif-labels \
-Wunreachable-code
# Suppress warning caused by SDK
CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined
# TinyUSB tusb_hal_nrf_power_event
CFLAGS += -Wno-cast-function-type
# Defined Symbol (MACROS)
CFLAGS += -D__HEAP_SIZE=0
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS
CFLAGS += -DNO_MAIN
# CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS) $(SD_NAME) $(SD_VERSION)"'
_VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION))))
#------------------------------------------------------------------------------
# Linker Flags
#------------------------------------------------------------------------------
LDFLAGS += \
$(CFLAGS) \
-Wl,-L,linker -Wl,-T,$(LD_FILE) \
-Wl,[email protected] -Wl,-cref -Wl,-gc-sections \
-specs=nosys.specs -specs=nano.specs
LIBS += -lm -lc
#------------------------------------------------------------------------------
# Assembler flags
#------------------------------------------------------------------------------
ASFLAGS += $(CFLAGS)
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
C_SOURCE_FILE_NAMES = $(notdir $(C_SRC))
C_PATHS = $(call remduplicates, $(dir $(C_SRC) ) )
C_OBJECTS = $(addprefix $(BUILD)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SRC))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SRC) ))
ASM_OBJECTS = $(addprefix $(BUILD)/, $(ASM_SOURCE_FILE_NAMES:.S=.o) )
vpath %.c $(C_PATHS)
vpath %.S $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
#------------------------------------------------------------------------------
# BUILD TARGETS
#------------------------------------------------------------------------------
# Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command
ifeq ("$(V)","1")
$(info CFLAGS $(CFLAGS))
$(info )
$(info LDFLAGS $(LDFLAGS))
$(info )
$(info ASFLAGS $(ASFLAGS))
$(info )
endif
.PHONY: all clean flash sd gdb
# default target to build
all: $(BUILD)/$(OUT_FILE)-nosd.hex
@echo "SoftDevice hex file:"
@echo " $(SD_HEX)"
@echo "Bootloader hex file:"
@echo " $(BUILD)/$(OUT_FILE)-nosd.hex"
@echo "Load these two files using openocd."
#------------------- Flash target -------------------
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined make flag: $1$(if $2, ($2))))
gdb: $(BUILD)/$(OUT_FILE)-nosd.elf
$(GDB_BMP) $<
#------------------- Compile rules -------------------
## Create build directories
$(BUILD):
@$(MK) $@
clean:
@$(RM) $(BUILD)
# Create objects from C SRC files
$(BUILD)/%.o: %.c
@echo CC $(notdir $<)
@$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
# Assemble files
$(BUILD)/%.o: %.S
@echo AS $(notdir $<)
@$(CC) -x assembler-with-cpp $(ASFLAGS) $(INC_PATHS) -c -o $@ $<
# Link
$(BUILD)/$(OUT_FILE)-nosd.elf: $(BUILD) $(OBJECTS)
@echo LD $(OUT_FILE)-nosd.elf
@$(CC) -o $@ $(LDFLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group
@$(SIZE) $@
#------------------- Binary generator -------------------
## Create binary .hex file from the .elf file
$(BUILD)/$(OUT_FILE)-nosd.hex: $(BUILD)/$(OUT_FILE)-nosd.elf
@echo CR $(OUT_FILE)-nosd.hex
@$(OBJCOPY) -O ihex $< $@