Subversion Repositories FlightCtrl

Rev

Rev 2164 | Details | Compare with Previous | Last modification | View Log | RSS feed

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