/
avr_makefile_brian
66 lines (53 loc) · 1.81 KB
/
avr_makefile_brian
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Generic AVR Makefile
# Brian Mayton <bmayton@media.mit.edu>
#
# 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. http://www.engbedded.com/fusecalc/ is very useful!
EFUSE=0xF9
HFUSE=0xDF
LFUSE=0x62
# 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
LDFLAGS=-mmcu=$(MCU)
all: $(APPLICATION).hex
clean:
rm -f *.hex *.elf *.o
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(APPLICATION).elf: $(OBJECTS)
$(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
fuses:
$(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