update Makefile

This commit is contained in:
Olaf Rempel 2014-10-05 14:32:07 +02:00
parent ca2a0a99ae
commit 5e4b562608
3 changed files with 70 additions and 50 deletions

1
.gitignore vendored
View File

@ -3,4 +3,5 @@
*.bin
*.hex
*.lst
*.lss
*.map

100
Makefile
View File

@ -1,65 +1,71 @@
PRG = twiboot
OBJ = main.o
MCU_TARGET = atmega88
OPTIMIZE = -Os
CC := avr-gcc
LD := avr-ld
OBJCOPY := avr-objcopy
OBJDUMP := avr-objdump
SIZE := avr-size
ifeq ($(MCU_TARGET), atmega8)
BOOTLOADER_START=0x1C00
TARGET = twiboot
SOURCE = $(wildcard *.c)
# select MCU
MCU = atmega88
AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
#AVRDUDE_PROG := -c dragon_isp -P usb
# ---------------------------------------------------------------------------
ifeq ($(MCU), atmega8)
# (8Mhz internal RC-Osz., 2.7V BOD)
AVRDUDE_MCU=m8
endif
ifeq ($(MCU_TARGET), atmega88)
AVRDUDE_FUSES=lfuse:w:0x84:m hfuse:w:0xda:m
BOOTLOADER_START=0x1C00
endif
ifeq ($(MCU), atmega88)
# (8Mhz internal RC-Osz., 2.7V BOD)
AVRDUDE_MCU=m88
AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
BOOTLOADER_START=0x1C00
endif
ifeq ($(MCU_TARGET), atmega168)
ifeq ($(MCU), atmega168)
# (8Mhz internal RC-Osz., 2.7V BOD)
AVRDUDE_MCU=m168 -F
AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
BOOTLOADER_START=0x3C00
AVRDUDE_MCU=m168
endif
DEFS = -DAPP_END=$(BOOTLOADER_START)
LIBS =
# ---------------------------------------------------------------------------
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override LDFLAGS = -Wl,-Map,$(PRG).map,--section-start=.text=$(BOOTLOADER_START)
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START)
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# ---------------------------------------------------------------------------
all: $(PRG).elf lst text
$(SIZE) -x -A $(PRG).elf
$(TARGET): $(TARGET).elf
@$(SIZE) -B -x --mcu=$(MCU) $<
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(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)
%.o: %.c $(MAKEFILE_LIST)
$(CC) $(CFLAGS) -c $< -o $@
@echo " Building file: $<"
@$(CC) $(CFLAGS) -o $@ -c $<
clean:
rm -rf *.o $(PRG).lst $(PRG).map $(PRG).elf $(PRG).hex $(PRG).bin
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
lst: $(PRG).lst
install: $(TARGET).elf
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
text: hex bin
hex: $(PRG).hex
bin: $(PRG).bin
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
install: text
avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U flash:w:$(PRG).hex
#fuses:
# avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U lfuse:w:0xc2:m
# avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U hfuse:w:0xdd:m
# avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U efuse:w:0xfa:m
fuses:
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))

19
main.c
View File

@ -54,6 +54,7 @@
#endif
#define EEPROM_SUPPORT 1
#define LED_SUPPORT 1
/* 25ms @8MHz */
#define TIMER_RELOAD (0xFF - 195)
@ -61,6 +62,7 @@
/* 40 * 25ms */
#define TIMEOUT 40
#if LED_SUPPORT
#define LED_INIT() DDRB = ((1<<PORTB4) | (1<<PORTB5))
#define LED_RT_ON() PORTB |= (1<<PORTB4)
#define LED_RT_OFF() PORTB &= ~(1<<PORTB4)
@ -68,8 +70,19 @@
#define LED_GN_OFF() PORTB &= ~(1<<PORTB5)
#define LED_GN_TOGGLE() PORTB ^= (1<<PORTB5)
#define LED_OFF() PORTB = 0x00
#else
#define LED_INIT()
#define LED_RT_ON()
#define LED_RT_OFF()
#define LED_GN_ON()
#define LED_GN_OFF()
#define LED_GN_TOGGLE()
#define LED_OFF()
#endif
#ifndef TWI_ADDRESS
#define TWI_ADDRESS 0x29
#endif
/* SLA+R */
#define CMD_WAIT 0x00
@ -138,8 +151,8 @@ const static uint8_t chipinfo[8] = {
SPM_PAGESIZE,
(APP_END >> 8) & 0xFF,
APP_END & 0xFF,
(BOOTLOADER_START >> 8) & 0xFF,
BOOTLOADER_START & 0xFF,
#if (EEPROM_SUPPORT)
((E2END +1) >> 8 & 0xFF),
(E2END +1) & 0xFF
@ -162,7 +175,7 @@ static void write_flash_page(void)
uint8_t size = SPM_PAGESIZE;
uint8_t *p = buf;
if (pagestart >= APP_END)
if (pagestart >= BOOTLOADER_START)
return;
boot_page_erase(pagestart);