/
Makefile
138 lines (99 loc) · 3.89 KB
/
Makefile
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# to use the same copy of v-usb with different defines, compiling needs to run
# through a subcall to make with BUILDDIR set.
BUILDDIR ?= /dev/null
INCLUDES ?=
F_CPU = 16500000
DEVICE = attiny85
FUSEOPT = $(FUSEOPT_t85)
LOCKOPT = -U lock:w:0x2f:m
# hexadecimal address for bootloader section to begin. To calculate the best value:
# - make clean; make main.hex; ### output will list data: 2124 (or something like that)
# - for the size of your device (8kb = 1024 * 8 = 8192) subtract above value 2124... = 6068
# - How many pages in is that? 6068 / 64 (tiny85 page size in bytes) = 94.8125
# - round that down to 94 - our new bootloader address is 94 * 64 = 6016, in hex = 1780
BOOTLOADER_ADDRESS = 1700
# PROGRAMMER contains AVRDUDE options to address your programmer
# This is set for using a TI launchpad programmed as an avr910
PROGRAMMER = -c avr910 -b 9600 -P /dev/ttyACM0
FUSEOPT_t85 = -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m
FUSEOPT_t85_DISABLERESET = -U lfuse:w:0xe1:m -U efuse:w:0xfe:m -U hfuse:w:0x5d:m
# Tools:
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
CC = avr-gcc
# Options:
DEFINES = -DBOOTLOADER_ADDRESS=0x$(BOOTLOADER_ADDRESS) #-DDEBUG_LEVEL=2
# Remove the -fno-* options when you use gcc 3, it does not understand them
CFLAGS = -Wall -Os -fno-move-loop-invariants -fno-tree-scev-cprop \
-fno-inline-small-functions -I. -mmcu=$(DEVICE) \
-DF_CPU=$(F_CPU) $(DEFINES)
CFLAGS += $(INCLUDES)
LDFLAGS = -Wl,--relax,--gc-sections \
-Wl,--section-start=.text=$(BOOTLOADER_ADDRESS)
OSCCAL_OBJECTS = $(BUILDDIR)/osccal/osccal.o
VUSB_OBJECTS = $(BUILDDIR)/usbdrv/usbdrvasm.o $(BUILDDIR)/usbdrv/oddebug.o
BOOTLOADER_OBJECTS = $(BUILDDIR)/bootloader/main.o $(OSCCAL_OBJECTS) \
$(VUSB_OBJECTS)
FIRMWARE_OBJECTS = $(BUILDDIR)/firmware/main.o $(OSCCAL_OBJECTS) \
$(VUSB_OBJECTS) $(BUILDDIR)/usbdrv/usbdrv.o
# symbolic targets:
all: bootloader firmware micronucleus
$(BUILDDIR)/%.o: %.c | $(BUILDDIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: %.S | $(BUILDDIR)
$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@
#.S.o: $(BUILDDIR)
# $(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $(BUILDDIR)/$@
#.c.s: $(BUILDDIR)
# $(CC) $(CFLAGS) -S $< -o $(BUILDDIR)/$@
program: micronucleus firmware
./micronucleus firmware.hex
flash: bootloader
$(AVRDUDE) -U flash:w:bootloader.hex:i
readflash:
$(AVRDUDE) -U flash:r:read.hex:i
fuse:
$(AVRDUDE) $(FUSEOPT)
disablereset:
$(AVRDUDE) $(FUSEOPT_t85_DISABLERESET)
lock:
$(AVRDUDE) $(LOCKOPT)
read_fuses:
$(UISP) --rd_fuses
# Main targets
clean:
rm -f micronucleus
rm -f *.hex
rm -rf build
%.hex: $(BUILDDIR)/%.bin
avr-objcopy -j .text -j .data -O ihex $^ $@
avr-size $@
bootloader:
BUILDDIR=build/$@ INCLUDES=-I$@ $(MAKE) $@.hex
firmware:
BUILDDIR=build/$@ INCLUDES=-I$@ $(MAKE) $@.hex
.PHONY: bootloader firmware
$(BUILDDIR): $(BUILDDIR)/usbdrv $(BUILDDIR)/osccal $(BUILDDIR)/bootloader \
$(BUILDDIR)/firmware $(BUILDDIR)/programmer
build/%:
mkdir -p $@
$(BUILDDIR)/bootloader.bin: $(BOOTLOADER_OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
$(BUILDDIR)/firmware.bin: $(FIRMWARE_OBJECTS)
$(CC) $(CFLAGS) -o $@ $^
######################################################
# Programmer Building (micronucleus)
######################################################
GCC = gcc
MICRONUCLEUS_FILES = programmer/micronucleus.c\
programmer/library/littleWire_util.c\
programmer/library/micronucleus_lib.c
USBFLAGS = `libusb-config --cflags`
USBLIBS = `libusb-config --libs`
OSFLAG = -D LINUX
MICRONUCLEUS_CFLAGS = $(USBFLAGS) $(USBLIBS) -Iprogrammer/library -O -g $(OSFLAG)
micronucleus_builddir: build/programmer build/programmer/library
build/programmer/%.o: programmer/%.c | micronucleus_builddir
$(GCC) $(MICRONUCLEUS_CFLAGS) -c -o $@ $^
micronucleus: $(addprefix build/,$(addsuffix .o, $(basename $(MICRONUCLEUS_FILES))))
echo $(addprefix build/, $(addsuffix .o, $(basename $(MICRONUCLEUS_FILES))))
$(GCC) $(MICRONUCLEUS_CFLAGS) -o $@ $^