Subversion Repositories FlightCtrl

Rev

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

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