Subversion Repositories FlightCtrl

Rev

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

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