Subversion Repositories FlightCtrl

Rev

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

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