upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

lufa_atprogram.mk 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #
  2. # LUFA Library
  3. # Copyright (C) Dean Camera, 2014.
  4. #
  5. # dean [at] fourwalledcubicle [dot] com
  6. # www.lufa-lib.org
  7. #
  8. LUFA_BUILD_MODULES += ATPROGRAM
  9. LUFA_BUILD_TARGETS += atprogram atprogram-ee
  10. LUFA_BUILD_MANDATORY_VARS += MCU TARGET
  11. LUFA_BUILD_OPTIONAL_VARS += ATPROGRAM_PROGRAMMER ATPROGRAM_INTERFACE ATPROGRAM_PORT
  12. LUFA_BUILD_PROVIDED_VARS +=
  13. LUFA_BUILD_PROVIDED_MACROS +=
  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. # PROVIDED VARIABLES:
  40. #
  41. # (None)
  42. #
  43. # PROVIDED MACROS:
  44. #
  45. # (None)
  46. #
  47. # -----------------------------------------------------------------------------
  48. SHELL = /bin/sh
  49. ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
  50. ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
  51. ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
  52. # Default values of optionally user-supplied variables
  53. ATPROGRAM_PROGRAMMER ?= jtagice3
  54. ATPROGRAM_INTERFACE ?= jtag
  55. ATPROGRAM_PORT ?=
  56. # Sanity check user supplied values
  57. $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
  58. $(call ERROR_IF_EMPTY, MCU)
  59. $(call ERROR_IF_EMPTY, TARGET)
  60. $(call ERROR_IF_EMPTY, ATPROGRAM_PROGRAMMER)
  61. $(call ERROR_IF_EMPTY, ATPROGRAM_INTERFACE)
  62. # Output Messages
  63. MSG_ATPROGRAM_CMD := ' [ATPRGRM] :'
  64. # Construct base atprogram command flags
  65. BASE_ATPROGRAM_FLAGS := --tool $(ATPROGRAM_PROGRAMMER) --interface $(ATPROGRAM_INTERFACE) --device $(MCU)
  66. ifneq ($(ATPROGRAM_PORT),)
  67. BASE_ATPROGRAM_FLAGS += --port $(ATPROGRAM_PORT)
  68. endif
  69. # Construct the flags to use for the various memory spaces
  70. ifeq ($(ARCH), AVR8)
  71. ATPROGRAM_FLASH_FLAGS := --chiperase --flash
  72. ATPROGRAM_EEPROM_FLAGS := --eeprom
  73. else ifeq ($(ARCH), XMEGA)
  74. ATPROGRAM_FLASH_FLAGS := --erase --flash
  75. ATPROGRAM_EEPROM_FLAGS := --eeprom
  76. else ifeq ($(ARCH), UC3)
  77. ATPROGRAM_FLASH_FLAGS := --erase
  78. ATPROGRAM_EEPROM_FLAGS := --eeprom
  79. else
  80. $(error Unsupported architecture "$(ARCH)")
  81. endif
  82. # Programs in the target FLASH memory using ATPROGRAM
  83. atprogram: $(TARGET).elf $(MAKEFILE_LIST)
  84. @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" FLASH using \"$(ATPROGRAM_PROGRAMMER)\"
  85. atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_FLASH_FLAGS) --file $<
  86. # Programs in the target EEPROM memory using ATPROGRAM
  87. atprogram-ee: $(TARGET).elf $(MAKEFILE_LIST)
  88. @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" EEPROM using \"$(ATPROGRAM_PROGRAMMER)\"
  89. atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_EEPROM_FLAGS) --file $<
  90. # Phony build targets for this module
  91. .PHONY: atprogram atprogram-ee