add assembly support and use optiboot (over default arduino boot which does not support watchdog)

This commit is contained in:
King Kévin 2016-01-18 15:48:21 +01:00
parent 42477df0d7
commit 4342eb802b
1 changed files with 27 additions and 19 deletions

View File

@ -12,9 +12,9 @@ F_CPU = 16000000UL
PROGRAMMER = arduino PROGRAMMER = arduino
PORT = /dev/ttyUSB0 PORT = /dev/ttyUSB0
# to flash # to flash
# use the aduino bootlaoder, with a baudrate of 57600 # use the aduino bootloader, with a baudrate of 57600
# reset the device to start bootlaoder # reset the device to start (optiboot) bootloader
FLASHER = avrdude -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b 57600 -D FLASHER = avrdude -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b 115200 -D
# compiler executables # compiler executables
CC = avr-gcc CC = avr-gcc
@ -24,26 +24,29 @@ SIZE = avr-size
# library directories, compiler, and linker flags # library directories, compiler, and linker flags
LIBS = lib LIBS = lib
CFLAGS = -g -Wall -Werror -O3 -std=c99 CFLAGS = -g -Wall -Werror -Os -mcall-prologues -std=c99
CFLAGS += -I. $(patsubst %,-I%,$(LIBS)) CFLAGS += -I. $(patsubst %,-I%,$(LIBS))
CFLAGS += -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) CFLAGS += -mmcu=$(DEVICE) -DF_CPU=$(F_CPU)
AFLAGS = -Wall -Werror -x assembler-with-cpp
AFLAGS += -I. $(patsubst %,-I%,$(LIBS))
AFLAGS += -mmcu=$(DEVICE)
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -I. $(patsubst %,-I%,$(LIBS)) LDFLAGS += -I. $(patsubst %,-I%,$(LIBS))
LDFLAGS += -mmcu=$(DEVICE) LDFLAGS += -mmcu=$(DEVICE)
# floating point printf version (requires -lm below) # floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
# math library # math library
#LDFLAGS += -lm LDFLAGS += -lm
# source files to compile # source files to compile
SRC = $(wildcard *.c) CSRC = $(wildcard *.c) $(foreach LIB,$(LIBS),$(wildcard $(LIB)/*.c))
SRC += $(foreach LIB,$(LIBS),$(wildcard $(LIB)/*.c)) ASRC = $(wildcard *.S) $(foreach LIB,$(LIBS),$(wildcard $(LIB)/*.S))
# header files # header files
HEADER = $(SRC:.c=.h) HEADER = $(SRC:.c=.h)
# object files # object files
OBJ = $(SRC:.c=.o) OBJ = $(patsubst %.c,%.o,$(CSRC)) $(patsubst %.S,%.o,$(ASRC))
# listing files. # listing files
LST = $(SRC:.c=.lst) LST = $(patsubst %.c,%.lst,$(CSRC)) $(patsubst %.S,%.lst,$(ASRC))
all: compile flash all: compile flash
$(info EEPROM has to be programmed separately) $(info EEPROM has to be programmed separately)
@ -56,21 +59,22 @@ debug: map lst all
# after reset the bootloader is start # after reset the bootloader is start
# the bootloader can be used to reflash the device # the bootloader can be used to reflash the device
reset: reset:
stty 57600 raw ignbrk hup < $(PORT) stty 115200 raw ignbrk hup < $(PORT)
# flash the device using the internal bootloader # flash the device using the internal bootloader
flash: $(TARGET).hex reset flash: $(TARGET).hex reset
$(FLASHER) -U flash:w:$<:i $(FLASHER) -U flash:w:$<:i
# write EEPROM on the device # write EEPROM on the device (optiboot has EEPROM capabilities disabled by default)
eeprom: $(TARGET)_eeprom.hex reset eeprom: $(TARGET)_eeprom.hex reset
$(FLASHER) -U eeprom:w:$<:i $(FLASHER) -U eeprom:w:$<:i
# write bootloader and fuses # write bootloader (optiboot) and fuses
bootloader: bootloader.hex:
wget https://arduino.googlecode.com/svn/trunk/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex wget -O $@ https://github.com/Optiboot/optiboot/raw/master/optiboot/bootloaders/optiboot/optiboot_atmega328.hex
avrdude -p $(DEVICE) -c usbtiny -U lfuse:w:0xff:m -U hfuse:w:0xda:m -U efuse:w:0x05:m -U flash:w:ATmegaBOOT_168_atmega328.hex:i
rm ATmegaBOOT_168_atmega328.hex bootloader: bootloader.hex
avrdude -p $(DEVICE) -c usbtiny -U lfuse:w:0xff:m -U hfuse:w:0xda:m -U efuse:w:0x05:m -U flash:w:$<:i
# create main target firmware # create main target firmware
compile: $(TARGET).elf compile: $(TARGET).elf
@ -83,11 +87,15 @@ lst: $(TARGET).lst
map: $(TARGET).map map: $(TARGET).map
# compile source files # compile source files
%.o: %.c %.h %.o: %.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
%.o: %.S
$(CC) $(AFLAGS) -c -o $@ $<
# link compiled files # link compiled files
%.elf: $(OBJ) %.elf: $(OBJ)
$(info elf)
$(CC) $(LDFLAGS) -o $@ $^ $(CC) $(LDFLAGS) -o $@ $^
$(TARGET).map: $(OBJ) $(TARGET).map: $(OBJ)