MCU=attiny13 # MCU=attiny24A # this is for tests of >1kB firmware CC=avr-gcc -mmcu=$(MCU) -I$(INCLUDE_DIRS) -Os -fshort-enums INCLUDE_DIRS=autoinclude MAKEHEX=avr-objcopy -O ihex AVRDUDE=avrdude # Make sure the programmer port is correct for you! For security reasons, we do # not script automatic port detection here. Please find the correct port # manually and change the variable PROGRAMMER_TTY here accordingly. ifeq ($(OS),Windows_NT) # Use the command `mode` to find the COM port on Windows. PROGRAMMER_TTY=COM3 else # Use the command `ls /dev/ttyUSB*` to find the port on Linux. Please make sure # the correct /dev/ttyUSBx has write permissions for everyone (at least 0666). # If for some reason you cannot change those, change the line # AVRDUDE=avrdude # above to # AVRDUDE=sudo avrdude # and program the chip with sudo permissions. PROGRAMMER_TTY=/dev/ttyUSB0 endif # Make sure this is your programmer board. We assume STK500 as the default. PROGRAMMER_BOARD=avrisp # Only stk500 and avrisp (Arduino ISP) have been tested, so you will have to # set the PROGRAMMER_BAUDRATE variable manually if you use any other # programmer. ifeq ($(PROGRAMMER_BOARD),stk500) PROGRAMMER_BAUDRATE=115200 endif ifeq ($(PROGRAMMER_BOARD),avrisp) # Arduino ISP - a DIY programmer made from Arduino, see # https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP PROGRAMMER_BAUDRATE=19200 endif all: build/main.hex build: mkdir -p build burn: mkdir -p burn autoinclude: mkdir -p autoinclude autoinclude/tinyqirx_conf.auto.h: conf/tinyqirx.conf autoinclude bin/generate_precalculation_header.py python bin/generate_precalculation_header.py $< $@ build/main.hex: build/main.o avr-size --mcu=$(MCU) build/main.o $(MAKEHEX) $< $@ build/main.cc: src/main.c src/tinyqirx_core.c src/tinyqirx.c src/tinyqirx_utils.c autoinclude/tinyqirx_conf.auto.h $(CC) -E $< -o $@ build/main.S: src/main.c src/tinyqirx_core.c src/tinyqirx.c src/tinyqirx_utils.c autoinclude/tinyqirx_conf.auto.h $(CC) -S $< -o $@ build/main.o: src/main.c build src/tinyqirx_core.c src/tinyqirx.c src/tinyqirx_utils.c autoinclude/tinyqirx_conf.auto.h $(CC) $< -o $@ .PHONY: install clean asm readfuses # For some reason, this command is prone to yielding "Unexpected Device # signature, 0x0000" and "Verification error, first mismatch at byte 0x0000" # errors. Just run it multiple times until succeeded. If it does not, try # moving the wires. install: build/main.hex $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U flash:w:$<:i -F burn/ensure_write.txt: burn touch burn/ensure_write.txt writefuses: burn/writehfuse.hex burn/writelfuse.hex # $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U hfuse:w:burn/writehfuse.hex:i -F $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U lfuse:w:burn/writelfuse.hex:i -F burn/writehfuse.hex: burn/writehfuse.bin avr-objcopy -O ihex -I binary $< $@ burn/writelfuse.hex: burn/writelfuse.bin avr-objcopy -O ihex -I binary $< $@ burn/writehfuse.bin: setfuse/hfuse.txt xxd -ps -r $< > $@ burn/writelfuse.bin: setfuse/lfuse.txt xxd -ps -r $< > $@ burn/ensure_read.txt: burn touch burn/ensure_read.txt burn/readhfuse.hex: burn/ensure_read.txt $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U hfuse:r:$@:i -F burn/readlfuse.hex: burn/ensure_read.txt $(AVRDUDE) -c $(PROGRAMMER_BOARD) -p $(MCU) -P $(PROGRAMMER_TTY) -b $(PROGRAMMER_BAUDRATE) -U lfuse:r:$@:i -F burn/readhfuse.bin: burn/readhfuse.hex avr-objcopy -I ihex -O binary $< $@ burn/readlfuse.bin: burn/readlfuse.hex avr-objcopy -I ihex -O binary $< $@ burn/readhfuse.txt: burn/readhfuse.bin xxd -ps $< > $@ burn/readlfuse.txt: burn/readlfuse.bin xxd -ps $< > $@ readfuses: burn/readhfuse.txt burn/readlfuse.txt cat burn/readhfuse.txt burn/readlfuse.txt rm burn/ensure_read.txt clean: rm -rf build autoinclude burn asm: build/main.S build/main.cc #asm: build/main.cc