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 *.bin
*.hex *.hex
*.lst *.lst
*.lss
*.map *.map

100
Makefile
View File

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

19
main.c
View File

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