3 # Released into the public domain.
5 # dean [at] fourwalledcubicle [dot] com
6 # www.fourwalledcubicle.com
9 DMBS_BUILD_MODULES
+= AVRDUDE
10 DMBS_BUILD_TARGETS
+= avrdude-lfuse avrdude-hfuse avrdude-efuse avrdude-lock avrdude-fuses
11 DMBS_BUILD_TARGETS
+= avrdude avrdude-ee avrdude-all avrdude-all-ee
12 DMBS_BUILD_MANDATORY_VARS
+= MCU TARGET
13 DMBS_BUILD_OPTIONAL_VARS
+= AVRDUDE_PROGRAMMER AVRDUDE_PORT AVRDUDE_FLAGS AVRDUDE_MEMORY AVRDUDE_BAUD
14 DMBS_BUILD_OPTIONAL_VARS
+= AVRDUDE_LFUSE AVRDUDE_HFUSE AVRDUDE_EUSE AVRDUDE_LOCK
15 DMBS_BUILD_PROVIDED_VARS
+=
16 DMBS_BUILD_PROVIDED_MACROS
+=
18 # Import the CORE module of DMBS
19 DMBS_MODULE_PATH
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
20 include $(DMBS_MODULE_PATH
)/core.mk
22 # Default values of optionally user-supplied variables
23 AVRDUDE_PROGRAMMER ?
= jtagicemkii
26 AVRDUDE_MEMORY ?
= flash
33 # Sanity check user supplied values
34 $(foreach MANDATORY_VAR
, $(DMBS_BUILD_MANDATORY_VARS
), $(call ERROR_IF_UNSET
, $(MANDATORY_VAR
)))
35 $(call ERROR_IF_EMPTY
, MCU
)
36 $(call ERROR_IF_EMPTY
, TARGET
)
37 $(call ERROR_IF_EMPTY
, AVRDUDE_PROGRAMMER
)
38 $(call ERROR_IF_EMPTY
, AVRDUDE_PORT
)
41 MSG_AVRDUDE_CMD
:= ' [AVRDUDE] :'
43 # Construct base avrdude command flags
44 BASE_AVRDUDE_FLAGS
:= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
45 ifneq ($(AVRDUDE_BAUD
),)
46 BASE_AVRDUDE_FLAGS
+= -b
$(AVRDUDE_BAUD
)
49 # Programs in the target FLASH memory using AVRDUDE
50 avrdude
: $(TARGET
).hex
$(MAKEFILE_LIST
)
51 @echo
$(MSG_AVRDUDE_CMD
) Programming device
\"$(MCU
)\" FLASH using
\"$(AVRDUDE_PROGRAMMER
)\" on port
\"$(AVRDUDE_PORT
)\"
52 avrdude
$(BASE_AVRDUDE_FLAGS
) -U
$(AVRDUDE_MEMORY
):w
:$< $(AVRDUDE_FLAGS
)
54 # Programs in the target EEPROM memory using AVRDUDE
55 avrdude-ee
: $(TARGET
).eep
$(MAKEFILE_LIST
)
56 @echo
$(MSG_AVRDUDE_CMD
) Programming device
\"$(MCU
)\" EEPROM using
\"$(AVRDUDE_PROGRAMMER
)\" on port
\"$(AVRDUDE_PORT
)\"
57 avrdude
$(BASE_AVRDUDE_FLAGS
) -U eeprom
:w
:$< $(AVRDUDE_FLAGS
)
59 # Programs in the target fuses using AVRDUDE
60 avrdude-lfuse
: $(MAKEFILE_LIST
)
61 @echo
$(MSG_AVRDUDE_CMD
) Programming device
\"$(MCU
)\" low fuse using
\"$(AVRDUDE_PROGRAMMER
)\" on port
\"$(AVRDUDE_PORT
)\"
62 $(call ERROR_IF_EMPTY
, AVRDUDE_LFUSE
)
63 avrdude
$(BASE_AVRDUDE_FLAGS
) -Ulfuse
:w
:$(AVRDUDE_LFUSE
):m
$(AVRDUDE_FLAGS
)
65 avrdude-hfuse
: $(MAKEFILE_LIST
)
66 @echo
$(MSG_AVRDUDE_CMD
) Programming device
\"$(MCU
)\" high fuse using
\"$(AVRDUDE_PROGRAMMER
)\" on port
\"$(AVRDUDE_PORT
)\"
67 $(call ERROR_IF_EMPTY
, AVRDUDE_HFUSE
)
68 avrdude
$(BASE_AVRDUDE_FLAGS
) -Uhfuse
:w
:$(AVRDUDE_HFUSE
):m
$(AVRDUDE_FLAGS
)
70 avrdude-efuse
: $(MAKEFILE_LIST
)
71 @echo
$(MSG_AVRDUDE_CMD
) Programming device
\"$(MCU
)\" extended fuse using
\"$(AVRDUDE_PROGRAMMER
)\" on port
\"$(AVRDUDE_PORT
)\"
72 $(call ERROR_IF_EMPTY
, AVRDUDE_EFUSE
)
73 avrdude
$(BASE_AVRDUDE_FLAGS
) -Uefuse
:w
:$(AVRDUDE_EFUSE
):m
$(AVRDUDE_FLAGS
)
75 avrdude-lock
: $(MAKEFILE_LIST
)
76 @echo
$(MSG_AVRDUDE_CMD
) Programming device
\"$(MCU
)\" lock bits using
\"$(AVRDUDE_PROGRAMMER
)\" on port
\"$(AVRDUDE_PORT
)\"
77 $(call ERROR_IF_EMPTY
, AVRDUDE_LOCK
)
78 avrdude
$(BASE_AVRDUDE_FLAGS
) -Ulock
:w
:$(AVRDUDE_LOCK
):m
$(AVRDUDE_FLAGS
)
80 avrdude-fuses
: avrdude-lfuse avrdude-hfuse avrdude-efuse avrdude-lock
82 avrdude-all
: avrdude avrdude-fuses
84 avrdude-all-ee
: avrdude avrdude-ee avrdude-fuses
86 # Phony build targets for this module
87 .PHONY
: $(DMBS_BUILD_TARGETS
)