Subversion Repositories FlightCtrl

Rev

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

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