Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. MCU=attiny13
  2. # MCU=attiny24A # this is for tests of >1kB firmware
  3. CC=avr-gcc -mmcu=$(MCU) -I$(INCLUDE_DIRS) -Os -fshort-enums
  4. INCLUDE_DIRS=autoinclude
  5. MAKEHEX=avr-objcopy -O ihex
  6. AVRDUDE=avrdude
  7. # Make sure the programmer port is correct for you! For security reasons, we do
  8. # not script automatic port detection here. Please find the correct port
  9. # manually and change the variable PROGRAMMER_TTY here accordingly.
  10. ifeq ($(OS),Windows_NT)
  11. # Use the command `mode` to find the COM port on Windows.
  12. PROGRAMMER_TTY=COM3
  13. else
  14. # Use the command `ls /dev/ttyUSB*` to find the port on Linux. Please make sure
  15. # the correct /dev/ttyUSBx has write permissions for everyone (at least 0666).
  16. # If for some reason you cannot change those, change the line
  17. # AVRDUDE=avrdude
  18. # above to
  19. # AVRDUDE=sudo avrdude
  20. # and program the chip with sudo permissions.
  21. PROGRAMMER_TTY=/dev/ttyUSB0
  22. endif
  23. # Make sure this is your programmer board. We assume STK500 as the default.
  24. PROGRAMMER_BOARD=avrisp
  25. # Only stk500 and avrisp (Arduino ISP) have been tested, so you will have to
  26. # set the PROGRAMMER_BAUDRATE variable manually if you use any other
  27. # programmer.
  28. ifeq ($(PROGRAMMER_BOARD),stk500)
  29. PROGRAMMER_BAUDRATE=115200
  30. endif
  31. ifeq ($(PROGRAMMER_BOARD),avrisp)
  32. # Arduino ISP - a DIY programmer made from Arduino, see
  33. # https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP
  34. PROGRAMMER_BAUDRATE=19200
  35. endif
  36. all: build/main.hex
  37. build:
  38. mkdir -p build
  39. burn:
  40. mkdir -p burn
  41. autoinclude:
  42. mkdir -p autoinclude
  43. autoinclude/tinyqirx_conf.auto.h: conf/tinyqirx.conf autoinclude bin/generate_precalculation_header.py
  44. python bin/generate_precalculation_header.py $< $@
  45. build/main.hex: build/main.o
  46. avr-size --mcu=$(MCU) build/main.o
  47. $(MAKEHEX) $< $@
  48. build/main.cc: src/main.c src/tinyqirx_core.c src/tinyqirx.c src/tinyqirx_utils.c autoinclude/tinyqirx_conf.auto.h
  49. $(CC) -E $< -o $@
  50. build/main.S: src/main.c src/tinyqirx_core.c src/tinyqirx.c src/tinyqirx_utils.c autoinclude/tinyqirx_conf.auto.h
  51. $(CC) -S $< -o $@
  52. build/main.o: src/main.c build src/tinyqirx_core.c src/tinyqirx.c src/tinyqirx_utils.c autoinclude/tinyqirx_conf.auto.h
  53. $(CC) $< -o $@
  54. .PHONY: install clean asm readfuses
  55. # For some reason, this command is prone to yielding "Unexpected Device
  56. # signature, 0x0000" and "Verification error, first mismatch at byte 0x0000"
  57. # errors. Just run it multiple times until succeeded. If it does not, try
  58. # moving the wires.
  59. install: build/main.hex
  60. $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U flash:w:$<:i -F
  61. burn/ensure_write.txt: burn
  62. touch burn/ensure_write.txt
  63. writefuses: burn/writehfuse.hex burn/writelfuse.hex
  64. # $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U hfuse:w:burn/writehfuse.hex:i -F
  65. $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U lfuse:w:burn/writelfuse.hex:i -F
  66. burn/writehfuse.hex: burn/writehfuse.bin
  67. avr-objcopy -O ihex -I binary $< $@
  68. burn/writelfuse.hex: burn/writelfuse.bin
  69. avr-objcopy -O ihex -I binary $< $@
  70. burn/writehfuse.bin: setfuse/hfuse.txt
  71. xxd -ps -r $< > $@
  72. burn/writelfuse.bin: setfuse/lfuse.txt
  73. xxd -ps -r $< > $@
  74. burn/ensure_read.txt: burn
  75. touch burn/ensure_read.txt
  76. burn/readhfuse.hex: burn/ensure_read.txt
  77. $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U hfuse:r:$@:i -F
  78. burn/readlfuse.hex: burn/ensure_read.txt
  79. $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U lfuse:r:$@:i -F
  80. burn/readhfuse.bin: burn/readhfuse.hex
  81. avr-objcopy -I ihex -O binary $< $@
  82. burn/readlfuse.bin: burn/readlfuse.hex
  83. avr-objcopy -I ihex -O binary $< $@
  84. burn/readhfuse.txt: burn/readhfuse.bin
  85. xxd -ps $< > $@
  86. burn/readlfuse.txt: burn/readlfuse.bin
  87. xxd -ps $< > $@
  88. readfuses: burn/readhfuse.txt burn/readlfuse.txt
  89. cat burn/readhfuse.txt burn/readlfuse.txt
  90. rm burn/ensure_read.txt
  91. clean:
  92. rm -rf build autoinclude burn
  93. asm: build/main.S build/main.cc
  94. #asm: build/main.cc