Makefile 7.9 KB

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