new targets: size, eeprom, bootlader, debug
This commit is contained in:
parent
bea4e707ac
commit
b30d73f3fa
|
@ -1,18 +1,24 @@
|
||||||
|
# Arduino Nano with ATmega328P programming script
|
||||||
|
# detailed configuration on http://arduino.cc/en/uploads/Main/boards.txt
|
||||||
# required packages: avrdude gcc-avr avr-libc
|
# required packages: avrdude gcc-avr avr-libc
|
||||||
# the atmega firmware binary to output
|
|
||||||
|
# the output firmware name
|
||||||
TARGET=scale
|
TARGET=scale
|
||||||
# to compile
|
# to compile
|
||||||
CC=avr-gcc
|
CC=avr-gcc
|
||||||
OBJDUMP=avr-objdump
|
OBJDUMP=avr-objdump
|
||||||
OBJCOPY=avr-objcopy
|
OBJCOPY=avr-objcopy
|
||||||
|
SIZE=avr-size
|
||||||
CFLAGS=-g -Wall -Werror -O3 -std=c99
|
CFLAGS=-g -Wall -Werror -O3 -std=c99
|
||||||
# the target
|
# the target (arduino nano)
|
||||||
DEVICE=atmega328p
|
DEVICE=atmega328p
|
||||||
F_CPU=16000000UL
|
F_CPU=16000000UL
|
||||||
# the flasher
|
# the flasher
|
||||||
PROGRAMMER=arduino
|
PROGRAMMER=arduino
|
||||||
PORT=/dev/ttyUSB0
|
PORT=/dev/ttyUSB0
|
||||||
# to flash (specially for the arduino, with DTR pulse ot reset)
|
# 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
|
FLASHER=avrdude -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b 57600 -D
|
||||||
# source files to compile
|
# source files to compile
|
||||||
SRC = $(wildcard *.c)
|
SRC = $(wildcard *.c)
|
||||||
|
@ -24,30 +30,54 @@ OBJ = $(SRC:.c=.o)
|
||||||
LST = $(SRC:.c=.lst)
|
LST = $(SRC:.c=.lst)
|
||||||
|
|
||||||
all: compile $(TARGET).lst flash
|
all: compile $(TARGET).lst flash
|
||||||
|
echo "EEPROM has to be programmed separately"
|
||||||
|
|
||||||
|
debug: CFLAGS += -DDEBUG
|
||||||
|
debug: all
|
||||||
|
|
||||||
|
# reset board by setting DTR
|
||||||
|
# the capacitor on DTR with create a pulse on RESET
|
||||||
|
# after reset the bootloader is start
|
||||||
|
# the bootloader can be used to reflash the device
|
||||||
reset:
|
reset:
|
||||||
stty 57600 raw ignbrk hup < $(PORT)
|
stty 57600 raw ignbrk hup < $(PORT)
|
||||||
|
|
||||||
flash: compile reset
|
# flash the device using the internal bootloader
|
||||||
|
flash: $(TARGET).hex reset
|
||||||
$(FLASHER) -U flash:w:$(TARGET).hex:i
|
$(FLASHER) -U flash:w:$(TARGET).hex:i
|
||||||
|
|
||||||
compile: $(TARGET).hex
|
# write EEPROM on the device
|
||||||
|
eeprom: $(TARGET)_eeprom.hex reset
|
||||||
|
$(FLASHER) -U eeprom:w:$(TARGET)_eeprom.hex:i
|
||||||
|
|
||||||
# compile
|
# write bootloader and fuses
|
||||||
|
bootloader:
|
||||||
|
wget http://code.google.com/p/arduino/source/browse/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
|
||||||
|
|
||||||
|
# create main target firmware
|
||||||
|
compile: $(TARGET).elf
|
||||||
|
$(SIZE) --format=avr --mcu=$(DEVICE) $(TARGET).elf
|
||||||
|
|
||||||
|
# compile source files
|
||||||
%.o: %.c %.h
|
%.o: %.c %.h
|
||||||
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -c -o $@ $<
|
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -c -o $@ $<
|
||||||
|
|
||||||
# link
|
# link compiled files
|
||||||
%.elf: $(OBJ)
|
%.elf: $(OBJ)
|
||||||
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -Wl,-Map=$(TARGET).map,--cref -o $@ $(OBJ)
|
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -Wl,-Map=$(TARGET).map,--cref -o $@ $(OBJ)
|
||||||
|
|
||||||
# extended listing
|
# create extended listing for additional information
|
||||||
%.lst: %.elf
|
%.lst: %.elf
|
||||||
$(OBJDUMP) -h -S $< > $@
|
$(OBJDUMP) --section-headers --source $< > $@
|
||||||
|
|
||||||
# output file
|
# create flashable ihex from firmware
|
||||||
%.hex: %.elf
|
%.hex: %.elf
|
||||||
$(OBJCOPY) -j .text -j .data -O ihex $< $@
|
$(OBJCOPY) --only-section .text --only-section .data --output-target ihex $< $@
|
||||||
|
|
||||||
|
%_eeprom.hex: %.elf
|
||||||
|
$(OBJCOPY) --only-section .eeprom --change-section-lma .eeprom=0 --output-target ihex $< $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TARGET) $(TARGET).hex $(TARGET).elf $(TARGET).lst $(TARGET).map $(LST) $(OBJ)
|
rm -f $(TARGET) $(TARGET).hex $(TARGET).elf $(TARGET).lst $(TARGET).map $(LST) $(OBJ)
|
||||||
|
|
Loading…
Reference in New Issue