Subversion Repositories FlightCtrl

Rev

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