Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
#--------------------------------------------------------------------
2
# MCU name
1097 killagreg 3
#MCU = atmega644
4
MCU = atmega644p
1 ingob 5
F_CPU = 20000000
6
#-------------------------------------------------------------------
1078 killagreg 7
VERSION_MAJOR    =  0
8
VERSION_MINOR    =  71
9
VERSION_PATCH    =  7
297 holgerb 10
 
1078 killagreg 11
VERSION_SERIAL_MAJOR = 10	# Serial Protocol Major Version
12
VERSION_SERIAL_MINOR = 0	# Serial Protocol Minor Version
1082 killagreg 13
NC_SPI_COMPATIBLE = 3 		# SPI Protocol Version
1078 killagreg 14
 
1 ingob 15
#-------------------------------------------------------------------
886 killagreg 16
#OPTIONS
908 killagreg 17
# Use one of the extensions for a gps solution
1097 killagreg 18
#EXT = KILLAGREG
19
EXT = NAVICTRL
913 killagreg 20
#EXT = MK3MAG
886 killagreg 21
#-------------------------------------------------------------------
961 killagreg 22
# get SVN revision
23
REV := $(shell sh -c "cat .svn/entries | sed -n '4p'")
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
886 killagreg 29
 HEX_NAME = MEGA644_$(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
886 killagreg 34
 HEX_NAME = MEGA644p_$(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
 
1078 killagreg 52
ifeq ($(VERSION_PATCH), 0)
53
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)a_SVN$(REV)
297 holgerb 54
endif
1078 killagreg 55
ifeq ($(VERSION_PATCH), 1)
56
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)b_SVN$(REV)
297 holgerb 57
endif
1078 killagreg 58
ifeq ($(VERSION_PATCH), 2)
59
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)c_SVN$(REV)
297 holgerb 60
endif
1078 killagreg 61
ifeq ($(VERSION_PATCH), 3)
62
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)d_SVN$(REV)
297 holgerb 63
endif
1078 killagreg 64
ifeq ($(VERSION_PATCH), 4)
65
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)e_SVN$(REV)
297 holgerb 66
endif
1078 killagreg 67
ifeq ($(VERSION_PATCH), 5)
68
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)f_SVN$(REV)
297 holgerb 69
endif
1078 killagreg 70
ifeq ($(VERSION_PATCH), 6)
71
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)g_SVN$(REV)
469 hbuss 72
endif
1078 killagreg 73
ifeq ($(VERSION_PATCH), 7)
74
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)h_SVN$(REV)
469 hbuss 75
endif
1078 killagreg 76
ifeq ($(VERSION_PATCH), 8)
77
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)i_SVN$(REV)
855 hbuss 78
endif
1078 killagreg 79
ifeq ($(VERSION_PATCH), 9)
80
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)j_SVN$(REV)
855 hbuss 81
endif
1078 killagreg 82
ifeq ($(VERSION_PATCH), 10)
83
TARGET = Flight-Ctrl_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)k_SVN$(REV)
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
908 killagreg 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
 
1078 killagreg 148
CFLAGS += -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)
1 ingob 149
 
886 killagreg 150
ifeq ($(EXT), KILLAGREG)
151
 CFLAGS += -DUSE_KILLAGREG
152
endif
908 killagreg 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
 
886 killagreg 160
 
161
 
162
 
1 ingob 163
# Optional assembler flags.
164
#  -Wa,...:   tell GCC to pass this to the assembler.
165
#  -ahlms:    create listing
166
#  -gstabs:   have the assembler create line number information; note that
167
#             for use in COFF files, additional information about filenames
168
#             and function names needs to be present in the assembler source
169
#             files -- see avr-libc docs [FIXME: not yet described there]
170
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
171
 
172
 
173
 
174
# Optional linker flags.
175
#  -Wl,...:   tell GCC to pass this to linker.
176
#  -Map:      create map file
177
#  --cref:    add cross reference to  map file
178
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
179
 
180
# Additional libraries
181
 
182
# Minimalistic printf version
183
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
184
 
185
# Floating point printf version (requires -lm below)
186
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
187
 
188
# -lm = math library
189
LDFLAGS += -lm
190
 
191
 
192
##LDFLAGS += -T./linkerfile/avr5.x
193
 
194
 
195
 
196
# Programming support using avrdude. Settings and variables.
197
 
198
# Programming hardware: alf avr910 avrisp bascom bsd
199
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
200
#
201
# Type: avrdude -c ?
202
# to get a full listing.
203
#
595 hbuss 204
#AVRDUDE_PROGRAMMER = dt006
1 ingob 205
#AVRDUDE_PROGRAMMER = stk200
206
#AVRDUDE_PROGRAMMER = ponyser
595 hbuss 207
AVRDUDE_PROGRAMMER = avrispv2
1 ingob 208
#falls Ponyser ausgewählt wird, muss sich unsere avrdude-Configdatei im Bin-Verzeichnis des Compilers befinden
209
 
595 hbuss 210
#AVRDUDE_PORT = com1    # programmer connected to serial device
211
#AVRDUDE_PORT = lpt1    # programmer connected to parallel port
212
AVRDUDE_PORT = usb # programmer connected to USB
1 ingob 213
 
214
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
215
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_SETTINGS)
216
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
217
 
595 hbuss 218
#avrdude -c avrispv2 -P usb -p m32 -U flash:w:blink.hex
1 ingob 219
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
220
 
221
# Uncomment the following if you want avrdude's erase cycle counter.
222
# Note that this counter needs to be initialized first using -Yn,
223
# see avrdude manual.
224
#AVRDUDE_ERASE += -y
225
 
226
# Uncomment the following if you do /not/ wish a verification to be
227
# performed after programming the device.
228
AVRDUDE_FLAGS += -V
229
 
230
# Increase verbosity level.  Please use this when submitting bug
231
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
232
# to submit bug reports.
233
#AVRDUDE_FLAGS += -v -v
234
 
235
# ---------------------------------------------------------------------------
236
# Define directories, if needed.
237
DIRAVR = c:/winavr
238
DIRAVRBIN = $(DIRAVR)/bin
239
DIRAVRUTILS = $(DIRAVR)/utils/bin
240
DIRINC = .
241
DIRLIB = $(DIRAVR)/avr/lib
242
 
243
 
244
# Define programs and commands.
245
SHELL = sh
246
 
247
CC = avr-gcc
248
 
249
OBJCOPY = avr-objcopy
250
OBJDUMP = avr-objdump
251
SIZE = avr-size
252
 
253
# Programming support using avrdude.
254
AVRDUDE = avrdude
255
 
256
REMOVE = rm -f
257
COPY = cp
258
 
259
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
260
ELFSIZE = $(SIZE) -A $(TARGET).elf
261
 
262
# Define Messages
263
# English
264
MSG_ERRORS_NONE = Errors: none
265
MSG_BEGIN = -------- begin --------
266
MSG_END = --------  end  --------
267
MSG_SIZE_BEFORE = Size before:
268
MSG_SIZE_AFTER = Size after:
269
MSG_COFF = Converting to AVR COFF:
270
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
271
MSG_FLASH = Creating load file for Flash:
272
MSG_EEPROM = Creating load file for EEPROM:
273
MSG_EXTENDED_LISTING = Creating Extended Listing:
274
MSG_SYMBOL_TABLE = Creating Symbol Table:
275
MSG_LINKING = Linking:
276
MSG_COMPILING = Compiling:
277
MSG_ASSEMBLING = Assembling:
278
MSG_CLEANING = Cleaning project:
279
 
280
 
281
# Define all object files.
282
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
283
 
284
# Define all listing files.
285
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
286
 
287
# Combine all necessary flags and optional flags.
288
# Add target processor to flags.
289
#ALL_CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. $(CFLAGS)
290
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
291
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
292
 
293
 
294
# Default target.
295
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
296
	$(TARGET).lss $(TARGET).sym sizeafter finished end
297
 
298
 
299
# Eye candy.
300
# AVR Studio 3.x does not check make's exit code but relies on
301
# the following magic strings to be generated by the compile job.
302
begin:
303
	@echo
304
	@echo $(MSG_BEGIN)
305
 
306
finished:
307
	@echo $(MSG_ERRORS_NONE)
308
 
309
end:
310
	@echo $(MSG_END)
311
	@echo
312
 
313
 
314
# Display size of file.
315
sizebefore:
316
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
317
 
318
sizeafter:
319
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
320
 
321
 
322
 
323
# Display compiler version information.
324
gccversion :
325
	@$(CC) --version
326
 
327
 
328
# Convert ELF to COFF for use in debugging / simulating in
329
# AVR Studio or VMLAB.
330
COFFCONVERT=$(OBJCOPY) --debugging \
331
	--change-section-address .data-0x800000 \
332
	--change-section-address .bss-0x800000 \
333
	--change-section-address .noinit-0x800000 \
334
	--change-section-address .eeprom-0x810000
335
 
336
 
337
coff: $(TARGET).elf
338
	@echo
339
	@echo $(MSG_COFF) $(TARGET).cof
340
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
341
 
342
 
343
extcoff: $(TARGET).elf
344
	@echo
345
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
346
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
347
 
348
 
349
 
350
 
351
# Program the device.
352
program: $(TARGET).hex $(TARGET).eep
353
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
354
 
355
 
356
 
357
 
358
# Create final output files (.hex, .eep) from ELF output file.
359
%.hex: %.elf
360
	@echo
361
	@echo $(MSG_FLASH) $@
362
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
363
 
364
%.eep: %.elf
365
	@echo
366
	@echo $(MSG_EEPROM) $@
367
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
368
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
369
 
370
# Create extended listing file from ELF output file.
371
%.lss: %.elf
372
	@echo
373
	@echo $(MSG_EXTENDED_LISTING) $@
374
	$(OBJDUMP) -h -S $< > $@
375
 
376
# Create a symbol table from ELF output file.
377
%.sym: %.elf
378
	@echo
379
	@echo $(MSG_SYMBOL_TABLE) $@
380
	avr-nm -n $< > $@
381
 
382
 
383
 
384
# Link: create ELF output file from object files.
385
.SECONDARY : $(TARGET).elf
386
.PRECIOUS : $(OBJ)
387
%.elf: $(OBJ)
388
	@echo
389
	@echo $(MSG_LINKING) $@
390
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
391
 
392
 
393
# Compile: create object files from C source files.
394
%.o : %.c
395
	@echo
396
	@echo $(MSG_COMPILING) $<
397
	$(CC) -c $(ALL_CFLAGS) $< -o $@
398
 
399
 
400
# Compile: create assembler files from C source files.
401
%.s : %.c
402
	$(CC) -S $(ALL_CFLAGS) $< -o $@
403
 
404
 
405
# Assemble: create object files from assembler source files.
406
%.o : %.S
407
	@echo
408
	@echo $(MSG_ASSEMBLING) $<
409
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
410
 
411
 
412
 
413
 
414
 
415
 
416
# Target: clean project.
417
clean: begin clean_list finished end
418
 
419
clean_list :
420
	@echo
421
	@echo $(MSG_CLEANING)
422
#	$(REMOVE) $(TARGET).hex
423
	$(REMOVE) $(TARGET).eep
424
	$(REMOVE) $(TARGET).obj
425
	$(REMOVE) $(TARGET).cof
426
	$(REMOVE) $(TARGET).elf
427
	$(REMOVE) $(TARGET).map
428
	$(REMOVE) $(TARGET).obj
429
	$(REMOVE) $(TARGET).a90
430
	$(REMOVE) $(TARGET).sym
431
	$(REMOVE) $(TARGET).lnk
432
	$(REMOVE) $(TARGET).lss
433
	$(REMOVE) $(OBJ)
434
	$(REMOVE) $(LST)
435
	$(REMOVE) $(SRC:.c=.s)
436
	$(REMOVE) $(SRC:.c=.d)
437
 
438
 
439
# Automatically generate C source code dependencies.
440
# (Code originally taken from the GNU make user manual and modified
441
# (See README.txt Credits).)
442
#
443
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
444
# (see the SHELL variable defined above).
445
# This may not work with other shells or other seds.
446
#
447
%.d: %.c
448
	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
449
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
450
	[ -s $@ ] || rm -f $@
451
 
452
 
453
# Remove the '-' if you want to see the dependency files generated.
454
-include $(SRC:.c=.d)
455
 
456
 
457
 
458
# Listing of phony targets.
459
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
460
	clean clean_list program
461