led-controller/firmware/Makefile

95 lines
2.6 KiB
Makefile

# required packages
# sudo aptitude install avrdude gcc-avr avr-libc
# the program
TARGET=led-controller
# to compile
CC=avr-gcc
OBJDUMP=avr-objdump
OBJCOPY=avr-objcopy
CFLAGS=-g -Wall -Werror -O3 -std=c99
# the target
DEVICE=atmega328p
F_CPU=18432000UL
# the flasher
PROGRAMMER=usbtiny
# to flash
FLASHER=avrdude -p $(DEVICE) -c $(PROGRAMMER)
# source files to compile
SRC = main.c uart.c ir_nec.c settings.c
# header files.
HEADER = $(SRC:.c=.h)
# object files.
OBJ = $(SRC:.c=.o)
# listing files.
LST = $(SRC:.c=.lst)
all: program $(TARGET).lst verify burn-fuse flash
verify:
$(FLASHER)
if [ $$? -eq 0 ]; then \
echo "flasher configured correctly"; \
else \
echo "flasher not configured correctly in Makefile"; \
exit 1; \
fi
reset:
$(FLASHER)
read-fuse:
$(FLASHER) -U lfuse:r:lfuse.raw:r -U hfuse:r:hfuse.raw:r -U efuse:r:efuse.raw:r
# Fuse low byte:
# 0xff = 1 1 1 1 1 1 1 1
# ^ ^ \+/ \--+--/
# | | | +------- CKSEL 3..0 (clock selection -> full swing crytal oscillator)
# | | +--------------- SUT 1..0 (select start-up time -> slowly rising power)
# | +------------------ CKOUT (clock output on CKOUT pin -> unprogrammed)
# +-------------------- CKDIV8 (divide clock by 8 -> unprogrammed)
#
# 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 -> unprogrammed)
# | | | +-------------- WDTON (watchdog timer always on -> unprogrammed)
# | | +---------------- SPIEN (enable serial programming -> programmed)
# | +------------------ DWEN (debug wire enable -> unprogrammed)
# +-------------------- RSTDISBL (disable external reset -> unprogrammed)
#
# Fuse extended byte:
# 0x04 = - - - - - 1 0 0
# \-+-/
# +------ BODLEVEL 2..0 (Brown-out Detector trigger level -> 4.3V)
burn-fuse:
$(FLASHER) -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0x04:m
read-flash:
$(FLASHER) -U flash:r:flash_dump.hex:i
flash:
$(FLASHER) -U flash:w:$(TARGET).hex:i
program: $(TARGET).hex
# compile
%.o: %.c %.h
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -c -o $@ $<
# link
%.elf: $(OBJ)
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -Wl,-Map=$(TARGET).map,--cref -o $@ $(OBJ)
# extended listing
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# output file
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
clean:
rm -f $(TARGET) $(TARGET).hex $(TARGET).elf $(LST) $(TARGET).lst $(OBJ)