Avr makefile
From Attie's Wiki
(Difference between revisions)
m |
m |
||
(7 intermediate revisions by one user not shown) | |||
Line 11: | Line 11: | ||
# what protocol do you use to communicate with the IC? | # what protocol do you use to communicate with the IC? | ||
− | AVRDUDE_PROTO:= | + | AVRDUDE_PROTO:=stk500v1 |
#AVRDUDE_PROTO:=buspirate | #AVRDUDE_PROTO:=buspirate | ||
Line 23: | Line 23: | ||
DIRS:=bin obj hex | DIRS:=bin obj hex | ||
SRCS+=main | SRCS+=main | ||
− | OPTIMISATION:= | + | OPTIMISATION:=-falign-functions \ |
− | + | ||
-falign-jumps \ | -falign-jumps \ | ||
-falign-labels \ | -falign-labels \ | ||
Line 32: | Line 31: | ||
-fregmove \ | -fregmove \ | ||
-frename-registers \ | -frename-registers \ | ||
+ | -fshort-enums \ | ||
-freorder-blocks \ | -freorder-blocks \ | ||
-freorder-functions \ | -freorder-functions \ | ||
Line 42: | Line 42: | ||
OBJCOPY:=$(CROSS_COMPILE)objcopy | OBJCOPY:=$(CROSS_COMPILE)objcopy | ||
CFLAGS:=$(OPTIMISATION) -mmcu=$(DEVICE) -c -Wall -O9 | CFLAGS:=$(OPTIMISATION) -mmcu=$(DEVICE) -c -Wall -O9 | ||
− | CLINKS:=$(OPTIMISATION) -mmcu=$(DEVICE) | + | CLINKS:=$(OPTIMISATION) -fwhole-program -mmcu=$(DEVICE) |
.PHONY: all new clean spotless .dirs upload download | .PHONY: all new clean spotless .dirs upload download | ||
Line 80: | Line 80: | ||
./obj/%.o: %.c makefile | ./obj/%.o: %.c makefile | ||
$(CC) $(CFLAGS) $*.c -o $@ | $(CC) $(CFLAGS) $*.c -o $@ | ||
+ | </source> | ||
+ | |||
+ | == Memory Usage == | ||
+ | It is very handy to know the current memory usage of your application. Especially when working with the smaller devices. | ||
+ | Add this to your makefile and then type <code>make meminfo</code> to get detailed information on the memory usage | ||
+ | <source lang="text"> | ||
+ | .PHONY: meminfo | ||
+ | |||
+ | meminfo: .meminfo | ||
+ | @cat .meminfo | ||
+ | |||
+ | .meminfo: ./bin/$(ELFOUT) | ||
+ | @echo "Regenerating memory usage information..." | ||
+ | @avr-objdump ./bin/$(ELFOUT) -t | grep -e "^[0-9a-f]* ......O \.bss" > .meminfo.t1 | ||
+ | @cat .meminfo.t1 | sed -re "s/.*\.bss[ \t]0*//" | awk --non-decimal-data '{print ("0x"$$1)+0 "\t" $$2}' > .meminfo.t2 | ||
+ | @cat .meminfo.t2 | sort -nr > .meminfo | ||
+ | @cat .meminfo | awk '{val += $$1}END{print "TOTAL: " val " bytes"}' >> .meminfo | ||
+ | @rm .meminfo.t* | ||
</source> | </source> |
Latest revision as of 21:14, 16 October 2011
# the output binary name (found in ./bin) ELFOUT:=main.elf HEXOUT:=main.hex # the source files you wish to use (without the '.c') - main.c is added later SRCS:= # which device are you using? DEVICE:=atmega328p # what protocol do you use to communicate with the IC? AVRDUDE_PROTO:=stk500v1 #AVRDUDE_PROTO:=buspirate # which serial port is it connected to? AVRDUDE_PORT:=/dev/ttyUSB0 AVRDUDE_BAUD:=57600 ################################################################################### # There should be no need to change below here for most projects DIRS:=bin obj hex SRCS+=main OPTIMISATION:=-falign-functions \ -falign-jumps \ -falign-labels \ -falign-loops \ -fif-conversion2 \ -finline-functions \ -fregmove \ -frename-registers \ -fshort-enums \ -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) -fwhole-program -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 $@
[edit] Memory Usage
It is very handy to know the current memory usage of your application. Especially when working with the smaller devices.
Add this to your makefile and then type make meminfo
to get detailed information on the memory usage
.PHONY: meminfo meminfo: .meminfo @cat .meminfo .meminfo: ./bin/$(ELFOUT) @echo "Regenerating memory usage information..." @avr-objdump ./bin/$(ELFOUT) -t | grep -e "^[0-9a-f]* ......O \.bss" > .meminfo.t1 @cat .meminfo.t1 | sed -re "s/.*\.bss[ \t]0*//" | awk --non-decimal-data '{print ("0x"$$1)+0 "\t" $$2}' > .meminfo.t2 @cat .meminfo.t2 | sort -nr > .meminfo @cat .meminfo | awk '{val += $$1}END{print "TOTAL: " val " bytes"}' >> .meminfo @rm .meminfo.t*