Subversion Repositories FlightCtrl

Rev

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