Skip to content

Instantly share code, notes, and snippets.

@blondie7575
Created March 12, 2013 23:36
Show Gist options
  • Save blondie7575/5148089 to your computer and use it in GitHub Desktop.
Save blondie7575/5148089 to your computer and use it in GitHub Desktop.
# Makefile
#
#
DEVICE = attiny85
CLOCK = 8000000UL
PROGRAMMER = -c usbtiny
OBJECTS = main.o
ROMBASE = 0xf000
FUSES = -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -O3 -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
ASSEMBLE = ca65 -D BASE=$(ROMBASE) -l
# Symbolic targets:
all: romImage.inc main.hex
.c.o:
$(COMPILE) -c $< -o $@
.S.o:
$(ASSEMBLE) $< -o $@
.c.s:
$(COMPILE) -S $< -o $@
flash: all
$(AVRDUDE) -U flash:w:main.hex:i
fuse:
$(AVRDUDE) $(FUSES)
image: romImage.bin
# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse
# If you use a bootloader, change the command below appropriately:
load: all
bootloadHID main.hex
clean:
rm -f main.hex main.elf romImage.o romImage.bin romImage.inc romImagePad.bin $(OBJECTS)
# file targets:
main.elf: $(OBJECTS)
$(COMPILE) -o main.elf $(OBJECTS)
main.hex: main.elf
rm -f main.hex
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
romImage.bin: romImage.o
cl65 romImage.o --target none --start-addr $(ROMBASE) -o romImage.bin
romImage.inc: romImage.bin
dd if=romImage.bin ibs=4090 count=1 of=romImagePad.bin conv=sync
hexdump -ve '10/1 "0x%.2x," 1/0 "\n"' romImagePad.bin > romImage.inc
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.
# Targets for code debugging and analysis:
disasm: main.elf
avr-objdump -d main.elf
cpp:
$(COMPILE) -E main.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment