Makefile 9.0 KB

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