Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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