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 +=
14 # -----------------------------------------------------------------------------
15 # LUFA DFU Bootloader Buildsystem Makefile Module.
16 # -----------------------------------------------------------------------------
18 # Provides a set of targets to re-program a device currently running a DFU
19 # class bootloader with a project's FLASH and EEPROM files.
20 # -----------------------------------------------------------------------------
23 # flip - Program FLASH into target via Atmel FLIP
24 # flip-ee - Program EEPROM into target via Atmel FLIP
25 # dfu - Program FLASH into target via dfu-programmer
26 # dfu-ee - Program EEPROM into target via dfu-programmer
28 # MANDATORY PARAMETERS:
30 # MCU - Microcontroller device model name
31 # TARGET - Application name
33 # OPTIONAL PARAMETERS:
37 # -----------------------------------------------------------------------------
39 ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
40 ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
41 ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
43 # Sanity-check values of mandatory user-supplied variables
44 $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
45 $(call ERROR_IF_EMPTY, MCU)
46 $(call ERROR_IF_EMPTY, TARGET)
49 MSG_COPY_CMD := ' [CP] :'
50 MSG_REMOVE_CMD := ' [RM] :'
51 MSG_DFU_CMD := ' [DFU] :'
53 flip: $(TARGET).hex $(MAKEFILE_LIST)
54 @echo $(MSG_DFU_CMD) Programming FLASH with batchisp using \"$<\"
55 batchisp -hardware usb -device $(MCU) -operation erase f
56 batchisp -hardware usb -device $(MCU) -operation loadbuffer $< program
57 batchisp -hardware usb -device $(MCU) -operation start reset 0
59 flip-ee: $(TARGET).eep $(MAKEFILE_LIST)
60 @echo $(MSG_DFU_CMD) Copying EEP file to temporary file \"$<.hex\"
62 @echo $(MSG_DFU_CMD) Programming EEPROM with batchisp using \"$<.hex\"
63 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
64 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $<.hex program
65 batchisp -hardware usb -device $(MCU) -operation start reset 0
66 @echo $(MSG_DFU_CMD) Removing temporary file \"$<.hex\"
69 dfu: $(TARGET).hex $(MAKEFILE_LIST)
70 @echo $(MSG_DFU_CMD) Programming FLASH with dfu-programmer using \"$<\"
71 dfu-programmer $(MCU) erase
72 dfu-programmer $(MCU) flash $<
73 dfu-programmer $(MCU) reset
75 dfu-ee: $(TARGET).eep $(MAKEFILE_LIST)
76 @echo $(MSG_DFU_CMD) Programming EEPROM with dfu-programmer using \"$<\"
77 dfu-programmer $(MCU) eeprom-flash $<
78 dfu-programmer $(MCU) reset
80 # Phony build targets for this module
81 .PHONY: flip flip-ee dfu dfu-ee