Subversion Repositories FlightCtrl

Rev

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

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