Subversion Repositories FlightCtrl

Rev

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