Makefile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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_MEGA/board.mk
  75. include $(CHIBIOS)/os/hal/ports/AVR/MEGA/ATMEGAxx/platform.mk
  76. include $(CHIBIOS)/os/hal/osal/nil/osal.mk
  77. # RTOS files (optional).
  78. include $(CHIBIOS)/os/nil/nil.mk
  79. include $(CHIBIOS)/os/common/ports/AVR/compilers/GCC/mk/port.mk
  80. # Other files (optional).
  81. include $(CHIBIOS)/test/lib/test.mk
  82. include $(CHIBIOS)/test/nil/nil_test.mk
  83. # List C source files here. (C dependencies are automatically generated.)
  84. CSRC = $(ALLCSRC) \
  85. $(TESTSRC) \
  86. main.c
  87. # List C++ sources file here.
  88. CPPSRC = $(ALLCPPSRC)
  89. INCDIR = $(ALLINC) $(TESTINC)
  90. #
  91. # Project, sources and paths.
  92. ##############################################################################
  93. ##############################################################################
  94. # Compiler settings.
  95. #
  96. # Micro-Controller Unit.
  97. MCU = atmega2560
  98. # MCU frequency (Hz).
  99. F_CPU=16000000
  100. # Output format. (can be srec, ihex, binary)
  101. FORMAT=ihex
  102. # C and C++ Compiler name.
  103. TRGT=avr-
  104. CC=$(TRGT)gcc
  105. CPPC=$(TRGT)g++
  106. # Enable loading with g++ only if you need C++ runtime support.
  107. # NOTE: You can use C++ even without C++ support if you are careful. C++
  108. # runtime support makes code size explode.
  109. LD = $(TRGT)gcc
  110. CP = $(TRGT)objcopy
  111. AR = $(TRGT)ar rcs
  112. OD = $(TRGT)objdump
  113. NM = $(TRGT)nm
  114. SZ = $(TRGT)size
  115. HEX = $(CP) -O ihex
  116. BIN = $(CP) -O binary
  117. # AVR programming tool.
  118. AVRDUDE = avrdude
  119. # Size of the elf binary file.
  120. ELFSIZE = $(SZ) --mcu=$(MCU) --format=avr $(BUILDDIR)/$(PROJECT).elf
  121. # MCU specific options here.
  122. MOPT =
  123. # Define C warning options here.
  124. CWARN = -Wall -Wstrict-prototypes
  125. # Define C++ warning options here.
  126. CPPWARN =
  127. #
  128. # Compiler settings.
  129. ##############################################################################
  130. ##############################################################################
  131. # Start of user section.
  132. #
  133. # List all user C define here, like -D_DEBUG=1.
  134. UDEFS =
  135. # Define ASM defines here.
  136. UADEFS =
  137. # List all user directories here.
  138. UINCDIR =
  139. # List the user directory to look for the libraries here.
  140. ULIBDIR =
  141. # List all user libraries here.
  142. ULIBS =
  143. #
  144. # End of user defines.
  145. ##############################################################################
  146. ##############################################################################
  147. # Start of programming Options.
  148. #
  149. # List of available AVR programmer.
  150. AVRDUDE_PROGRAMMER = avrdude
  151. AVRDUDE_PROGRAMMER_ID = wiring
  152. DFU_PROGRAMMER = dfu-programmer
  153. MICRONUCLEUS = micronucleus
  154. # Set the AVR programmer according to the selection..
  155. ifeq ($(USE_AVRDUDE_PROGRAMMER),yes)
  156. AVR_PROGRAMMER = $(AVRDUDE_PROGRAMMER)
  157. else ifeq ($(USE_DFU_PROGRAMMER),yes)
  158. AVR_PROGRAMMER = $(DFU_PROGRAMMER)
  159. else ifeq ($(USE_MICRONUCLEUS_PROGRAMMER),yes)
  160. AVR_PROGRAMMER = $(MICRONUCLEUS_PROGRAMMER)
  161. else
  162. $(error ERROR: Please you need to configure the AVR programmer!)
  163. endif
  164. # AVR serial port.
  165. AVRDUDE_PORT = /dev/ttyUSB0
  166. AVRDUDE_WRITE_FLASH = -D -U flash:w:$(BUILDDIR)/$(PROJECT).hex
  167. # Check if the counter cycle erase must be performed after device programming.
  168. ifeq ($(USE_AVRDUDE_ERASE_COUNTER),yes)
  169. AVRDUDE_ERASE_COUNTER = -y
  170. endif
  171. # Check if a verification must be performed after device programming.
  172. ifeq ($(USE_AVRDUDE_NO_VERIFY),no)
  173. AVRDUDE_NO_VERIFY = -V
  174. endif
  175. # Check verbosity level activation.
  176. ifeq ($(USE_VERBOSE_PROGRAMMATION),yes)
  177. AVRDUDE_VERBOSE = -v -v
  178. endif
  179. # AVR programmer flags for AVRDUDE programmer.
  180. ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
  181. AVRDUDE_FLAGS = -p $(MCU)
  182. AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
  183. AVRDUDE_FLAGS += -b 115200
  184. AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER_ID)
  185. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  186. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  187. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  188. endif
  189. # AVR programmer flags for DFU programmer.
  190. ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
  191. DFU_WRITE_FLASH = flash --force
  192. DFU_ERASE_FLASH = erase
  193. DFU_RESET=reset
  194. endif
  195. # AVR programmer flags for MICRONUCLEUS programmer.
  196. ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
  197. MICRONUCLEUS_TIMEOUT_ARG = --timeout 60
  198. MICRONUCLEUS_RUN_ARG = --run
  199. MICRONUCLEUS_TYPE_ARG = --type raw
  200. MICRONUCLEUS_DUMP_PROGRESS = --dump-progress
  201. MICRONUCLEUS_FLAGS=$(MICRONUCLEUS_TYPE_ARG)
  202. MICRONUCLEUS_FLAGS+=$(MICRONUCLEUS_TIMEOUT_ARG)
  203. MICRONUCLEUS_FLAGS+=$(MICRONUCLEUS_RUN_ARG)
  204. endif
  205. #
  206. # End of Programming Options.
  207. ##############################################################################
  208. ##############################################################################
  209. # Include file.
  210. #
  211. RULESPATH = $(CHIBIOS)/os/common/ports/AVR/compilers/GCC
  212. include $(RULESPATH)/rules.mk
  213. #
  214. # End of include file.
  215. ##############################################################################
  216. ##############################################################################
  217. # Programming rules
  218. #
  219. # AVRDUDE programming rules.
  220. ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
  221. program: $(BUILDDIR)/$(PROJECT).hex
  222. @echo
  223. @echo Programming $(MCU) device.
  224. $(AVR_PROGRAMMER) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $<
  225. @echo Done.
  226. endif
  227. # DFU programming rules.
  228. ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
  229. program: $(BUILDDIR)/$(PROJECT).hex
  230. @echo
  231. @echo Programming $(MCU) device.
  232. $(AVR_PROGRAMMER) $(MCU) $(DFU_WRITE_FLASH) $<
  233. $(AVR_PROGRAMMER) $(MCU) $(DFU_RESET)
  234. @echo Done.
  235. erase:
  236. @echo
  237. @echo Erasing $(MCU) device.
  238. $(AVR_PROGRAMMER) $(MCU) $(DFU_ERASE_FLASH)
  239. @echo Done.
  240. endif
  241. # MICRONUCLEUS programming rules.
  242. ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
  243. program: $(BUILDDIR)/$(PROJECT).bin
  244. @echo
  245. @echo Programming $(MCU) device.
  246. $(AVR_PROGRAMMER) $(MICRONUCLEUS_FLAGS) $<
  247. @echo Done.
  248. endif
  249. #
  250. # End of programming rules.
  251. ##############################################################################
  252. # EOF