3 # Copyright (C) Dean Camera, 2012.
5 # dean [at] fourwalledcubicle [dot] com
9 LUFA_BUILD_MODULES += ATPROGRAM
10 LUFA_BUILD_TARGETS += atprogram atprogram-ee
11 LUFA_BUILD_MANDATORY_VARS += MCU TARGET
12 LUFA_BUILD_OPTIONAL_VARS += ATPROGRAM_PROGRAMMER ATPROGRAM_INTERFACE ATPROGRAM_PORT
14 # -----------------------------------------------------------------------------
15 # LUFA ATPROGRAM Programmer Buildsystem Makefile Module.
16 # -----------------------------------------------------------------------------
18 # Provides a set of targets to re-program a device using the Atmel atprogram
19 # utility in AVR Studio 5.x and Atmel Studio 6.0 onwards.
20 # -----------------------------------------------------------------------------
23 # atprogram - Program target FLASH with application using
25 # atprogram-ee - Program target EEPROM with application data
28 # MANDATORY PARAMETERS:
30 # MCU - Microcontroller device model name
31 # TARGET - Application name
33 # OPTIONAL PARAMETERS:
35 # ATPROGRAM_PROGRAMMER - Name of programming hardware to use
36 # ATPROGRAM_INTERFACE - Name of programming interface to use
37 # ATPROGRAM_PORT - Name of communication port to use
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 ATPROGRAM_PROGRAMMER ?= jtagice3
47 ATPROGRAM_INTERFACE ?= jtag
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, ATPROGRAM_PROGRAMMER)
55 $(call ERROR_IF_EMPTY, ATPROGRAM_INTERFACE)
58 MSG_ATPROGRAM_CMD := ' [ATPRGRM] :'
60 # Construct base atprogram command flags
61 BASE_ATPROGRAM_FLAGS := --tool $(ATPROGRAM_PROGRAMMER) --interface $(ATPROGRAM_INTERFACE) --device $(MCU)
62 ifneq ($(ATPROGRAM_PORT),)
63 BASE_ATPROGRAM_FLAGS += --port $(ATPROGRAM_PORT)
66 # Construct the flags to use for the various memory spaces
68 ATPROGRAM_FLASH_FLAGS := --chiperase --flash
69 ATPROGRAM_EEPROM_FLAGS := --eeprom
70 else ifeq ($(ARCH), XMEGA)
71 ATPROGRAM_FLASH_FLAGS := --erase --flash
72 ATPROGRAM_EEPROM_FLAGS := --eeprom
73 else ifeq ($(ARCH), UC3)
74 ATPROGRAM_FLASH_FLAGS := --erase
75 ATPROGRAM_EEPROM_FLAGS := --eeprom
77 $(error Unsupported architecture "$(ARCH)")
80 atprogram: $(TARGET).elf $(MAKEFILE_LIST)
81 @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" FLASH using \"$(ATPROGRAM_PROGRAMMER)\"
82 atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_FLASH_FLAGS) --file $<
84 atprogram-ee: $(TARGET).elf $(MAKEFILE_LIST)
85 @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" EEPROM using \"$(ATPROGRAM_PROGRAMMER)\"
86 atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_EEPROM_FLAGS) --file $<
88 # Phony build targets for this module
89 .PHONY: atprogram atprogram-ee