Subversion Repositories FlightCtrl

Rev

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