3 # Copyright (C) Dean Camera, 2012.
5 # dean [at] fourwalledcubicle [dot] com
9 LUFA_BUILD_MODULES += AVRDUDE
10 LUFA_BUILD_TARGETS += avrdude avrdude-ee
11 LUFA_BUILD_MANDATORY_VARS += MCU TARGET
12 LUFA_BUILD_OPTIONAL_VARS += AVRDUDE_PROGRAMMER AVRDUDE_PORT AVRDUDE_FLAGS
13 LUFA_BUILD_PROVIDED_VARS +=
14 LUFA_BUILD_PROVIDED_MACROS +=
16 # -----------------------------------------------------------------------------
17 # LUFA AVRDUDE Programmer Buildsystem Makefile Module.
18 # -----------------------------------------------------------------------------
20 # Provides a set of targets to re-program a device using the open source
22 # -----------------------------------------------------------------------------
25 # avrdude - Program target FLASH with application using
27 # avrdude-ee - Program target EEPROM with application data
30 # MANDATORY PARAMETERS:
32 # MCU - Microcontroller device model name
33 # TARGET - Application name
35 # OPTIONAL PARAMETERS:
37 # AVRDUDE_PROGRAMMER - Name of programming hardware to use
38 # AVRDUDE_PORT - Name of communication port to use
39 # AVRDUDE_FLAGS - Flags to pass to avr-dude
49 # -----------------------------------------------------------------------------
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 # Default values of optionally user-supplied variables
56 AVRDUDE_PROGRAMMER ?= jtagicemkii
60 # Sanity check user supplied values
61 $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
62 $(call ERROR_IF_EMPTY, MCU)
63 $(call ERROR_IF_EMPTY, TARGET)
64 $(call ERROR_IF_EMPTY, AVRDUDE_PROGRAMMER)
65 $(call ERROR_IF_EMPTY, AVRDUDE_PORT)
68 MSG_AVRDUDE_CMD := ' [AVRDUDE] :'
70 avrdude: $(TARGET).hex $(MAKEFILE_LIST)
71 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" FLASH with settings \"$(AVRDUDE_FLASH_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
72 avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U flash:w:$< $(AVRDUDE_FLAGS)
74 avrdude-ee: $(TARGET).eep $(MAKEFILE_LIST)
75 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" EEPROM with settings \"$(AVRDUDE_EEP_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
76 avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U eeprom:w:$< $(AVRDUDE_FLAGS)
78 # Phony build targets for this module
79 .PHONY: avrdude avrdude-ee