Subversion Repositories FlightCtrl

Rev

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

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