-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
113 lines (77 loc) · 2.93 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
PRG = counter
OBJ = counter.o EERTOS.o EERTOSHAL.o HAL.o
PROGRAMMER = usbasp
PORT = usb
MCU_TARGET = attiny2313
AVRDUDE_TARGET = attiny2313
Q_OPT = -fgcse-las -fgcse-sm -fmodulo-sched -fmodulo-sched-allow-regmoves \
-freorder-blocks -freorder-blocks-and-partition -freschedule-modulo-scheduled-loops \
-frtl-abstract-sequences -fsched-spec-load-dangerous -fsched-stalled-insns=0
OPTIMIZE = -Os -fshort-enums -fcse-skip-blocks -fomit-frame-pointer -Wl,--gc-section -ffunction-sections -fdata-sections\
-fgcse-after-reload -fipa-cp -fipa-matrix-reorg -fpredictive-commoning
OPTIMIZE += $(Q_OPT)
DEFS = -I.
LIBS =
HZ = 1000000
# You should not have to change anything below here.
CC = avr-gcc
# Override is only needed by avr-lib build system.
override CFLAGS =-gdwarf-2 -DF_CPU=$(HZ)L -Wall -Winline -Wextra $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override LDFLAGS = -Wl,-Map,$(PRG).map
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: $(PRG).elf lst text size #eeprom
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
size:
avr-size -C --mcu=$(MCU_TARGET) $(PRG).elf
clean:
rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak *.hex *.bin *.srec *~
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# Rules for building the .text rom images
text: hex bin srec
hex: $(PRG).hex
bin: $(PRG).bin
srec: $(PRG).srec
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
# Rules for building the .eeprom rom images
eeprom: ehex ebin esrec
ehex: $(PRG)_eeprom.hex
ebin: $(PRG)_eeprom.bin
esrec: $(PRG)_eeprom.srec
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
# command to program chip (invoked by running "make install")
install: $(PRG).hex
avrdude -p $(AVRDUDE_TARGET) -c $(PROGRAMMER) -P $(PORT) \
-U flash:w:$(PRG).hex
install_eeprom: $(PRG).hex
avrdude -p $(AVRDUDE_TARGET) -c $(PROGRAMMER) -P $(PORT) \
-U eeprom:w:$(PRG)_eeprom.hex
fuse:
avrdude -p $(AVRDUDE_TARGET) -c $(PROGRAMMER) -P $(PORT) -v \
-U lfuse:w:0xc6:m -U hfuse:w:0xd9:m
ddd: gdbinit
ddd --debugger "avr-gdb -x $(GDBINITFILE)"
gdbserver: gdbinit
simulavr --device $(MCU_TARGET) --gdbserver
gdbinit: $(GDBINITFILE)
$(GDBINITFILE): $(PRG).hex
@echo "file $(PRG).elf" > $(GDBINITFILE)
@echo "target remote localhost:1212" >> $(GDBINITFILE)
@echo "load" >> $(GDBINITFILE)
@echo "break main" >> $(GDBINITFILE)
@echo
@echo "Use 'avr-gdb -x $(GDBINITFILE)'"