81 lines
2.4 KiB
Makefile
81 lines
2.4 KiB
Makefile
# required packages
|
|
# sudo aptitude install avrdude gcc-avr avr-libc
|
|
# the program
|
|
PROG=ir-cock-grenade
|
|
# to compile
|
|
CC=avr-gcc
|
|
OBJDUMP=avr-objdump
|
|
OBJCOPY=avr-objcopy
|
|
CFLAGS=-g -Wall -O3
|
|
# the target
|
|
#DEVICE=atmega328p
|
|
DEVICE=attiny85
|
|
F_CPU=1000000
|
|
# the port to flash
|
|
#PORT=/dev/ttyUSB0
|
|
# the flasher
|
|
#PROGRAMMER=buspirate
|
|
PROGRAMMER=usbtiny
|
|
# to flash
|
|
#AVRDUDE=avrdude -p $(DEVICE) -P $(PORT) -c $(PROGRAMMER)
|
|
AVRDUDE=avrdude -p $(DEVICE) -c $(PROGRAMMER) -B 50
|
|
|
|
all: prog
|
|
|
|
prog: verify $(PROG).c
|
|
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -o $(PROG) $(PROG).c
|
|
$(OBJDUMP) -h -S $(PROG) > $(PROG).lst
|
|
$(OBJCOPY) -j .text -j .data -O ihex $(PROG) $(PROG).hex
|
|
|
|
# Fuse extended byte:
|
|
# 0x07 = - - - - - 1 1 1
|
|
# \-+-/
|
|
# +------ BODLEVEL 2..0 (Brown-out Detector trigger level -> disabled)
|
|
#
|
|
# Fuse high byte:
|
|
# 0xdf = 1 1 0 1 1 1 1 1
|
|
# ^ ^ ^ ^ ^ \+/ ^
|
|
# | | | | | | +---- BOOTRST (Select Reset Vector -> jump to application at start)
|
|
# | | | | | +------- BOOTSZ 1..0 (Select Boot Size -> 256 words starting at 0x3F00)
|
|
# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
|
|
# | | | +-------------- WDTON (watchdog timer always on -> disable)
|
|
# | | +---------------- SPIEN (enable serial programming -> enabled)
|
|
# | +------------------ DWEN (debug wire enable -> enabled)
|
|
# +-------------------- RSTDISBL (disable external reset -> reset disabled)
|
|
#
|
|
# Fuse low byte:
|
|
# 0x62 = 0 1 1 0 0 0 1 0
|
|
# ^ ^ \+/ \--+--/
|
|
# | | | +------- CKSEL 3..0 (clock selection -> Internal RC oscillator)
|
|
# | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
|
|
# | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
|
|
# +-------------------- CKDIV8 (divide clock by 8 -> divide)
|
|
burn-fuse:
|
|
$(AVRDUDE) -U efuse:w:0x07:m -U hfuse:w:0xdf:m -U lfuse:w:0x62:m
|
|
|
|
read-fuse:
|
|
$(AVRDUDE) -U efuse:r:efuse.raw:r -U hfuse:r:hfuse.raw:r -U lfuse:r:lfuse.raw:r
|
|
|
|
flash:
|
|
$(AVRDUDE) -U flash:w:$(PROG).hex:i
|
|
|
|
read-flash:
|
|
$(AVRDUDE) -U flash:r:flash_dump.hex:i
|
|
|
|
flash: prog load
|
|
install : prog load
|
|
load:
|
|
$(AVRDUDE) -U flash:w:$(PROG).hex:i
|
|
|
|
clean:
|
|
rm -f $(PROG) *.hex *.lst
|
|
|
|
verify:
|
|
$(AVRDUDE)
|
|
if [ $$? -eq 0 ]; then \
|
|
echo "avrdude configured correctly"; \
|
|
else \
|
|
echo "avrdude not configured correctly in Makefile"; \
|
|
exit 1; \
|
|
fi
|