Subversion Repositories FlightCtrl

Rev

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

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