Subversion Repositories FlightCtrl

Rev

Rev 2053 | Rev 2059 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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