3 # Released into the public domain.
5 # dean [at] fourwalledcubicle [dot] com
6 # www.fourwalledcubicle.com
9 DMBS_BUILD_MODULES
+= ATPROGRAM
10 DMBS_BUILD_TARGETS
+= atprogram atprogram-ee
11 DMBS_BUILD_MANDATORY_VARS
+= MCU TARGET
12 DMBS_BUILD_OPTIONAL_VARS
+= ATPROGRAM_PROGRAMMER ATPROGRAM_INTERFACE ATPROGRAM_PORT
13 DMBS_BUILD_PROVIDED_VARS
+=
14 DMBS_BUILD_PROVIDED_MACROS
+=
18 ERROR_IF_UNSET ?
= $(if
$(filter undefined
, $(origin $(strip $(1)))), $(error Makefile
$(strip $(1)) value not set
))
19 ERROR_IF_EMPTY ?
= $(if
$(strip $($(strip $(1)))), , $(error Makefile
$(strip $(1)) option cannot be blank
))
20 ERROR_IF_NONBOOL ?
= $(if
$(filter Y N
, $($(strip $(1)))), , $(error Makefile
$(strip $(1)) option must be Y or N
))
22 # Default values of optionally user-supplied variables
23 ATPROGRAM_PROGRAMMER ?
= atmelice
24 ATPROGRAM_INTERFACE ?
= jtag
27 # Sanity check user supplied values
28 $(foreach MANDATORY_VAR
, $(DMBS_BUILD_MANDATORY_VARS
), $(call ERROR_IF_UNSET
, $(MANDATORY_VAR
)))
29 $(call ERROR_IF_EMPTY
, MCU
)
30 $(call ERROR_IF_EMPTY
, TARGET
)
31 $(call ERROR_IF_EMPTY
, ATPROGRAM_PROGRAMMER
)
32 $(call ERROR_IF_EMPTY
, ATPROGRAM_INTERFACE
)
35 MSG_ATPROGRAM_CMD
:= ' [ATPRGRM] :'
37 # Construct base atprogram command flags
38 BASE_ATPROGRAM_FLAGS
:= --tool
$(ATPROGRAM_PROGRAMMER
) --interface
$(ATPROGRAM_INTERFACE
) --device
$(MCU
)
39 ifneq ($(ATPROGRAM_PORT
),)
40 BASE_ATPROGRAM_FLAGS
+= --port
$(ATPROGRAM_PORT
)
43 # Construct the flags to use for the various memory spaces
45 ATPROGRAM_FLASH_FLAGS
:= --chiperase
--flash
46 ATPROGRAM_EEPROM_FLAGS
:= --eeprom
47 else ifeq ($(ARCH
), XMEGA
)
48 ATPROGRAM_FLASH_FLAGS
:= --erase
--flash
49 ATPROGRAM_EEPROM_FLAGS
:= --eeprom
50 else ifeq ($(ARCH
), UC3
)
51 ATPROGRAM_FLASH_FLAGS
:= --erase
52 ATPROGRAM_EEPROM_FLAGS
:= --eeprom
54 $(error Unsupported architecture
"$(ARCH)")
57 # Programs in the target FLASH memory using ATPROGRAM
58 atprogram
: $(TARGET
).elf
$(MAKEFILE_LIST
)
59 @echo
$(MSG_ATPROGRAM_CMD
) Programming device
\"$(MCU
)\" FLASH using
\"$(ATPROGRAM_PROGRAMMER
)\"
60 atprogram
$(BASE_ATPROGRAM_FLAGS
) program
$(ATPROGRAM_FLASH_FLAGS
) --file
$<
62 # Programs in the target EEPROM memory using ATPROGRAM
63 atprogram-ee
: $(TARGET
).elf
$(MAKEFILE_LIST
)
64 @echo
$(MSG_ATPROGRAM_CMD
) Programming device
\"$(MCU
)\" EEPROM using
\"$(ATPROGRAM_PROGRAMMER
)\"
65 atprogram
$(BASE_ATPROGRAM_FLAGS
) program
$(ATPROGRAM_EEPROM_FLAGS
) --file
$<
67 # Phony build targets for this module
68 .PHONY
: $(DMBS_BUILD_TARGETS
)