-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
84 lines (61 loc) · 1.79 KB
/
Copy pathmakefile
File metadata and controls
84 lines (61 loc) · 1.79 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# AVR Makefile
# James Stockton
# make file commands
# all - compiles whole program
# iotest - test dac pins
# disasm - disassembles elf file
# size - shows size of elf file
# test - test programmer connection
# flash - upload hex to target
# fuse - set fuses of target
# clean - deletes compiled files
# avr constants
MCU = atmega644p
CLK = 12000000
# compiler constants
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
OBJSIZE = avr-size
# compiler flags
CFLAGS = -Wall -Os
TARGET = main
TEST = iotest
# build and source folders
BUILD = build
SOURCE = src
INCLUDES = $(wildcard $(SOURCE)/*.c)
LIB = lib
LIBRARY = $(wildcard $(LIB)/*.c)
#programmer constant
AVRDUDE = avrdude
PROGRAMMER = usbasp
#fuses
LF = 0xff
HF = 0x9c
EF = 0xff
all: $(BUILD)/$(TARGET).hex
testio: $(BUILD)/$(TEST).hex
disasm: $(BUILD)/$(TARGET).elf
$(OBJDUMP) -d $(BUILD)/$(TARGET).elf
size: $(BUILD)/$(TARGET).elf
$(OBJSIZE) -C $(BUILD)/$(TARGET).elf
test:
$(AVRDUDE) -c $(PROGRAMMER) -p $(MCU)
flash: all
$(AVRDUDE) -c $(PROGRAMMER) -p $(MCU) -U flash:w:$(BUILD)/$(TARGET).hex
fuse:
$(AVRDUDE) -c $(PROGRAMMER) -p $(MCU) -U lfuse:w:$(LF):m -U hfuse:w:$(HF):m -U efuse:w:$(EF):m
clean:
rm -f $(BUILD)/$(TARGET).elf
rm -f $(BUILD)/$(TARGET).hex
rm -f $(BUILD)/$(TEST).elf
rm -f $(BUILD)/$(TEST).hex
$(BUILD)/$(TARGET).elf: $(TARGET).c $(INCLUDES) $(LIBRARY)
$(CC) -DF_CPU=$(CLK) -mmcu=$(MCU) $(CFLAGS) $(TARGET).c $(INCLUDES) $(LIBRARY) -o $(BUILD)/$(TARGET).elf
$(BUILD)/$(TARGET).hex: $(BUILD)/$(TARGET).elf
$(OBJCOPY) $(BUILD)/$(TARGET).elf $(BUILD)/$(TARGET).hex -O ihex
$(BUILD)/$(TEST).elf: $(TEST).c $(INCLUDES)
$(CC) -DF_CPU=$(CLK) -mmcu=$(MCU) $(CFLAGS) $(TEST).c $(INCLUDES) -o $(BUILD)/$(TEST).elf
$(BUILD)/$(TEST).hex: $(BUILD)/$(TEST).elf
$(OBJCOPY) $(BUILD)/$(TEST).elf $(BUILD)/$(TEST).hex -O ihex