3 #     Copyright (C) Dean Camera, 2013. 
   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
 
  13 LUFA_BUILD_PROVIDED_VARS   
+=  
  14 LUFA_BUILD_PROVIDED_MACROS 
+=  
  16 # ----------------------------------------------------------------------------- 
  17 #             LUFA ATPROGRAM Programmer Buildsystem Makefile Module. 
  18 # ----------------------------------------------------------------------------- 
  20 #   Provides a set of targets to re-program a device using the Atmel atprogram 
  21 #   utility in AVR Studio 5.x and Atmel Studio 6.0 onwards. 
  22 # ----------------------------------------------------------------------------- 
  25 #    atprogram                 - Program target FLASH with application using 
  27 #    atprogram-ee              - Program target EEPROM with application data 
  30 # MANDATORY PARAMETERS: 
  32 #    MCU                       - Microcontroller device model name 
  33 #    TARGET                    - Application name 
  35 # OPTIONAL PARAMETERS: 
  37 #    ATPROGRAM_PROGRAMMER      - Name of programming hardware to use 
  38 #    ATPROGRAM_INTERFACE       - Name of programming interface to use 
  39 #    ATPROGRAM_PORT            - Name of communication port to use 
  49 # ----------------------------------------------------------------------------- 
  53 ERROR_IF_UNSET   ?
= $(if 
$(filter undefined
, $(origin $(strip $(1)))), $(error Makefile 
$(strip $(1)) value not set
)) 
  54 ERROR_IF_EMPTY   ?
= $(if 
$(strip $($(strip $(1)))), , $(error Makefile 
$(strip $(1)) option cannot be blank
)) 
  55 ERROR_IF_NONBOOL ?
= $(if 
$(filter Y N
, $($(strip $(1)))), , $(error Makefile 
$(strip $(1)) option must be Y or N
)) 
  57 # Default values of optionally user-supplied variables 
  58 ATPROGRAM_PROGRAMMER ?
= jtagice3
 
  59 ATPROGRAM_INTERFACE  ?
= jtag
 
  62 # Sanity check user supplied values 
  63 $(foreach MANDATORY_VAR
, $(LUFA_BUILD_MANDATORY_VARS
), $(call ERROR_IF_UNSET
, $(MANDATORY_VAR
))) 
  64 $(call ERROR_IF_EMPTY
, MCU
) 
  65 $(call ERROR_IF_EMPTY
, TARGET
) 
  66 $(call ERROR_IF_EMPTY
, ATPROGRAM_PROGRAMMER
) 
  67 $(call ERROR_IF_EMPTY
, ATPROGRAM_INTERFACE
) 
  70 MSG_ATPROGRAM_CMD    
:= ' [ATPRGRM] :' 
  72 # Construct base atprogram command flags 
  73 BASE_ATPROGRAM_FLAGS 
:= --tool 
$(ATPROGRAM_PROGRAMMER
) --interface 
$(ATPROGRAM_INTERFACE
) --device 
$(MCU
) 
  74 ifneq ($(ATPROGRAM_PORT
),) 
  75    BASE_ATPROGRAM_FLAGS 
+= --port 
$(ATPROGRAM_PORT
) 
  78 # Construct the flags to use for the various memory spaces 
  80    ATPROGRAM_FLASH_FLAGS  
:= --chiperase 
--flash
 
  81    ATPROGRAM_EEPROM_FLAGS 
:= --eeprom
 
  82 else ifeq ($(ARCH
), XMEGA
) 
  83    ATPROGRAM_FLASH_FLAGS  
:= --erase 
--flash
 
  84    ATPROGRAM_EEPROM_FLAGS 
:= --eeprom
 
  85 else ifeq ($(ARCH
), UC3
) 
  86    ATPROGRAM_FLASH_FLAGS  
:= --erase
 
  87    ATPROGRAM_EEPROM_FLAGS 
:= --eeprom
 
  89    $(error Unsupported architecture 
"$(ARCH)") 
  92 # Programs in the target FLASH memory using ATPROGRAM 
  93 atprogram
: $(TARGET
).elf 
$(MAKEFILE_LIST
) 
  94         @echo 
$(MSG_ATPROGRAM_CMD
) Programming device 
\"$(MCU
)\" FLASH using 
\"$(ATPROGRAM_PROGRAMMER
)\" 
  95         atprogram 
$(BASE_ATPROGRAM_FLAGS
) program 
$(ATPROGRAM_FLASH_FLAGS
) --file 
$< 
  97 # Programs in the target EEPROM memory using ATPROGRAM 
  98 atprogram-ee
: $(TARGET
).elf 
$(MAKEFILE_LIST
) 
  99         @echo 
$(MSG_ATPROGRAM_CMD
) Programming device 
\"$(MCU
)\" EEPROM using 
\"$(ATPROGRAM_PROGRAMMER
)\" 
 100         atprogram 
$(BASE_ATPROGRAM_FLAGS
) program 
$(ATPROGRAM_EEPROM_FLAGS
) --file 
$< 
 102 # Phony build targets for this module 
 103 .PHONY
: atprogram atprogram-ee