Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (53 sloc) 1.81 KB
# Generic AVR Makefile
# Brian Mayton <>
# This is a basic Makefile for building programs for the AVR. I usually start
# with this for any new project; it's pretty versatile.
# 'make' builds the .hex file.
# 'make install' uses the programmer to load it onto the target chip.
# 'make fuses' programs the fuse bits on the target chip.
# 'make clean' removes all autogenerated files.
# OBJECTS should list all of the object files for the program (e.g. for each
# .c file, list a corresponding .o file here.) APPLICATION just specifies the
# name of the hex/elf files, and can be whatever you want.
OBJECTS = file1.o file2.o
APPLICATION = application
# Set up which MCU you're using, and what programmer, and the clock speed
# here.
MCU = atmega168
PROGRAMMER = jtag2isp
F_CPU = 20000000UL
# Make sure you check these fuse settings before actually using them, using
# fuse settings for the wrong clock setup or chip can make it hard to
# reprogram. is very useful!
# Edit these if you want to use different compilers
CC = avr-gcc
OBJCOPY = avr-objcopy
SIZE = avr-size
AVRDUDE = avrdude
# Compiler and linker flags
CFLAGS=-mmcu=$(MCU) -Wall -DF_CPU=$(F_CPU) -I. -funsigned-char \
-funsigned-bitfields -fpack-struct -fshort-enums -Os
all: $(APPLICATION).hex
rm -f *.hex *.elf *.o
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(CC) $(LDFLAGS) -o $@ $^
$(SIZE) -C --mcu=$(MCU) $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
install: all
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -P usb -e \
-U flash:w:$(APPLICATION).hex
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -P usb -e \
-U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m \
-U efuse:w:$(EFUSE):m
.PHONY: all clean install fuses