Subversion Repositories FlightCtrl

Rev

Rev 1617 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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