PROGRAMMER:= usbtiny PROGRAMMER_PORT:= usb CC:=avr-gcc OBJCOPY:=avr-objcopy AVRDUDE:=avrdude CFLAGS:= -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wextra -Wall -Wstrict-prototypes -std=gnu99 -ggdb LIBS:= HOSTCC:=gcc #Fuse Settings LFUSE:=0xBF HFUSE:=0xDD EFUSE:=0x00 # Source filenames FILES:=soil_sensor.c bus.c light.c humidity.c time.c moisture.c crc.c BT_FILES:=bootloader/bootloader.c bootloader/bus.c bootloader/crc.c bootloader/light.c BOOTSTART = 0x1800 BTLDFLAGS += -Wl,--section-start=.text=$(BOOTSTART) .PHONY: clean fuses download bootloader download-bootloader download-combo all newdevice # By default, compile and download both bootloader and main program. all: download-combo bootloader: bootloader.bin download-bootloader newdevice: fuses download-combo # Burn fuses fuses: @$(AVRDUDE) -p atmega88pb -c $(PROGRAMMER) -P $(PROGRAMMER_PORT) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m # Compile and Link Bootloader bootloader.bin: $(BT_FILES) ifndef BREV @$(error Board revision is not set. Use BREV=2, BREV=4, or BREV=5 on the make command line.) endif @$(CC) -mmcu=atmega88pb $(CFLAGS) -DBREV=$(BREV) -I. $(BT_FILES) -o bootloader.elf $(LIBS) $(BTLDFLAGS) @$(OBJCOPY) -O binary -R .eeprom bootloader.elf bootloader.bin @$(OBJCOPY) -O ihex -R .eeprom bootloader.elf bootloader.hex # Compile & link main program main.bin: $(FILES) ifndef BREV @$(error Board revision is not set. Use BREV=2, BREV=4, or BREV=5 on the make command line.) endif @$(CC) -mmcu=atmega88pb $(CFLAGS) -DBREV=$(BREV) -I. -T ldscript-avr4-mainprogram-custom.x $(FILES) -o main.elf $(LIBS) @$(OBJCOPY) -O binary -R .eeprom main.elf main.bin # Download main program, without changing fuses or eeprom. download: main.bin @$(AVRDUDE) -p atmega88pb -c $(PROGRAMMER) -P $(PROGRAMMER_PORT) -U flash:w:main.bin:r # Download bootloader, without changing fuses or eeprom. download-bootloader: bootloader.bin @$(AVRDUDE) -p atmega88pb -c $(PROGRAMMER) -P $(PROGRAMMER_PORT) -U flash:w:bootloader.hex:i # Download both bootloader and main program download-combo: main.bin bootloader.bin tools/crc-calc @cp main.bin combo.bin @dd if=bootloader.bin of=combo.bin conv=notrunc seek=6144 bs=1 @tools/crc-calc combo.bin @$(AVRDUDE) -p atmega88pb -c $(PROGRAMMER) -P $(PROGRAMMER_PORT) -U flash:w:combo.bin:r # Build crc-calc for setting the CRC on the combined firmware file tools/crc-calc: tools/crc-calc.c @$(HOSTCC) tools/crc-calc.c -o tools/crc-calc -Wall -std=gnu99 -ggdb #Delete generated files clean: @rm -f *.hex *.elf *.bin