Add Build System documentation to the library manual. Update CPPCHECK build system...
[pub/USBasp.git] / LUFA / Build / lufa.atprogram.in
1 #
2 # LUFA Library
3 # Copyright (C) Dean Camera, 2012.
4 #
5 # dean [at] fourwalledcubicle [dot] com
6 # www.lufa-lib.org
7 #
8
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
14 # -----------------------------------------------------------------------------
15 # LUFA ATPROGRAM Programmer Buildsystem Makefile Module.
16 # -----------------------------------------------------------------------------
17 # DESCRIPTION:
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 # -----------------------------------------------------------------------------
21 # TARGETS:
22 #
23 # atprogram - Program target FLASH with application using
24 # atprogram
25 # atprogram-ee - Program target EEPROM with application data
26 # using atprogram
27 #
28 # MANDATORY PARAMETERS:
29 #
30 # MCU - Microcontroller device model name
31 # TARGET - Application name
32 #
33 # OPTIONAL PARAMETERS:
34 #
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
38 #
39 # -----------------------------------------------------------------------------
40
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))
44
45 # Default values of optionally user-supplied variables
46 ATPROGRAM_PROGRAMMER ?= jtagice3
47 ATPROGRAM_INTERFACE ?= jtag
48 ATPROGRAM_PORT ?=
49
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)
56
57 # Output Messages
58 MSG_ATPROGRAM_CMD := ' [ATPRGRM] :'
59
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)
64 endif
65
66 # Construct the flags to use for the various memory spaces
67 ifeq ($(ARCH), AVR8)
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
76 else
77 $(error Unsupported architecture "$(ARCH)")
78 endif
79
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 $<
83
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 $<
87
88 # Phony build targets for this module
89 .PHONY: atprogram atprogram-ee