2014-10-05 14:32:07 +02:00
|
|
|
CC := avr-gcc
|
|
|
|
LD := avr-ld
|
|
|
|
OBJCOPY := avr-objcopy
|
|
|
|
OBJDUMP := avr-objdump
|
|
|
|
SIZE := avr-size
|
2007-09-21 21:39:09 +02:00
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
TARGET = twiboot
|
|
|
|
SOURCE = $(wildcard *.c)
|
|
|
|
|
|
|
|
# select MCU
|
2020-10-26 13:51:07 +01:00
|
|
|
MCU = attiny85
|
2014-10-05 14:32:07 +02:00
|
|
|
|
|
|
|
AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
|
|
|
|
#AVRDUDE_PROG := -c dragon_isp -P usb
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ifeq ($(MCU), atmega8)
|
2019-11-06 10:03:47 +01:00
|
|
|
# atmega8:
|
|
|
|
# Fuse L: 0x84 (8Mhz internal RC-Osz., 2.7V BOD)
|
|
|
|
# Fuse H: 0xda (512 words bootloader)
|
2010-08-15 16:44:54 +02:00
|
|
|
AVRDUDE_MCU=m8
|
2014-10-05 14:32:07 +02:00
|
|
|
AVRDUDE_FUSES=lfuse:w:0x84:m hfuse:w:0xda:m
|
|
|
|
|
2010-08-15 16:44:54 +02:00
|
|
|
BOOTLOADER_START=0x1C00
|
2014-10-05 14:32:07 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(MCU), atmega88)
|
2019-11-06 10:03:47 +01:00
|
|
|
# atmega88:
|
|
|
|
# Fuse L: 0xc2 (8Mhz internal RC-Osz.)
|
|
|
|
# Fuse H: 0xdd (2.7V BOD)
|
|
|
|
# Fuse E: 0xfa (512 words bootloader)
|
2010-08-15 16:44:54 +02:00
|
|
|
AVRDUDE_MCU=m88
|
2014-10-05 14:32:07 +02:00
|
|
|
AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
|
|
|
|
|
|
|
|
BOOTLOADER_START=0x1C00
|
2010-08-15 16:44:54 +02:00
|
|
|
endif
|
2014-10-05 14:32:07 +02:00
|
|
|
|
|
|
|
ifeq ($(MCU), atmega168)
|
2019-11-06 10:03:47 +01:00
|
|
|
# atmega168:
|
|
|
|
# Fuse L: 0xc2 (8Mhz internal RC-Osz.)
|
|
|
|
# Fuse H: 0xdd (2.7V BOD)
|
|
|
|
# Fuse E: 0xfa (512 words bootloader)
|
2014-10-05 14:32:07 +02:00
|
|
|
AVRDUDE_MCU=m168 -F
|
|
|
|
AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
|
|
|
|
|
2010-08-15 16:44:54 +02:00
|
|
|
BOOTLOADER_START=0x3C00
|
|
|
|
endif
|
|
|
|
|
2015-03-18 23:28:12 +01:00
|
|
|
ifeq ($(MCU), atmega328p)
|
2019-11-06 10:03:47 +01:00
|
|
|
# atmega328p:
|
|
|
|
# Fuse L: 0xc2 (8Mhz internal RC-Osz.)
|
|
|
|
# Fuse H: 0xdc (512 words bootloader)
|
|
|
|
# Fuse E: 0xfd (2.7V BOD)
|
2015-03-18 23:28:12 +01:00
|
|
|
AVRDUDE_MCU=m328p -F
|
2015-03-21 09:15:43 +01:00
|
|
|
AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdc:m efuse:w:0xfd:m
|
2015-03-18 23:28:12 +01:00
|
|
|
|
2015-03-21 09:15:43 +01:00
|
|
|
BOOTLOADER_START=0x7C00
|
2015-03-18 23:28:12 +01:00
|
|
|
endif
|
|
|
|
|
2020-10-26 13:51:07 +01:00
|
|
|
ifeq ($(MCU), attiny85)
|
|
|
|
# attiny85:
|
|
|
|
# Fuse L: 0xe2 (8Mhz internal RC-Osz.)
|
|
|
|
# Fuse H: 0xdd (2.7V BOD)
|
|
|
|
# Fuse E: 0xfe (self programming enable)
|
|
|
|
AVRDUDE_MCU=t85
|
|
|
|
AVRDUDE_FUSES=lfuse:w:0xe2:m hfuse:w:0xdd:m efuse:w:0xfe:m
|
|
|
|
|
|
|
|
BOOTLOADER_START=0x1C00
|
2020-10-26 18:54:00 +01:00
|
|
|
CFLAGS_TARGET=-DUSE_CLOCKSTRETCH=1 -DVIRTUAL_BOOT_SECTION=1
|
2020-10-26 13:51:07 +01:00
|
|
|
endif
|
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
2007-09-21 21:39:09 +02:00
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
|
2020-10-26 13:51:07 +01:00
|
|
|
CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START) $(CFLAGS_TARGET)
|
2014-10-05 14:32:07 +02:00
|
|
|
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
|
2019-11-03 18:31:30 +01:00
|
|
|
LDFLAGS += -nostartfiles
|
2007-09-21 21:39:09 +02:00
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
2007-09-21 21:39:09 +02:00
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
$(TARGET): $(TARGET).elf
|
|
|
|
@$(SIZE) -B -x --mcu=$(MCU) $<
|
2007-09-21 21:39:09 +02:00
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
$(TARGET).elf: $(SOURCE:.c=.o)
|
|
|
|
@echo " Linking file: $@"
|
|
|
|
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
|
|
|
@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
|
|
|
|
@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
|
|
|
|
@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
|
2007-09-21 21:39:09 +02:00
|
|
|
|
2010-08-15 16:44:54 +02:00
|
|
|
%.o: %.c $(MAKEFILE_LIST)
|
2014-10-05 14:32:07 +02:00
|
|
|
@echo " Building file: $<"
|
|
|
|
@$(CC) $(CFLAGS) -o $@ -c $<
|
2010-08-15 16:44:54 +02:00
|
|
|
|
2007-09-21 21:39:09 +02:00
|
|
|
clean:
|
2014-10-05 14:32:07 +02:00
|
|
|
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
|
2007-09-21 21:39:09 +02:00
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
install: $(TARGET).elf
|
|
|
|
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
|
2009-01-24 16:52:22 +01:00
|
|
|
|
2014-10-05 14:32:07 +02:00
|
|
|
fuses:
|
|
|
|
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))
|