Subversion Repositories Projects

Rev

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

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