-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
271 lines (201 loc) · 6.29 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
##### This Makefile will make compiling Atmel AVR
##### micro controller projects simple with Linux
##### or other Unix workstations and the AVR-GCC
##### tools.
#####
##### It supports C, C++ and Assembly source files.
#####
##### Customize the values as indicated below and :
##### make
##### make disasm
##### make stats
##### make hex
##### make writeflash
##### make gdbinit
##### or make clean
#####
##### See the http://electrons.psychogenic.com/
##### website for detailed instructions
#MCU=atmega328p
#PROGRAMMER_MCU=m328p
MCU=atmega328p
PROGRAMMER_MCU=m328p
# Name of our project
# (use a single word, e.g. 'myproject')
PROJECTNAME=DreamMaskV4
# Source files
# List C/C++/Assembly source files:
# (list all files to compile, e.g. 'a.c b.cpp as.S'):
# Use .cc, .cpp or .C suffix for C++ files, use .S
# (NOT .s !!!) for assembly source code files.
PRJSRC=main.c power.c clock.c serial.c flash.c spi.c commands.c adc.c buttons.c calib_32kHz.c leds.c morse.c detector.c ringbuffer.c alarm.c
# additional includes (e.g. -I/path/to/mydir)
#INC=-I/path/to/include
# libraries to link in (e.g. -lmylib)
LIBS=
# Optimization level,
# use s (size opt), 1, 2, 3 or 0 (off)
OPTLEVEL=s
##### AVR Dude 'writeflash' options #####
##### If you are using the avrdude program
##### (http://www.bsdhome.com/avrdude/) to write
##### to the MCU, you can set the following config
##### options and use 'make writeflash' to program
##### the device.
# programmer id--check the avrdude for complete list
# of available opts. These should include stk500,
# avr910, avrisp, bsd, pony and more. Set this to
# one of the valid "-c PROGRAMMER-ID" values
# described in the avrdude info page.
#
AVRDUDE_PROGRAMMERID=stk500
# port--serial or parallel port to which your
# hardware programmer is attached
#
AVRDUDE_PORT=/dev/ttyACM0
####################################################
##### Config Done #####
##### #####
##### You shouldn't need to edit anything #####
##### below to use the makefile but may wish #####
##### to override a few of the flags #####
##### nonetheless #####
##### #####
####################################################
##### Flags ####
# HEXFORMAT -- format for .hex file output
HEXFORMAT=ihex
# compiler
CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wextra -Werror -Wstrict-prototypes \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.c=.lst)))
# c++ specific flags
CPPFLAGS=-fno-exceptions \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.cpp=.lst))\
$(filter %.lst, $(<:.cc=.lst)) \
$(filter %.lst, $(<:.C=.lst)))
# assembler
ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-Wa,-gstabs,-ahlms=$(firstword \
$(<:.S=.lst) $(<.s=.lst))
# linker
LDFLAGS=-Wl,-Map,$(TRG).map -mmcu=$(MCU) \
-lm $(LIBS)
##### executables ####
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
SIZE=avr-size
AVRDUDE=avrdude
REMOVE=rm -f
##### automatic target names ####
TRG=$(PROJECTNAME).out
DUMPTRG=$(PROJECTNAME).s
HEXROMTRG=$(PROJECTNAME).hex
HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex
GDBINITFILE=gdbinit-$(PROJECTNAME)
# Define all object files.
# Start by splitting source files by type
# C++
CPPFILES=$(filter %.cpp, $(PRJSRC))
CCFILES=$(filter %.cc, $(PRJSRC))
BIGCFILES=$(filter %.C, $(PRJSRC))
# C
CFILES=$(filter %.c, $(PRJSRC))
# Assembly
ASMFILES=$(filter %.S, $(PRJSRC))
# List all object files we need to create
OBJDEPS=$(CFILES:.c=.o) \
$(CPPFILES:.cpp=.o)\
$(BIGCFILES:.C=.o) \
$(CCFILES:.cc=.o) \
$(ASMFILES:.S=.o)
# Define all lst files.
LST=$(filter %.lst, $(OBJDEPS:.o=.lst))
# All the possible generated assembly
# files (.s files)
GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s))
.SUFFIXES : .c .cc .cpp .C .o .out .s .S \
.hex .ee.hex .h .hh .hpp
.PHONY: writeflash clean stats gdbinit stats install fuses program
detectortest: detectortest.c ringbuffer.c detector.c ringbuffer.h detector.h
gcc -o dt detectortest.c ringbuffer.c detector.c
# Make targets:
# all, disasm, stats, hex, writeflash/install, clean
all: $(TRG)
disasm: $(DUMPTRG) stats
stats: $(TRG)
$(OBJDUMP) -h $(TRG)
$(SIZE) $(TRG)
hex: $(HEXTRG)
writeflash: hex
$(AVRDUDE) -B2.2 -c $(AVRDUDE_PROGRAMMERID) \
-p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(HEXROMTRG)
fuses:
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e \
-U lfuse:w:0x7e:m -U hfuse:w:0xd9:m -U efuse:w:0x07:m
install: writeflash
program: writeflash
$(DUMPTRG): $(TRG)
$(OBJDUMP) -S $< > $@
$(TRG): $(OBJDEPS)
$(CC) $(LDFLAGS) -o $(TRG) $(OBJDEPS)
#### Generating assembly ####
# asm from C
%.s: %.c
$(CC) -S $(CFLAGS) $< -o $@
# asm from (hand coded) asm
%.s: %.S
$(CC) -S $(ASMFLAGS) $< > $@
# asm from C++
.cpp.s .cc.s .C.s :
$(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o $@
#### Generating object files ####
# object from C
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# object from C++ (.cc, .cpp, .C files)
.cc.o .cpp.o .C.o :
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# object from asm
.S.o :
$(CC) $(ASMFLAGS) -c $< -o $@
#### Generating hex files ####
# hex files from elf
##### Generating a gdb initialisation file #####
.out.hex:
$(OBJCOPY) -j .text \
-j .data \
-O $(HEXFORMAT) $< $@
.out.ee.hex:
$(OBJCOPY) -j .eeprom \
--change-section-lma .eeprom=0 \
-O $(HEXFORMAT) $< $@
##### Generating a gdb initialisation file #####
##### Use by launching simulavr and avr-gdb: #####
##### avr-gdb -x gdbinit-myproject #####
gdbinit: $(GDBINITFILE)
$(GDBINITFILE): $(TRG)
@echo "file $(TRG)" > $(GDBINITFILE)
@echo "target remote localhost:1212" \
>> $(GDBINITFILE)
@echo "load" >> $(GDBINITFILE)
@echo "break main" >> $(GDBINITFILE)
@echo "continue" >> $(GDBINITFILE)
@echo
@echo "Use 'avr-gdb -x $(GDBINITFILE)'"
#### Cleanup ####
clean:
$(REMOVE) $(TRG) $(TRG).map $(DUMPTRG)
$(REMOVE) $(OBJDEPS)
$(REMOVE) $(LST) $(GDBINITFILE)
$(REMOVE) $(GENASMFILES)
$(REMOVE) $(HEXTRG)
##### EOF #####