Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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