Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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