Makefile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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/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. # Other files (optional).
  81. include $(CHIBIOS)/test/lib/test.mk
  82. include $(CHIBIOS)/test/oslib/oslib_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. # Size of the elf binary file.
  118. ELFSIZE = $(SZ) --mcu=$(MCU) --format=avr $(BUILDDIR)/$(PROJECT).elf
  119. # MCU specific options here.
  120. MOPT =
  121. # Define C warning options here.
  122. CWARN = -Wall -Wstrict-prototypes
  123. # Define C++ warning options here.
  124. CPPWARN =
  125. #
  126. # Compiler settings.
  127. ##############################################################################
  128. ##############################################################################
  129. # Start of user section.
  130. #
  131. # List all user C define here, like -D_DEBUG=1.
  132. UDEFS =
  133. # Define ASM defines here.
  134. UADEFS =
  135. # List all user directories here.
  136. UINCDIR =
  137. # List the user directory to look for the libraries here.
  138. ULIBDIR =
  139. # List all user libraries here.
  140. ULIBS =
  141. #
  142. # End of user defines.
  143. ##############################################################################
  144. ##############################################################################
  145. # Start of programming Options.
  146. #
  147. # List of available AVR programmer.
  148. AVRDUDE_PROGRAMMER = avrdude
  149. AVRDUDE_PROGRAMMER_ID = wiring
  150. DFU_PROGRAMMER = dfu-programmer
  151. MICRONUCLEUS = micronucleus
  152. # Set the AVR programmer according to the selection..
  153. ifeq ($(USE_AVRDUDE_PROGRAMMER),yes)
  154. AVR_PROGRAMMER = $(AVRDUDE_PROGRAMMER)
  155. else ifeq ($(USE_DFU_PROGRAMMER),yes)
  156. AVR_PROGRAMMER = $(DFU_PROGRAMMER)
  157. else ifeq ($(USE_MICRONUCLEUS_PROGRAMMER),yes)
  158. AVR_PROGRAMMER = $(MICRONUCLEUS_PROGRAMMER)
  159. else
  160. $(error ERROR: Please you need to configure the AVR programmer!)
  161. endif
  162. # AVR serial port.
  163. AVRDUDE_PORT = /dev/ttyUSB0
  164. AVRDUDE_WRITE_FLASH = -D -U flash:w:$(BUILDDIR)/$(PROJECT).hex
  165. # Check if the counter cycle erase must be performed after device programming.
  166. ifeq ($(USE_AVRDUDE_ERASE_COUNTER),yes)
  167. AVRDUDE_ERASE_COUNTER = -y
  168. endif
  169. # Check if a verification must be performed after device programming.
  170. ifeq ($(USE_AVRDUDE_NO_VERIFY),no)
  171. AVRDUDE_NO_VERIFY = -V
  172. endif
  173. # Check verbosity level activation.
  174. ifeq ($(USE_VERBOSE_PROGRAMMATION),yes)
  175. AVRDUDE_VERBOSE = -v -v
  176. endif
  177. # AVR programmer flags for AVRDUDE programmer.
  178. ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
  179. AVRDUDE_FLAGS = -p $(MCU)
  180. AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
  181. AVRDUDE_FLAGS += -b 115200
  182. AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER_ID)
  183. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  184. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  185. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  186. endif
  187. # AVR programmer flags for DFU programmer.
  188. ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
  189. DFU_WRITE_FLASH = flash --force
  190. DFU_ERASE_FLASH = erase
  191. DFU_RESET=reset
  192. endif
  193. # AVR programmer flags for MICRONUCLEUS programmer.
  194. ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
  195. MICRONUCLEUS_TIMEOUT_ARG = --timeout 60
  196. MICRONUCLEUS_RUN_ARG = --run
  197. MICRONUCLEUS_TYPE_ARG = --type raw
  198. MICRONUCLEUS_DUMP_PROGRESS = --dump-progress
  199. MICRONUCLEUS_FLAGS=$(MICRONUCLEUS_TYPE_ARG)
  200. MICRONUCLEUS_FLAGS+=$(MICRONUCLEUS_TIMEOUT_ARG)
  201. MICRONUCLEUS_FLAGS+=$(MICRONUCLEUS_RUN_ARG)
  202. endif
  203. #
  204. # End of Programming Options.
  205. ##############################################################################
  206. ##############################################################################
  207. # Include file.
  208. #
  209. RULESPATH = $(CHIBIOS)/os/common/ports/AVR/compilers/GCC
  210. include $(RULESPATH)/rules.mk
  211. #
  212. # End of include file.
  213. ##############################################################################
  214. ##############################################################################
  215. # Programming rules
  216. #
  217. # AVRDUDE programming rules.
  218. ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
  219. program: $(BUILDDIR)/$(PROJECT).hex
  220. @echo
  221. @echo Programming $(MCU) device.
  222. $(AVR_PROGRAMMER) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $<
  223. @echo Done.
  224. endif
  225. # DFU programming rules.
  226. ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
  227. program: $(BUILDDIR)/$(PROJECT).hex
  228. @echo
  229. @echo Programming $(MCU) device.
  230. $(AVR_PROGRAMMER) $(MCU) $(DFU_WRITE_FLASH) $<
  231. $(AVR_PROGRAMMER) $(MCU) $(DFU_RESET)
  232. @echo Done.
  233. erase:
  234. @echo
  235. @echo Erasing $(MCU) device.
  236. $(AVR_PROGRAMMER) $(MCU) $(DFU_ERASE_FLASH)
  237. @echo Done.
  238. endif
  239. # MICRONUCLEUS programming rules.
  240. ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
  241. program: $(BUILDDIR)/$(PROJECT).bin
  242. @echo
  243. @echo Programming $(MCU) device.
  244. $(AVR_PROGRAMMER) $(MICRONUCLEUS_FLAGS) $<
  245. @echo Done.
  246. endif
  247. #
  248. # End of programming rules.
  249. ##############################################################################
  250. # EOF