Subversion Repositories FlightCtrl

Rev

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