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