Makefile 7.9 KB

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