Subversion Repositories FlightCtrl

Rev

Rev 838 | Details | Compare with Previous | Last modification | View Log | RSS feed

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