Skip to content

Commit 934d141

Browse files
authored
Merge pull request #158 from nitz/feature-pyocd-flasher
Add pyocd flash targets.
2 parents 791906c + 9d86c6b commit 934d141

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

Makefile

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,25 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
4444
SIZE = $(CROSS_COMPILE)size
4545
GDB = $(CROSS_COMPILE)gdb
4646

47+
# Flasher utility options
4748
NRFUTIL = adafruit-nrfutil
4849
NRFJPROG = nrfjprog
50+
FLASHER ?= nrfjprog
51+
PYOCD ?= pyocd
52+
53+
# Flasher will default to nrfjprog,
54+
# Check for pyocd, error on unexpected value.
55+
ifeq ($(FLASHER),nrfjprog)
56+
FLASH_CMD = $(NRFJPROG) --program $1 --sectoranduicrerase -f nrf52 --reset
57+
FLASH_NOUICR_CMD = $(NRFJPROG) --program $1 -f nrf52 --sectorerase --reset
58+
FLASH_ERASE_CMD = $(NRFJPROG) -f nrf52 --eraseall
59+
else ifeq ($(FLASHER),pyocd)
60+
FLASH_CMD = $(PYOCD) flash -t $(MCU_SUB_VARIANT) $1
61+
FLASH_NOUICR_CMD = $(PYOCD) flash -t $(MCU_SUB_VARIANT) $1
62+
FLASH_ERASE_CMD = $(PYOCD) erase -t $(MCU_SUB_VARIANT) --chip
63+
else
64+
$(error Unsupported flash utility: "$(FLASHER)")
65+
endif
4966

5067
# Set make directory command, Windows tries to create a directory named "-p" if that flag is there.
5168
ifneq ($(OS), Windows_NT)
@@ -390,26 +407,30 @@ __check_defined = \
390407
# Flash the compiled
391408
flash: $(BUILD)/$(OUT_FILE)-nosd.hex
392409
@echo Flashing: $(notdir $<)
393-
$(NRFJPROG) --program $< --sectoranduicrerase -f nrf52 --reset
394-
395-
# dfu using CDC interface
396-
dfu-flash: $(BUILD)/$(MERGED_FILE).zip
397-
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
398-
$(NRFUTIL) --verbose dfu serial --package $< -p $(SERIAL) -b 115200 --singlebank --touch 1200
410+
$(call FLASH_CMD,$<)
399411

400412
erase:
401413
@echo Erasing flash
402-
$(NRFJPROG) -f nrf52 --eraseall
414+
$(call FLASH_ERASE_CMD)
403415

404416
# flash SD only
405417
sd:
406418
@echo Flashing: $(SD_HEX)
407-
$(NRFJPROG) --program $(SD_HEX) -f nrf52 --sectorerase --reset
419+
$(call FLASH_NOUICR_CMD,$(SD_HEX))
408420

409421
# flash MBR only
410422
mbr:
411423
@echo Flashing: $(MBR_HEX)
412-
$(NRFJPROG) --program $(MBR_HEX) -f nrf52 --sectorerase --reset
424+
$(call FLASH_NOUICR_CMD,$(MBR_HEX))
425+
426+
#------------------- Flash with NRFUTIL via DFU -------------------
427+
428+
# dfu using CDC interface
429+
dfu-flash: $(BUILD)/$(MERGED_FILE).zip
430+
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
431+
$(NRFUTIL) --verbose dfu serial --package $< -p $(SERIAL) -b 115200 --singlebank --touch 1200
432+
433+
#------------------- Debugging -------------------
413434

414435
gdbflash: $(BUILD)/$(MERGED_FILE).hex
415436
@echo Flashing: $<

0 commit comments

Comments
 (0)