3 # Copyright (C) Dean Camera, 2012.
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 # -----------------------------------------------------------------------------
49 ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
50 ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
51 ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
53 # Sanity-check values of mandatory user-supplied variables
54 $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
55 $(call ERROR_IF_EMPTY, MCU)
56 $(call ERROR_IF_EMPTY, TARGET)
59 MSG_COPY_CMD := ' [CP] :'
60 MSG_REMOVE_CMD := ' [RM] :'
61 MSG_DFU_CMD := ' [DFU] :'
63 flip: $(TARGET).hex $(MAKEFILE_LIST)
64 @echo $(MSG_DFU_CMD) Programming FLASH with batchisp using \"$<\"
65 batchisp -hardware usb -device $(MCU) -operation erase f
66 batchisp -hardware usb -device $(MCU) -operation loadbuffer $< program
67 batchisp -hardware usb -device $(MCU) -operation start reset 0
69 flip-ee: $(TARGET).eep $(MAKEFILE_LIST)
70 @echo $(MSG_DFU_CMD) Copying EEP file to temporary file \"$<.hex\"
72 @echo $(MSG_DFU_CMD) Programming EEPROM with batchisp using \"$<.hex\"
73 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
74 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $<.hex program
75 batchisp -hardware usb -device $(MCU) -operation start reset 0
76 @echo $(MSG_DFU_CMD) Removing temporary file \"$<.hex\"
79 dfu: $(TARGET).hex $(MAKEFILE_LIST)
80 @echo $(MSG_DFU_CMD) Programming FLASH with dfu-programmer using \"$<\"
81 dfu-programmer $(MCU) erase
82 dfu-programmer $(MCU) flash $<
83 dfu-programmer $(MCU) reset
85 dfu-ee: $(TARGET).eep $(MAKEFILE_LIST)
86 @echo $(MSG_DFU_CMD) Programming EEPROM with dfu-programmer using \"$<\"
87 dfu-programmer $(MCU) eeprom-flash $<
88 dfu-programmer $(MCU) reset
90 # Phony build targets for this module
91 .PHONY: flip flip-ee dfu dfu-ee