Makefile 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. ##############################################################################
  2. #
  3. # @file Makefile.
  4. #
  5. # @brief AVR Make file, it can be use to build, and program an application to
  6. # an AVR MCU like atmega328p, atmega2560 and so on.
  7. #
  8. # @author Theodore Ateba, tf.ateba@gmail.com
  9. #
  10. ##############################################################################
  11. ##############################################################################
  12. # Building and programming global options.
  13. # NOTE: Can be overridden externally.
  14. #
  15. # Compiler options here.
  16. ifeq ($(USE_OPT),)
  17. USE_OPT = -O2
  18. endif
  19. # C specific options here (added to USE_OPT).
  20. ifeq ($(USE_COPT),)
  21. USE_COPT =
  22. endif
  23. # C++ specific options here (added to USE_OPT).
  24. ifeq ($(USE_CPPOPT),)
  25. USE_CPPOPT =
  26. endif
  27. # Enable this if you want to see the full log while compiling.
  28. ifeq ($(USE_VERBOSE_COMPILE),)
  29. USE_VERBOSE_COMPILE = no
  30. endif
  31. # If enabled, this option makes the build process faster by not compiling
  32. # modules not used in the current configuration.
  33. ifeq ($(USE_SMART_BUILD),)
  34. USE_SMART_BUILD = yes
  35. endif
  36. # If enable, this option arase the counter cycle after device programming.
  37. ifeq ($(USE_AVRDUDE_ERASE_COUNTER),)
  38. USE_AVRDUDE_ERASE_COUNTER = no
  39. endif
  40. # If enable, this option perform a verification after device programming.
  41. ifeq ($(USE_AVRDUDE_NO_VERIFY),)
  42. USE_AVRDUDE_NO_VERIFY = no
  43. endif
  44. # If enabled, this option increase the programming verbosity level.
  45. ifeq ($(USE_VERBOSE_PROGRAMMATION),)
  46. USE_VERBOSE_PROGRAMMATION = no
  47. endif
  48. # Enable this if you want to use AVRDUDE programmer.
  49. ifeq ($(USE_AVRDUDE_PROGRAMMER),)
  50. USE_AVRDUDE_PROGRAMMER = yes
  51. endif
  52. # Enable this if you want to use DFU programmer.
  53. ifeq ($(USE_DFU_PROGRAMMER),)
  54. USE_DFU_PROGRAMMER = no
  55. endif
  56. # Enable this if you want to use MICRONUCLEUS programmer.
  57. ifeq ($(USE_MICRONUCLEUS_PROGRAMMER),)
  58. USE_MICRONUCLEUS_PROGRAMMER = no
  59. endif
  60. #
  61. # Building and programming global options.
  62. ##############################################################################
  63. ##############################################################################
  64. # Project, sources and paths.
  65. #
  66. # Define project name here.
  67. PROJECT = ch
  68. # Imported source files and paths
  69. CHIBIOS = ../../..
  70. # Licensing files.
  71. include $(CHIBIOS)/os/license/license.mk
  72. # HAL-OSAL files (optional).
  73. include $(CHIBIOS)/os/hal/hal.mk
  74. include $(CHIBIOS)/os/hal/boards/ARDUINO_LEONARDO/board.mk
  75. include $(CHIBIOS)/os/hal/ports/AVR/MEGA/ATMEGAxx/platform.mk
  76. include $(CHIBIOS)/os/hal/osal/rt/osal.mk
  77. # RTOS files (optional).
  78. include $(CHIBIOS)/os/rt/rt.mk
  79. include $(CHIBIOS)/os/common/ports/AVR/compilers/GCC/mk/port.mk
  80. # List C source files here. (C dependencies are automatically generated.)
  81. CSRC = $(ALLCSRC) \
  82. usbcfg.c \
  83. main.c
  84. # List C++ sources file here.
  85. CPPSRC = $(ALLCPPSRC)
  86. # Header files here.
  87. INCDIR = $(ALLINC)
  88. #
  89. # Project, sources and paths.
  90. ##############################################################################
  91. ##############################################################################
  92. # Compiler settings.
  93. #
  94. # Micro-Controller Unit.
  95. MCU = atmega32u4
  96. # MCU frequency (Hz).
  97. F_CPU = 16000000
  98. # Output format. (can be srec, ihex, binary)
  99. FORMAT = ihex
  100. # C and C++ Compiler name.
  101. TRGT = avr-
  102. CC = $(TRGT)gcc
  103. CPPC = $(TRGT)g++
  104. # Enable loading with g++ only if you need C++ runtime support.
  105. # NOTE: You can use C++ even without C++ support if you are careful. C++
  106. # runtime support makes code size explode.
  107. LD = $(TRGT)gcc
  108. CP = $(TRGT)objcopy
  109. AR = $(TRGT)ar rcs
  110. OD = $(TRGT)objdump
  111. NM = $(TRGT)nm
  112. SZ = $(TRGT)size
  113. HEX = $(CP) -O ihex
  114. BIN = $(CP) -O binary
  115. # Size of the elf binary file.
  116. ELFSIZE = $(SZ) --mcu=$(MCU) --format=avr $(BUILDDIR)/$(PROJECT).elf
  117. # MCU specific options here.
  118. MOPT =
  119. # Define C warning options here.
  120. CWARN = -Wall -Wstrict-prototypes
  121. # Define C++ warning options here.
  122. CPPWARN =
  123. #
  124. # Compiler settings.
  125. ##############################################################################
  126. ##############################################################################
  127. # Start of user section.
  128. #
  129. # List all user C define here, like -D_DEBUG=1.
  130. UDEFS =
  131. # Define ASM defines here.
  132. UADEFS =
  133. # List all user directories here.
  134. UINCDIR =
  135. # List the user directory to look for the libraries here.
  136. ULIBDIR =
  137. # List all user libraries here.
  138. ULIBS =
  139. #
  140. # End of user defines.
  141. ##############################################################################
  142. ##############################################################################
  143. # Start of programming Options.
  144. #
  145. # List of available AVR programmer.
  146. AVRDUDE_PROGRAMMER = avrdude
  147. AVRDUDE_PROGRAMMER_ID = avr109
  148. DFU_PROGRAMMER = dfu-programmer
  149. MICRONUCLEUS = micronucleus
  150. # Set the AVR programmer according to the selection..
  151. ifeq ($(USE_AVRDUDE_PROGRAMMER),yes)
  152. AVR_PROGRAMMER = $(AVRDUDE_PROGRAMMER)
  153. else ifeq ($(USE_DFU_PROGRAMMER),yes)
  154. AVR_PROGRAMMER = $(DFU_PROGRAMMER)
  155. else ifeq ($(USE_MICRONUCLEUS_PROGRAMMER),yes)
  156. AVR_PROGRAMMER = $(MICRONUCLEUS_PROGRAMMER)
  157. else
  158. $(error ERROR: Please you need to configure the AVR programmer!)
  159. endif
  160. # AVR serial port.
  161. AVRDUDE_PORT = /dev/ttyACM0
  162. AVRDUDE_WRITE_FLASH = -D -Uflash:w:$(BUILDDIR)/$(PROJECT).hex
  163. # Check if the counter cycle erase must be performed after device programming.
  164. ifeq ($(USE_AVRDUDE_ERASE_COUNTER),yes)
  165. AVRDUDE_ERASE_COUNTER = -y
  166. endif
  167. # Check if a verification must be performed after device programming.
  168. ifeq ($(USE_AVRDUDE_NO_VERIFY),no)
  169. AVRDUDE_NO_VERIFY = -V
  170. endif
  171. # Check verbosity level activation.
  172. ifeq ($(USE_VERBOSE_PROGRAMMATION),yes)
  173. AVRDUDE_VERBOSE = -v -v
  174. endif
  175. # AVR programmer flags for AVRDUDE programmer.
  176. ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
  177. AVRDUDE_FLAGS = -p $(MCU)
  178. AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
  179. AVRDUDE_FLAGS += -b 57600
  180. AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER_ID)
  181. AVRDUDE_FLAGS +=$(AVRDUDE_NO_VERIFY)
  182. AVRDUDE_FLAGS +=$(AVRDUDE_VERBOSE)
  183. AVRDUDE_FLAGS +=$(AVRDUDE_ERASE_COUNTER)
  184. endif
  185. # AVR programmer flags for DFU programmer.
  186. ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
  187. DFU_WRITE_FLASH = flash --force
  188. DFU_ERASE_FLASH = erase
  189. DFU_RESET = reset
  190. endif
  191. # AVR programmer flags for MICRONUCLEUS programmer.
  192. ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
  193. MICRONUCLEUS_TIMEOUT_ARG = --timeout 60
  194. MICRONUCLEUS_RUN_ARG = --run
  195. MICRONUCLEUS_TYPE_ARG = --type raw
  196. MICRONUCLEUS_DUMP_PROGRESS = --dump-progress
  197. MICRONUCLEUS_FLAGS = $(MICRONUCLEUS_TYPE_ARG)
  198. MICRONUCLEUS_FLAGS += $(MICRONUCLEUS_TIMEOUT_ARG)
  199. MICRONUCLEUS_FLAGS += $(MICRONUCLEUS_RUN_ARG)
  200. endif
  201. #
  202. # End of Programming Options.
  203. ##############################################################################
  204. ##############################################################################
  205. # Include file.
  206. #
  207. RULESPATH = $(CHIBIOS)/os/common/ports/AVR/compilers/GCC
  208. include $(RULESPATH)/rules.mk
  209. #
  210. # End of include file.
  211. ##############################################################################
  212. ##############################################################################
  213. # Programming rules
  214. #
  215. # AVRDUDE programming rules.
  216. ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
  217. program: $(BUILDDIR)/$(PROJECT).hex
  218. @echo
  219. @echo Programming $(MCU) device.
  220. $(AVR_PROGRAMMER) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
  221. @echo Done.
  222. endif
  223. # DFU programming rules.
  224. ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
  225. program: $(BUILDDIR)/$(PROJECT).hex
  226. @echo
  227. @echo Programming $(MCU) device.
  228. $(AVR_PROGRAMMER) $(MCU) $(DFU_WRITE_FLASH) $<
  229. $(AVR_PROGRAMMER) $(MCU) $(DFU_RESET)
  230. @echo Done.
  231. erase:
  232. @echo
  233. @echo Erasing $(MCU) device.
  234. $(AVR_PROGRAMMER) $(MCU) $(DFU_ERASE_FLASH)
  235. @echo Done.
  236. endif
  237. # MICRONUCLEUS programming rules.
  238. ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
  239. program: $(BUILDDIR)/$(PROJECT).bin
  240. @echo
  241. @echo Programming $(MCU) device.
  242. $(AVR_PROGRAMMER) $(MICRONUCLEUS_FLAGS) $<
  243. @echo Done.
  244. endif
  245. #
  246. # End of programming rules.
  247. ##############################################################################
  248. # EOF