Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2226 - 1
# MCU name
2
MCU = atmega32
3
 
4
# Crystal frequency 16 MHz
5
F_CPU = 16000000
6
 
7
 
8
# Output format. (can be srec, ihex, binary)
9
FORMAT = ihex
10
 
11
# Target file name (without extension).
12
TARGET = main
13
 
14
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
15
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
16
OPT = s
17
 
18
##########################################################################################################
19
# List C source files here. (C dependencies are automatically generated.)
20
SRC = main.c timer.c twimaster.c analog.c
21
##########################################################################################################
22
# If there is more than one source file, append them above, or modify and
23
# uncomment the following:
24
#SRC += foo.c bar.c
25
 
26
# You can also wrap lines by appending a backslash to the end of the line:
27
#SRC += baz.c \
28
 
29
# List Assembler source files here.
30
# Make them always end in a capital .S.  Files ending in a lowercase .s
31
# will not be considered source files but generated files (assembler
32
# output from the compiler), and will be deleted upon "make clean"!
33
# Even though the DOS/Win* filesystem matches both .s and .S the same,
34
# it will preserve the spelling of the filenames, and gcc itself does
35
# care about how the name is spelled on its command-line.
36
ASRC =
37
 
38
 
39
# List any extra directories to look for include files here.
40
#     Each directory must be seperated by a space.
41
EXTRAINCDIRS =
42
 
43
 
44
# Optional compiler flags.
45
#  -g:        generate debugging information (for GDB, or for COFF conversion)
46
#  -O*:       optimization level
47
#  -f...:     tuning, see gcc manual and avr-libc documentation
48
#  -Wall...:  warning level
49
#  -Wa,...:   tell GCC to pass this to the assembler.
50
#    -ahlms:  create assembler listing
51
CFLAGS = -g -O$(OPT) \
52
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
53
-Wall -Wstrict-prototypes \
54
-Wa,-adhlns=$(<:.c=.lst) \
55
$(patsubst %,-I%,$(EXTRAINCDIRS))
56
 
57
 
58
# Set a "language standard" compiler flag.
59
#   Unremark just one line below to set the language standard to use.
60
#   gnu99 = C99 + GNU extensions. See GCC manual for more information.
61
#CFLAGS += -std=c89
62
#CFLAGS += -std=gnu89
63
#CFLAGS += -std=c99
64
CFLAGS += -std=gnu99
65
 
66
 
67
 
68
# Optional assembler flags.
69
#  -Wa,...:   tell GCC to pass this to the assembler.
70
#  -ahlms:    create listing
71
#  -gstabs:   have the assembler create line number information; note that
72
#             for use in COFF files, additional information about filenames
73
#             and function names needs to be present in the assembler source
74
#             files -- see avr-libc docs [FIXME: not yet described there]
75
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
76
 
77
 
78
 
79
# Optional linker flags.
80
#  -Wl,...:   tell GCC to pass this to linker.
81
#  -Map:      create map file
82
#  --cref:    add cross reference to  map file
83
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
84
 
85
 
86
 
87
# Additional libraries
88
 
89
# Minimalistic printf version
90
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
91
 
92
# Floating point printf version (requires -lm below)
93
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
94
 
95
# -lm = math library
96
LDFLAGS += -lm
97
 
98
 
99
# Programming support using avrdude. Settings and variables.
100
 
101
# Programming hardware: alf avr910 avrisp bascom bsd
102
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
103
#
104
# Type: avrdude -c ?
105
# to get a full listing.
106
#
107
# AVRDUDE_PROGRAMMER = ponyser
108
AVRDUDE_PROGRAMMER = avrispmkII
109
 
110
# AVRDUDE_PORT = com1
111
AVRDUDE_PORT = usb
112
 
113
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
114
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
115
 
116
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
117
 
118
# Uncomment the following if you want avrdude's erase cycle counter.
119
# Note that this counter needs to be initialized first using -Yn,
120
# see avrdude manual.
121
#AVRDUDE_ERASE += -y
122
 
123
# Uncomment the following if you do /not/ wish a verification to be
124
# performed after programming the device.
125
AVRDUDE_FLAGS += -V
126
 
127
# Increase verbosity level.  Please use this when submitting bug
128
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
129
# to submit bug reports.
130
#AVRDUDE_FLAGS += -v -v
131
 
132
 
133
# ---------------------------------------------------------------------------
134
 
135
# Define directories, if needed.
136
DIRAVR = c:/winavr
137
DIRAVRBIN = $(DIRAVR)/bin
138
DIRAVRUTILS = $(DIRAVR)/utils/bin
139
DIRINC = .
140
DIRLIB = $(DIRAVR)/avr/lib
141
 
142
 
143
# Define programs and commands.
144
SHELL = sh
145
 
146
CC = avr-gcc
147
 
148
OBJCOPY = avr-objcopy
149
OBJDUMP = avr-objdump
150
SIZE = avr-size
151
 
152
 
153
# Programming support using avrdude.
154
AVRDUDE = avrdude
155
 
156
 
157
REMOVE = rm -f
158
COPY = cp
159
 
160
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
161
ELFSIZE = $(SIZE) -A $(TARGET).elf
162
 
163
 
164
 
165
# Define Messages
166
# English
167
MSG_ERRORS_NONE = Errors: none
168
MSG_BEGIN = -------- begin --------
169
MSG_END = --------  end  --------
170
MSG_SIZE_BEFORE = Size before:
171
MSG_SIZE_AFTER = Size after:
172
MSG_COFF = Converting to AVR COFF:
173
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
174
MSG_FLASH = Creating load file for Flash:
175
MSG_EEPROM = Creating load file for EEPROM:
176
MSG_EXTENDED_LISTING = Creating Extended Listing:
177
MSG_SYMBOL_TABLE = Creating Symbol Table:
178
MSG_LINKING = Linking:
179
MSG_COMPILING = Compiling:
180
MSG_ASSEMBLING = Assembling:
181
MSG_CLEANING = Cleaning project:
182
 
183
 
184
 
185
 
186
# Define all object files.
187
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
188
 
189
# Define all listing files.
190
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
191
 
192
# Combine all necessary flags and optional flags.
193
# Add target processor to flags.
194
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
195
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
196
 
197
 
198
 
199
# Default target.
200
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
201
	$(TARGET).lss $(TARGET).sym sizeafter finished end
202
 
203
 
204
# Eye candy.
205
# AVR Studio 3.x does not check make's exit code but relies on
206
# the following magic strings to be generated by the compile job.
207
begin:
208
	@echo
209
	@echo $(MSG_BEGIN)
210
 
211
finished:
212
	@echo $(MSG_ERRORS_NONE)
213
 
214
end:
215
	@echo $(MSG_END)
216
	@echo
217
 
218
 
219
# Display size of file.
220
sizebefore:
221
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
222
 
223
sizeafter:
224
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
225
 
226
 
227
 
228
# Display compiler version information.
229
gccversion :
230
	@$(CC) --version
231
 
232
 
233
 
234
 
235
# Convert ELF to COFF for use in debugging / simulating in
236
# AVR Studio or VMLAB.
237
COFFCONVERT=$(OBJCOPY) --debugging \
238
	--change-section-address .data-0x800000 \
239
	--change-section-address .bss-0x800000 \
240
	--change-section-address .noinit-0x800000 \
241
	--change-section-address .eeprom-0x810000
242
 
243
 
244
coff: $(TARGET).elf
245
	@echo
246
	@echo $(MSG_COFF) $(TARGET).cof
247
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
248
 
249
 
250
extcoff: $(TARGET).elf
251
	@echo
252
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
253
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
254
 
255
 
256
 
257
 
258
# Program the device.
259
program: $(TARGET).hex $(TARGET).eep
260
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
261
 
262
 
263
 
264
 
265
# Create final output files (.hex, .eep) from ELF output file.
266
%.hex: %.elf
267
	@echo
268
	@echo $(MSG_FLASH) $@
269
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
270
 
271
%.eep: %.elf
272
	@echo
273
	@echo $(MSG_EEPROM) $@
274
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
275
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
276
 
277
# Create extended listing file from ELF output file.
278
%.lss: %.elf
279
	@echo
280
	@echo $(MSG_EXTENDED_LISTING) $@
281
	$(OBJDUMP) -h -S $< > $@
282
 
283
# Create a symbol table from ELF output file.
284
%.sym: %.elf
285
	@echo
286
	@echo $(MSG_SYMBOL_TABLE) $@
287
	avr-nm -n $< > $@
288
 
289
 
290
 
291
# Link: create ELF output file from object files.
292
.SECONDARY : $(TARGET).elf
293
.PRECIOUS : $(OBJ)
294
%.elf: $(OBJ)
295
	@echo
296
	@echo $(MSG_LINKING) $@
297
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
298
 
299
 
300
# Compile: create object files from C source files.
301
%.o : %.c
302
	@echo
303
	@echo $(MSG_COMPILING) $<
304
	$(CC) -c $(ALL_CFLAGS) $< -o $@
305
 
306
 
307
# Compile: create assembler files from C source files.
308
%.s : %.c
309
	$(CC) -S $(ALL_CFLAGS) $< -o $@
310
 
311
 
312
# Assemble: create object files from assembler source files.
313
%.o : %.S
314
	@echo
315
	@echo $(MSG_ASSEMBLING) $<
316
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
317
 
318
 
319
 
320
 
321
# Target: clean project.
322
clean: begin clean_list finished end
323
 
324
clean_list :
325
	@echo
326
	@echo $(MSG_CLEANING)
327
#	$(REMOVE) $(TARGET).hex
328
	$(REMOVE) $(TARGET).eep
329
	$(REMOVE) $(TARGET).obj
330
	$(REMOVE) $(TARGET).cof
331
	$(REMOVE) $(TARGET).elf
332
	$(REMOVE) $(TARGET).map
333
	$(REMOVE) $(TARGET).obj
334
	$(REMOVE) $(TARGET).a90
335
	$(REMOVE) $(TARGET).sym
336
	$(REMOVE) $(TARGET).lnk
337
	$(REMOVE) $(TARGET).lss
338
	$(REMOVE) $(OBJ)
339
	$(REMOVE) $(LST)
340
	$(REMOVE) $(SRC:.c=.s)
341
	$(REMOVE) $(SRC:.c=.d)
342
 
343
 
344
# Automatically generate C source code dependencies.
345
# (Code originally taken from the GNU make user manual and modified
346
# (See README.txt Credits).)
347
#
348
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
349
# (see the SHELL variable defined above).
350
# This may not work with other shells or other seds.
351
#
352
%.d: %.c
353
	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
354
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
355
	[ -s $@ ] || rm -f $@
356
 
357
 
358
# Remove the '-' if you want to see the dependency files generated.
359
-include $(SRC:.c=.d)
360
 
361
 
362
 
363
# Listing of phony targets.
364
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
365
	clean clean_list program
366