Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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