@@ -17,8 +17,10 @@ SD_VERSION = 6.1.1
17
17
SD_FILENAME = $(SD_NAME ) _nrf52_$(SD_VERSION )
18
18
SD_HEX = $(SD_PATH ) /$(SD_FILENAME ) _softdevice.hex
19
19
20
- # linker by MCU and SoftDevice eg. nrf52840_s140_v6.ld
21
- LD_FILE = linker/$(MCU_SUB_VARIANT ) _$(SD_NAME ) _v$(word 1, $(subst ., ,$(SD_VERSION ) ) ) .ld
20
+ MBR_HEX = lib/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex
21
+
22
+ # linker by MCU eg. nrf52840.ld
23
+ LD_FILE = linker/$(MCU_SUB_VARIANT ) .ld
22
24
23
25
GIT_VERSION = $(shell git describe --dirty --always --tags)
24
26
GIT_SUBMODULE_VERSIONS = $(shell git submodule status | cut -d' ' -f3,4 | paste -s -d" " -)
93
95
# all files in src
94
96
C_SRC += $(wildcard src/* .c)
95
97
98
+ # all files in boards
99
+ C_SRC += $(wildcard src/boards/* .c)
100
+
96
101
# all sources files in specific board
97
102
C_SRC += $(wildcard src/boards/$(BOARD ) /* .c)
98
103
@@ -162,11 +167,10 @@ ASM_SRC = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S
162
167
163
168
# src
164
169
IPATH += src
170
+ IPATH += src/boards
165
171
IPATH += src/boards/$(BOARD )
166
-
167
172
IPATH += src/cmsis/include
168
173
IPATH += src/usb
169
- IPATH += src/boards
170
174
IPATH += $(TUSB_PATH )
171
175
172
176
# nrfx
@@ -196,17 +200,17 @@ IPATH += $(SDK_PATH)/drivers_nrf/delay
196
200
IPATH += $(SD_PATH ) /$(SD_FILENAME ) _API/include
197
201
IPATH += $(SD_PATH ) /$(SD_FILENAME ) _API/include/nrf52
198
202
199
- INC_PATHS = $(addprefix -I,$(IPATH ) )
200
-
201
203
# ------------------------------------------------------------------------------
202
204
# Compiler Flags
203
205
# ------------------------------------------------------------------------------
204
206
205
- # Debugging/Optimization
207
+ # Debug option use RTT for printf
206
208
ifeq ($(DEBUG ) , 1)
207
- CFLAGS += -Og -ggdb
208
- else
209
- CFLAGS += -Os
209
+ RTT_SRC = lib/SEGGER_RTT
210
+
211
+ CFLAGS += -ggdb -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
212
+ IPATH += $(RTT_SRC)/RTT
213
+ C_SRC += $(RTT_SRC ) /RTT/SEGGER_RTT.c
210
214
endif
211
215
212
216
# flags common to all targets
@@ -216,6 +220,7 @@ CFLAGS += \
216
220
-mcpu=cortex-m4 \
217
221
-mfloat-abi=hard \
218
222
-mfpu=fpv4-sp-d16 \
223
+ -Os \
219
224
-ffunction-sections \
220
225
-fdata-sections \
221
226
-fno-builtin \
@@ -249,7 +254,7 @@ CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS
249
254
CFLAGS += -DSOFTDEVICE_PRESENT
250
255
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
251
256
252
- CFLAGS += -DUF2_VERSION='"$(GIT_VERSION ) $(GIT_SUBMODULE_VERSIONS ) $( SD_NAME ) $( SD_VERSION ) "'
257
+ CFLAGS += -DUF2_VERSION='"$(GIT_VERSION ) $(GIT_SUBMODULE_VERSIONS ) "'
253
258
CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION ) $(SD_NAME ) $(SD_VERSION ) "'
254
259
255
260
_VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION ) ) ) )
@@ -289,6 +294,8 @@ vpath %.S $(ASM_PATHS)
289
294
290
295
OBJECTS = $(C_OBJECTS ) $(ASM_OBJECTS )
291
296
297
+ INC_PATHS = $(addprefix -I,$(IPATH ) )
298
+
292
299
# ------------------------------------------------------------------------------
293
300
# BUILD TARGETS
294
301
# ------------------------------------------------------------------------------
@@ -306,40 +313,11 @@ endif
306
313
.PHONY : all clean flash dfu-flash sd gdbflash gdb
307
314
308
315
# default target to build
309
- all : $(BUILD ) /$(OUT_FILE ) -nosd.out $(BUILD ) /$(MERGED_FILE ) .hex
310
-
311
- # ------------------- Flash target -------------------
312
-
313
- check_defined = \
314
- $(strip $(foreach 1,$1, \
315
- $(call __check_defined,$1,$(strip $(value 2)))))
316
- __check_defined = \
317
- $(if $(value $1),, \
318
- $(error Undefined make flag : $1$(if $2, ($2) )))
319
-
320
- # Flash the compiled
321
- flash : $(BUILD ) /$(OUT_FILE ) -nosd.hex
322
- @echo Flashing: $<
323
- $(NRFJPROG ) --program $< --sectoranduicrerase -f nrf52 --reset
324
-
325
- dfu-flash : $(BUILD ) /$(MERGED_FILE ) .zip
326
- @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
327
- $(NRFUTIL ) --verbose dfu serial --package $< -p $(SERIAL ) -b 115200 --singlebank --touch 1200
328
-
329
- sd :
330
- @echo Flashing: $(SD_HEX )
331
- $(NRFJPROG ) --program $(SD_HEX ) -f nrf52 --chiperase --reset
332
-
333
- gdbflash : $(BUILD ) /$(MERGED_FILE ) .hex
334
- @echo Flashing: $<
335
- @$(GDB_BMP ) -nx --batch -ex ' load $<' -ex ' compare-sections' -ex ' kill'
336
-
337
- gdb : $(BUILD ) /$(OUT_FILE ) -nosd.out
338
- $(GDB_BMP ) $<
316
+ all : $(BUILD ) /$(OUT_FILE ) .out $(BUILD ) /$(OUT_FILE ) -nosd.hex $(BUILD ) /$(OUT_FILE ) -nosd.uf2 $(BUILD ) /$(MERGED_FILE ) .hex $(BUILD ) /$(MERGED_FILE ) .zip
339
317
340
318
# ------------------- Compile rules -------------------
341
319
342
- # # Create build directories
320
+ # Create build directories
343
321
$(BUILD ) :
344
322
@$(MK ) $@
345
323
@@ -357,26 +335,73 @@ $(BUILD)/%.o: %.S
357
335
@$(CC ) -x assembler-with-cpp $(ASFLAGS ) $(INC_PATHS ) -c -o $@ $<
358
336
359
337
# Link
360
- $(BUILD ) /$(OUT_FILE ) -nosd .out : $(BUILD ) $(OBJECTS )
361
- @echo LD $(OUT_FILE ) -nosd.out
338
+ $(BUILD ) /$(OUT_FILE ) .out : $(BUILD ) $(OBJECTS )
339
+ @echo LD $(notdir $@ )
362
340
@$(CC ) -o $@ $(LDFLAGS ) $(OBJECTS ) -Wl,--start-group $(LIBS ) -Wl,--end-group
363
341
@$(SIZE ) $@
364
342
365
343
# ------------------- Binary generator -------------------
366
344
367
- # # Create binary . hex file from the .out file
368
- $(BUILD ) /$(OUT_FILE ) -nosd .hex : $(BUILD ) /$(OUT_FILE ) -nosd .out
369
- @echo CR $(OUT_FILE ) -nosd.hex
345
+ # Create hex file (no sd, no mbr)
346
+ $(BUILD ) /$(OUT_FILE ) .hex : $(BUILD ) /$(OUT_FILE ) .out
347
+ @echo Create $(notdir $@ )
370
348
@$(OBJCOPY ) -O ihex $< $@
371
349
372
- # merge bootloader and sd hex together
373
- $(BUILD ) /$(MERGED_FILE ) .hex : $(BUILD ) /$(OUT_FILE ) -nosd .hex
374
- @echo CR $(MERGED_FILE ) .hex
375
- @mergehex -q -m $ < $(SD_HEX ) -o $@
350
+ # Hex file with mbr (still no SD)
351
+ $(BUILD ) /$(OUT_FILE ) -nosd .hex : $(BUILD ) /$(OUT_FILE ) .hex
352
+ @echo Create $(notdir $@ )
353
+ @python3 tools/hexmerge.py --overlap=replace -o $@ $ < $(MBR_HEX )
376
354
377
- # # Create pkg zip file for bootloader+SD combo to use with DFU Serial
378
- .PHONY : genpkg
379
- genpkg : $(BUILD ) /$(MERGED_FILE ) .zip
355
+ # Bootolader only uf2
356
+ $(BUILD ) /$(OUT_FILE ) -nosd.uf2 : $(BUILD ) /$(OUT_FILE ) -nosd.hex
357
+ @echo Create $(notdir $@ )
358
+ @python3 lib/uf2/utils/uf2conv.py -f 0xd663823c -c -o $@ $^
380
359
381
- $(BUILD ) /$(MERGED_FILE ) .zip : $(BUILD ) /$(OUT_FILE ) -nosd.hex
360
+ # merge bootloader and sd hex together
361
+ $(BUILD ) /$(MERGED_FILE ) .hex : $(BUILD ) /$(OUT_FILE ) .hex
362
+ @echo Create $(notdir $@ )
363
+ @python3 tools/hexmerge.py -o $@ $< $(SD_HEX )
364
+
365
+ # Create pkg zip file for bootloader+SD combo to use with DFU CDC
366
+ $(BUILD ) /$(MERGED_FILE ) .zip : $(BUILD ) /$(OUT_FILE ) .hex
382
367
@$(NRFUTIL ) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV ) --bootloader $< --softdevice $(SD_HEX ) $@
368
+
369
+ # ------------------- Flash target -------------------
370
+
371
+ check_defined = \
372
+ $(strip $(foreach 1,$1, \
373
+ $(call __check_defined,$1,$(strip $(value 2)))))
374
+ __check_defined = \
375
+ $(if $(value $1),, \
376
+ $(error Undefined make flag : $1$(if $2, ($2) )))
377
+
378
+ # Flash the compiled
379
+ flash : $(BUILD ) /$(OUT_FILE ) -nosd.hex
380
+ @echo Flashing: $(notdir $< )
381
+ $(NRFJPROG ) --program $< --sectoranduicrerase -f nrf52 --reset
382
+
383
+ # dfu using CDC interface
384
+ dfu-flash : $(BUILD ) /$(MERGED_FILE ) .zip
385
+ @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
386
+ $(NRFUTIL ) --verbose dfu serial --package $< -p $(SERIAL ) -b 115200 --singlebank --touch 1200
387
+
388
+ erase :
389
+ @echo Erasing flash
390
+ $(NRFJPROG ) -f nrf52 --eraseall
391
+
392
+ # flash SD only
393
+ sd :
394
+ @echo Flashing: $(SD_HEX )
395
+ $(NRFJPROG ) --program $(SD_HEX ) -f nrf52 --sectorerase --reset
396
+
397
+ # flash MBR only
398
+ mbr :
399
+ @echo Flashing: $(MBR_HEX )
400
+ $(NRFJPROG ) --program $(MBR_HEX ) -f nrf52 --sectorerase --reset
401
+
402
+ gdbflash : $(BUILD ) /$(MERGED_FILE ) .hex
403
+ @echo Flashing: $<
404
+ @$(GDB_BMP ) -nx --batch -ex ' load $<' -ex ' compare-sections' -ex ' kill'
405
+
406
+ gdb : $(BUILD ) /$(OUT_FILE ) .out
407
+ $(GDB_BMP ) $<
0 commit comments