Skip to content

Instantly share code, notes, and snippets.

@TechplexEngineer
Created March 27, 2014 12:34
Show Gist options
  • Select an option

  • Save TechplexEngineer/9806566 to your computer and use it in GitHub Desktop.

Select an option

Save TechplexEngineer/9806566 to your computer and use it in GitHub Desktop.
Sample AVR makefile, just change the TARGET variable to the name of your main code. ie: if your code is main.c TARGET=main
CC=avr-gcc
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega88
OBJ2HEX=avr-objcopy
#UISP=/usr/local/bin/uisp
TARGET=main
#ADFLAGS=-p m8 -c FT232 -P /dev/tty.usbserial-A8003POq
ADFLAGS=-p m88 -c avrispmkII -P usb
# .PHONY means that these are not a target
.PHONY: fuses prog erase
prog: $(TARGET).hex $(TARGET).eeprom #this programs the chip, depends on Target.hex and Target.eeprom
avrdude $(ADFLAGS) -V -U flash:w:$(TARGET).hex:i
# make .obj (any obj) if corresponding .o is newer
%.obj: %.o
$(CC) $(CFLAGS) $< -o $@ # $@ means target of rule, $< means prerequisite of rule
# similarly, make any .hex if corresponding .obj is newer
%.hex: %.obj
$(OBJ2HEX) -R .eeprom -O ihex $< $@ # remove eeprom output ihex translate .obj into hex file
# any eeprom depends on same .obj
%.eeprom: %.obj
$(OBJ2HEX) -j .eeprop -O ihex $< $@
# this target will just erase avr
erase:
avrdude $(ADFLAGS) -E noreset -e
# this target will remove all non-source files (will cause a complete re-build on next make)
clean:
rm -f *.hex *.obj *.o *.eeprom
# program the fuses (NOT done by regular make)
fuses:
avrdude $(ADFLAGS) -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m
#www.engbedded.com/fusecalc
# $@ -- is the target
# $^ -- is a list of all the prerequisites of the rule
# $< -- is the first prerequisite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment