3 # Copyright (C) Dean Camera, 2014.
5 # dean [at] fourwalledcubicle [dot] com
9 LUFA_BUILD_MODULES += DFU
10 LUFA_BUILD_TARGETS += flip flip-ee dfu dfu-ee
11 LUFA_BUILD_MANDATORY_VARS += MCU TARGET
12 LUFA_BUILD_OPTIONAL_VARS +=
13 LUFA_BUILD_PROVIDED_VARS +=
14 LUFA_BUILD_PROVIDED_MACROS +=
16 # -----------------------------------------------------------------------------
17 # LUFA DFU Bootloader Buildsystem Makefile Module.
18 # -----------------------------------------------------------------------------
20 # Provides a set of targets to re-program a device currently running a DFU
21 # class bootloader with a project's FLASH and EEPROM files.
22 # -----------------------------------------------------------------------------
25 # flip - Program FLASH into target via Atmel FLIP
26 # flip-ee - Program EEPROM into target via Atmel FLIP
27 # dfu - Program FLASH into target via dfu-programmer
28 # dfu-ee - Program EEPROM into target via dfu-programmer
30 # MANDATORY PARAMETERS:
32 # MCU - Microcontroller device model name
33 # TARGET - Application name
35 # OPTIONAL PARAMETERS:
47 # -----------------------------------------------------------------------------
51 ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
52 ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
53 ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
55 # Sanity-check values of mandatory user-supplied variables
56 $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
57 $(call ERROR_IF_EMPTY, MCU)
58 $(call ERROR_IF_EMPTY, TARGET)
61 MSG_COPY_CMD := ' [CP] :'
62 MSG_REMOVE_CMD := ' [RM] :'
63 MSG_DFU_CMD := ' [DFU] :'
65 # Programs in the target FLASH memory using BATCHISP, the command line tool used by FLIP
66 flip: $(TARGET).hex $(MAKEFILE_LIST)
67 @echo $(MSG_DFU_CMD) Programming FLASH with batchisp using \"$<\"
68 batchisp -hardware usb -device $(MCU) -operation erase f loadbuffer $< program
69 batchisp -hardware usb -device $(MCU) -operation start reset 0
71 # Programs in the target EEPROM memory using BATCHISP, the command line tool used by FLIP
72 flip-ee: $(TARGET).eep $(MAKEFILE_LIST)
73 @echo $(MSG_COPY_CMD) Copying EEP file to temporary file \"$<.hex\"
75 @echo $(MSG_DFU_CMD) Programming EEPROM with batchisp using \"$<.hex\"
76 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $<.hex program
77 batchisp -hardware usb -device $(MCU) -operation start reset 0
78 @echo $(MSG_REMOVE_CMD) Removing temporary file \"$<.hex\"
81 # Programs in the target FLASH memory using DFU-PROGRAMMER
82 dfu: $(TARGET).hex $(MAKEFILE_LIST)
83 @echo $(MSG_DFU_CMD) Programming FLASH with dfu-programmer using \"$<\"
84 dfu-programmer $(MCU) erase
85 dfu-programmer $(MCU) flash $<
86 dfu-programmer $(MCU) reset
88 # Programs in the target EEPROM memory using DFU-PROGRAMMER
89 dfu-ee: $(TARGET).eep $(MAKEFILE_LIST)
90 @echo $(MSG_DFU_CMD) Programming EEPROM with dfu-programmer using \"$<\"
91 dfu-programmer $(MCU) eeprom-flash $<
92 dfu-programmer $(MCU) reset
94 # Phony build targets for this module
95 .PHONY: flip flip-ee dfu dfu-ee