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
14 # -----------------------------------------------------------------------------
15 # LUFA AVRDUDE Programmer Buildsystem Makefile Module.
16 # -----------------------------------------------------------------------------
18 # Provides a set of targets to re-program a device using the open source
20 # -----------------------------------------------------------------------------
23 # avrdude - Program target FLASH with application using
25 # avrdude-ee - Program target EEPROM with application data
28 # MANDATORY PARAMETERS:
30 # MCU - Microcontroller device model name
31 # TARGET - Application name
33 # OPTIONAL PARAMETERS:
35 # AVRDUDE_PROGRAMMER - Name of programming hardware to use
36 # AVRDUDE_PORT - Name of communication port to use
37 # AVRDUDE_FLAGS - Flags to pass to avr-dude
39 # -----------------------------------------------------------------------------
41 ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
42 ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
43 ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
45 # Default values of optionally user-supplied variables
46 AVRDUDE_PROGRAMMER ?= jtagicemkii
50 # Sanity check user supplied values
51 $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
52 $(call ERROR_IF_EMPTY, MCU)
53 $(call ERROR_IF_EMPTY, TARGET)
54 $(call ERROR_IF_EMPTY, AVRDUDE_PROGRAMMER)
55 $(call ERROR_IF_EMPTY, AVRDUDE_PORT)
58 MSG_AVRDUDE_CMD := ' [AVRDUDE] :'
60 avrdude: $(TARGET).hex $(MAKEFILE_LIST)
61 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" FLASH with settings \"$(AVRDUDE_FLASH_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
62 avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U flash:w:$< $(AVRDUDE_FLAGS)
64 avrdude-ee: $(TARGET).eep $(MAKEFILE_LIST)
65 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" EEPROM with settings \"$(AVRDUDE_EEP_FLAGS)\" using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
66 avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U eeprom:w:$< $(AVRDUDE_FLAGS)
68 # Phony build targets for this module
69 .PHONY: avrdude avrdude-ee