From 4342eb802b047c80cbeadd7c728777c481c951e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 18 Jan 2016 15:48:21 +0100 Subject: [PATCH] add assembly support and use optiboot (over default arduino boot which does not support watchdog) --- Makefile | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index a84e246..3b9ae33 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,9 @@ F_CPU = 16000000UL PROGRAMMER = arduino PORT = /dev/ttyUSB0 # to flash -# use the aduino bootlaoder, with a baudrate of 57600 -# reset the device to start bootlaoder -FLASHER = avrdude -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b 57600 -D +# use the aduino bootloader, with a baudrate of 57600 +# reset the device to start (optiboot) bootloader +FLASHER = avrdude -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b 115200 -D # compiler executables CC = avr-gcc @@ -24,26 +24,29 @@ SIZE = avr-size # library directories, compiler, and linker flags LIBS = lib -CFLAGS = -g -Wall -Werror -O3 -std=c99 +CFLAGS = -g -Wall -Werror -Os -mcall-prologues -std=c99 CFLAGS += -I. $(patsubst %,-I%,$(LIBS)) 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 += -I. $(patsubst %,-I%,$(LIBS)) LDFLAGS += -mmcu=$(DEVICE) # floating point printf version (requires -lm below) -#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt +LDFLAGS += -Wl,-u,vfprintf -lprintf_flt # math library -#LDFLAGS += -lm +LDFLAGS += -lm # source files to compile -SRC = $(wildcard *.c) -SRC += $(foreach LIB,$(LIBS),$(wildcard $(LIB)/*.c)) +CSRC = $(wildcard *.c) $(foreach LIB,$(LIBS),$(wildcard $(LIB)/*.c)) +ASRC = $(wildcard *.S) $(foreach LIB,$(LIBS),$(wildcard $(LIB)/*.S)) # header files HEADER = $(SRC:.c=.h) # object files -OBJ = $(SRC:.c=.o) -# listing files. -LST = $(SRC:.c=.lst) +OBJ = $(patsubst %.c,%.o,$(CSRC)) $(patsubst %.S,%.o,$(ASRC)) +# listing files +LST = $(patsubst %.c,%.lst,$(CSRC)) $(patsubst %.S,%.lst,$(ASRC)) all: compile flash $(info EEPROM has to be programmed separately) @@ -56,21 +59,22 @@ debug: map lst all # after reset the bootloader is start # the bootloader can be used to reflash the device reset: - stty 57600 raw ignbrk hup < $(PORT) + stty 115200 raw ignbrk hup < $(PORT) # flash the device using the internal bootloader flash: $(TARGET).hex reset $(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 $(FLASHER) -U eeprom:w:$<:i -# write bootloader and fuses -bootloader: - wget https://arduino.googlecode.com/svn/trunk/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_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 +# write bootloader (optiboot) and fuses +bootloader.hex: + wget -O $@ https://github.com/Optiboot/optiboot/raw/master/optiboot/bootloaders/optiboot/optiboot_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 compile: $(TARGET).elf @@ -83,11 +87,15 @@ lst: $(TARGET).lst map: $(TARGET).map # compile source files -%.o: %.c %.h +%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< +%.o: %.S + $(CC) $(AFLAGS) -c -o $@ $< + # link compiled files %.elf: $(OBJ) + $(info elf) $(CC) $(LDFLAGS) -o $@ $^ $(TARGET).map: $(OBJ)