Makefile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #
  2. # Makefile
  3. #
  4. # (c) 2012-2020 by Markus Reschke
  5. # based on code from Markus Frejek and Karl-Heinz Kübbeler
  6. #
  7. PROJECT = ComponentTester
  8. #
  9. # MCU settings
  10. # - Change to fit your setup!
  11. #
  12. # avr-gcc: MCU model
  13. # - ATmega 328/328P : atmega328
  14. # - ATmega 324P/324PA : atmega324p
  15. # - ATmega 324PB : atmega328pb
  16. # - ATmega 644/644P/644PA : atmega644
  17. # - ATmega 1284/1284P : atmega1284
  18. MCU = atmega328
  19. # MCU freqency:
  20. # - 1MHz : 1
  21. # - 8MHz : 8
  22. # - 16MHz : 16
  23. # - 20MHz : 20
  24. FREQ = 16
  25. # oscillator type
  26. # - internal RC oscillator : RC
  27. # - external full swing crystal : Crystal
  28. # - external low power crystal : LowPower
  29. OSCILLATOR = Crystal
  30. # oscillator start-up cycles
  31. # - Crystal and LowPower could also be 1024 or 256 based on fuse settings
  32. ifeq (${OSCILLATOR},RC)
  33. OSC_STARTUP = 6
  34. endif
  35. ifeq (${OSCILLATOR},Crystal)
  36. OSC_STARTUP = 16384
  37. endif
  38. ifeq (${OSCILLATOR},LowPower)
  39. OSC_STARTUP = 16384
  40. endif
  41. # avrdude: part number of MCU
  42. # - ATmega 328 : m328
  43. # - ATmega 328P : m328p
  44. # - ATmega 328PB : m328pb
  45. # - ATmega 324P : m324p
  46. # - ATmega 324PA : m324pa
  47. # - ATmega 644 : m644
  48. # - ATmega 644P : m644p
  49. # - ATmega 644PA : m644p
  50. # - ATmega 1284 : m1284
  51. # - ATmega 1284P : m1284p
  52. PARTNO = m328p
  53. # avrdude: ISP programmer
  54. #PROGRAMMER = buspirate
  55. #PROGRAMMER = USBasp
  56. #PROGRAMMER = usbtiny
  57. #PROGRAMMER = stk500v2
  58. PROGRAMMER = avrispmkII
  59. # avrdude: port of ISP programmer
  60. #PORT = /dev/bus_pirate
  61. #PORT = /dev/ttyACM0
  62. PORT = usb
  63. # avrdude: bitclock
  64. BITCLOCK = 5.0
  65. #BITCLOCK = 10.0
  66. #
  67. # global settings
  68. #
  69. # project name
  70. NAME = ComponentTester
  71. # name and version based on directory name
  72. DIST = $(notdir ${CURDIR})
  73. # compiler flags
  74. CC = avr-gcc
  75. CPP = avr-g++
  76. CFLAGS = -mmcu=${MCU} -Wall -mcall-prologues -I. -Ibitmaps
  77. CFLAGS += -DF_CPU=${FREQ}000000UL
  78. CFLAGS += -DOSC_STARTUP=${OSC_STARTUP}
  79. CFLAGS += -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  80. CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
  81. #CFLAGS += -flto
  82. # linker flags
  83. LDFLAGS = -mmcu=${MCU} -Wl,-Map=${NAME}.map
  84. # hex file flags
  85. HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
  86. HEX_EEPROM_FLAGS = -j .eeprom
  87. HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
  88. HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
  89. # header files
  90. HEADERS = config.h config_328.h config_644.h colors.h
  91. HEADERS += common.h variables.h $(wildcard var_*.h) functions.h
  92. HEADERS += OneWire.h
  93. HEADERS += HD44780.h ST7565R.h ILI9341.h PCD8544.h ST7735.h ST7920.h
  94. HEADERS += SSD1306.h ILI9163.h STE2007.h PCF8814.h ST7036.h ADS7843.h
  95. # objects
  96. OBJECTS_C = main.o user.o pause.o adjust.o ADC.o probes.o display.o
  97. OBJECTS_C += resistor.o cap.o semi.o inductor.o tools_misc.o tools_signal.o
  98. OBJECTS_C += SPI.o I2C.o serial.o commands.o OneWire.o
  99. OBJECTS_C += IR_RX.o IR_TX.o DHTxx.o
  100. OBJECTS_C += HD44780.o ST7565R.o ILI9341.o PCD8544.o ST7735.o ST7920.o
  101. OBJECTS_C += SSD1306.o ILI9163.o STE2007.o PCF8814.o ST7036.o VT100.o
  102. OBJECTS_C += ADS7843.o
  103. OBJECTS_S = wait.o
  104. OBJECTS = ${OBJECTS_C} ${OBJECTS_S}
  105. #
  106. # build
  107. #
  108. all: ${NAME} ${NAME}.hex ${NAME}.eep ${NAME}.lss size
  109. #
  110. # link
  111. #
  112. # link firmware
  113. $(NAME): ${OBJECTS}
  114. ${CC} ${LDFLAGS} ${OBJECTS} ${LIBDIRS} ${LIBS} -o ${NAME}
  115. # create hex file of firmware
  116. %.hex: ${NAME}
  117. avr-objcopy -O ihex ${HEX_FLASH_FLAGS} $< $@
  118. # create hex file of EEPROM data
  119. %.eep: ${NAME}
  120. -avr-objcopy ${HEX_EEPROM_FLAGS} -O ihex $< $@ || exit 0
  121. # create dump of firmware
  122. %.lss: ${NAME}
  123. avr-objdump -h -S $< > $@
  124. # output size of firmware and stuff
  125. size: ${NAME}
  126. @echo
  127. @avr-size -C --mcu=${MCU} $<
  128. #
  129. # compile source files
  130. #
  131. # rule for all c-files
  132. ${OBJECTS_C}: %.o: %.c ${HEADERS} ${MAKEFILE_LIST}
  133. ${CC} ${CFLAGS} -c ${@:.o=.c}
  134. # rule for all S-files
  135. ${OBJECTS_S}: %.o: %.S ${HEADERS} ${MAKEFILE_LIST}
  136. ${CC} ${CFLAGS} -c ${@:.o=.S}
  137. # external dependencies
  138. -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
  139. #
  140. # extras
  141. #
  142. # program firmware and EEPROM data
  143. upload: ${NAME} ${NAME}.hex ${NAME}.eep ${NAME}.lss size
  144. avrdude -c ${PROGRAMMER} -B ${BITCLOCK} -p ${PARTNO} -P ${PORT} \
  145. -U flash:w:./${NAME}.hex:a -U eeprom:w:./${NAME}.eep:a
  146. # program firmware only
  147. prog_fw: ${NAME} ${NAME}.hex ${NAME}.lss size
  148. avrdude -c ${PROGRAMMER} -B ${BITCLOCK} -p ${PARTNO} -P ${PORT} \
  149. -U flash:w:./${NAME}.hex:a
  150. # program EEPROM data only
  151. prog_ee: ${NAME} ${NAME}.eep ${NAME}.lss size
  152. avrdude -c ${PROGRAMMER} -B ${BITCLOCK} -p ${PARTNO} -P ${PORT} \
  153. -U eeprom:w:./${NAME}.eep:a
  154. # create distribution package
  155. dist:
  156. rm -f *.tgz
  157. cd ..; tar -czf ${DIST}/${DIST}.tgz \
  158. ${DIST}/*.h ${DIST}/*.c ${DIST}/*.S ${DIST}/bitmaps/*.h \
  159. ${DIST}/Makefile ${DIST}/README ${DIST}/CHANGES \
  160. ${DIST}/README.de ${DIST}/CHANGES.de ${DIST}/Clones \
  161. ${DIST}/*.pdf
  162. # clean up
  163. clean:
  164. -rm -rf ${OBJECTS} ${NAME} dep/* *.tgz
  165. -rm -rf ${NAME}.hex ${NAME}.eep ${NAME}.lss ${NAME}.map
  166. #
  167. # MCU fuse bytes
  168. #
  169. # ATmega 328/328P
  170. ifeq (${MCU},atmega328)
  171. FAMILY = atmega328_324
  172. endif
  173. # ATmega 328PB
  174. ifeq (${MCU},atmega328pb)
  175. FAMILY = atmega328pb
  176. endif
  177. # ATmega 324P/324PA
  178. ifeq (${MCU},atmega324p)
  179. FAMILY = atmega328_324
  180. endif
  181. # ATmega 644/644P/644PA
  182. ifeq (${MCU},atmega644)
  183. FAMILY = atmega328_324
  184. endif
  185. # ATmega 1284/1284P
  186. ifeq (${MCU},atmega1284)
  187. FAMILY = atmega328_324
  188. endif
  189. # ATmega 328/324/644/1284
  190. ifeq (${FAMILY},atmega328_324)
  191. # high byte: use default settings
  192. HFUSE = -U hfuse:w:0xd9:m
  193. # extended byte: BOD level 4.3V
  194. EFUSE = -U efuse:w:0xfc:m
  195. # low byte: clock settings
  196. ifeq (${FREQ},1)
  197. # internal RC oscillator (8MHz) and /1 clock divider
  198. LFUSE_RC = -U lfuse:w:0x62:m
  199. # external 8MHz full swing crystal and /8 clock divider
  200. LFUSE_CRYSTAL = -U lfuse:w:0x77:m
  201. # external 8MHz low power crystal and /8 clock divider
  202. LFUSE_LOWPOWER = -U lfuse:w:0x7f:m
  203. endif
  204. ifeq (${FREQ},8)
  205. # internal RC oscillator (8MHz) and /1 clock divider
  206. LFUSE_RC = -U lfuse:w:0xe2:m
  207. # external 8MHz full swing crystal and /1 clock divider
  208. LFUSE_CRYSTAL = -U lfuse:w:0xf7:m
  209. # external 8MHz low power crystal and /1 clock divider
  210. LFUSE_LOWPOWER = -U lfuse:w:0xff:m
  211. endif
  212. ifeq (${FREQ},16)
  213. # internal RC oscillator (8MHz) not possible
  214. LFUSE_RC =
  215. # external 16MHz full swing crystal and /1 clock divider
  216. LFUSE_CRYSTAL = -U lfuse:w:0xf7:m
  217. # external 16MHz low power crystal and /1 clock divider
  218. LFUSE_LOWPOWER = -U lfuse:w:0xff:m
  219. endif
  220. ifeq (${FREQ},20)
  221. # internal RC oscillator (8MHz) not possible
  222. LFUSE_RC =
  223. # external 20MHz full swing crystal and /1 clock divider
  224. LFUSE_CRYSTAL = -U lfuse:w:0xf7:m
  225. # external 20MHz low power crystal and /1 clock divider
  226. LFUSE_LOWPOWER = -U lfuse:w:0xff:m
  227. endif
  228. endif
  229. # ATmega 328PB
  230. ifeq (${FAMILY},atmega328pb)
  231. # high byte: use default settings
  232. HFUSE = -U hfuse:w:0xd9:m
  233. # extended byte: BOD level 4.3V, CFD disabled
  234. EFUSE = -U efuse:w:0xf4:m
  235. # low byte: clock settings
  236. ifeq (${FREQ},8)
  237. # internal RC oscillator (8MHz) and /1 clock divider
  238. LFUSE_RC = -U lfuse:w:0xe2:m
  239. # full swing crystal not supported, use low power crystal
  240. LFUSE_CRYSTAL = -U lfuse:w:0xff:m
  241. # external 8MHz low power crystal and /1 clock divider
  242. LFUSE_LOWPOWER = -U lfuse:w:0xff:m
  243. endif
  244. ifeq (${FREQ},16)
  245. # internal RC oscillator (8MHz) not possible
  246. LFUSE_RC =
  247. # full swing crystal not supported, use low power crystal
  248. LFUSE_CRYSTAL = -U lfuse:w:0xff:m
  249. # external 16MHz low power crystal and /1 clock divider
  250. LFUSE_LOWPOWER = -U lfuse:w:0xff:m
  251. endif
  252. endif
  253. # select LFUSE
  254. ifeq (${OSCILLATOR},RC)
  255. LFUSE = ${LFUSE_RC}
  256. endif
  257. ifeq (${OSCILLATOR},Crystal)
  258. LFUSE = ${LFUSE_CRYSTAL}
  259. endif
  260. ifeq (${OSCILLATOR},LowPower)
  261. LFUSE = ${LFUSE_LOWPOWER}
  262. endif
  263. # check fuses
  264. FUSES =
  265. ifneq ($(strip ${LFUSE}),)
  266. ifneq ($(strip ${HFUSE}),)
  267. FUSES = ${LFUSE} ${HFUSE} ${EFUSE}
  268. endif
  269. endif
  270. # set fuses
  271. fuses:
  272. ifeq ($(strip ${FUSES}),)
  273. @echo Invalid fuse settings!
  274. else
  275. avrdude -c ${PROGRAMMER} -B ${BITCLOCK} -p ${PARTNO} -P ${PORT} ${FUSES}
  276. endif