# This board uses the vendor's serial bootloader

PROGRAMMER ?= nrfutil

ifeq (nrfutil,$(PROGRAMMER))

  # For this board it is required to use Adafruit's implementation of nrfutil.
  # https://github.com/adafruit/Adafruit_nRF52_nrfutil
  #
  # This boards comes with Adafruit's bootloader:
  # https://github.com/adafruit/Adafruit_nRF52_Bootloader
  # In order to burn the application in the correct location, a offset of
  # 0x26000 is required

  ROM_OFFSET = 0x26000
  ROM_LEN = 0xda000

  FLASHFILE = $(HEXFILE)
  FLASHDEPS += $(HEXFILE).zip
  FLASHER = adafruit-nrfutil
  FFLAGS = --verbose dfu serial -p ${PORT} -b 115200 --singlebank --package=$(HEXFILE).zip

  include $(RIOTMAKE)/tools/usb_board_reset.mk
endif

%.hex.zip: %.hex
	$(call check_cmd,$(FLASHER),Flash program and preparation tool)
	$(FLASHER) dfu genpkg --dev-type 0x0052 --sd-req 0x00B6 --application $< $@

include $(RIOTBOARD)/common/nrf52/Makefile.include