Avr makefile

From Attie's Wiki
Revision as of 14:58, 15 October 2011 by Attie (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  1. the output binary name (found in ./bin)

ELFOUT:=main.elf HEXOUT:=main.hex

  1. the source files you wish to use (without the '.c') - main.c is added later

SRCS:=

  1. which device are you using?

DEVICE:=atmega328p

  1. what protocol do you use to communicate with the IC?

AVRDUDE_PROTO:=cstk500v1

  1. AVRDUDE_PROTO:=buspirate
  1. which serial port is it connected to?

AVRDUDE_PORT:=/dev/ttyUSB0 AVRDUDE_BAUD:=57600

  1. There should be no need to change below here for most projects

DIRS:=bin obj hex SRCS+=main OPTIMISATION:=-fwhole-program \

             -falign-functions \
             -falign-jumps \
             -falign-labels \
             -falign-loops \
             -fif-conversion2 \
             -finline-functions \
             -fregmove \
             -frename-registers \
             -freorder-blocks \
             -freorder-functions \
             -fsplit-wide-types \
             -ftoplevel-reorder \
             -funroll-all-loops \
             -fvariable-expansion-in-unroller

CROSS_COMPILE:=avr- CC:=$(CROSS_COMPILE)gcc OBJCOPY:=$(CROSS_COMPILE)objcopy CFLAGS:=$(OPTIMISATION) -mmcu=$(DEVICE) -c -Wall -O9 CLINKS:=$(OPTIMISATION) -mmcu=$(DEVICE)

.PHONY: all new clean spotless .dirs upload download

all: .dirs ./hex/$(HEXOUT)

new: clean ./hex/$(HEXOUT)

clean: rm -f *~ rm -f ./hex/$(HEXOUT) rm -f ./bin/$(ELFOUT) rm -f ./obj/*.o

spotless: clean rm -rdf $(addprefix ./,$(DIRS)) .dirs .dirs: makefile mkdir -p $(addprefix ./,$(DIRS)) @touch .dirs


upload: ./hex/$(HEXOUT) avrdude -c$(AVRDUDE_PROTO) -P$(AVRDUDE_PORT) -b$(AVRDUDE_BAUD) -D -Uflash:w:./hex/$(HEXOUT):a

download: rm ./hex/$(HEXOUT).downloaded avrdude -c$(AVRDUDE_PROTO) -P$(AVRDUDE_PORT) -b$(AVRDUDE_BAUD) -D -Uflash:r:./hex/$(HEXOUT).downloaded:a


./hex/$(HEXOUT): ./bin/$(ELFOUT) $(OBJCOPY) -j .text -O ihex $^ $@ ./bin/$(ELFOUT): $(addprefix ./obj/,$(addsuffix .o,$(SRCS))) makefile $(CC) $(CLINKS) $(filter %.o,$^) -o $@

./obj/%.o: %.c %.h makefile $(CC) $(CFLAGS) $*.c -o $@ ./obj/%.o: %.c makefile $(CC) $(CFLAGS) $*.c -o $@

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox