Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
730 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 = MMT
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
ifeq ($(BOARD), MMT)
138
SRC	= main.c menu.c timer.c lcd.c font8X6.c usart.c settings.c motortest.c display.c osd.c debug.c parameter.c status.c eeprom.c
139
else
140
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
141
endif
142
##########################################################################################################
143
 
144
 
145
# List Assembler source files here.
146
# Make them always end in a capital .S.  Files ending in a lowercase .s
147
# will not be considered source files but generated files (assembler
148
# output from the compiler), and will be deleted upon "make clean"!
149
# Even though the DOS/Win* filesystem matches both .s and .S the same,
150
# it will preserve the spelling of the filenames, and gcc itself does
151
# care about how the name is spelled on its command-line.
152
ASRC =
153
 
154
 
155
 
156
# List any extra directories to look for include files here.
157
#     Each directory must be seperated by a space.
158
EXTRAINCDIRS =
159
 
160
 
161
# Optional compiler flags.
162
#  -g:        generate debugging information (for GDB, or for COFF conversion)
163
#  -O*:       optimization level
164
#  -f...:     tuning, see gcc manual and avr-libc documentation
165
#  -Wall...:  warning level
166
#  -Wa,...:   tell GCC to pass this to the assembler.
167
#    -ahlms:  create assembler listing
168
CFLAGS  = -O$(OPT)
169
CFLAGS += -funsigned-char
170
CFLAGS += -funsigned-bitfields
171
CFLAGS += -fpack-struct
172
CFLAGS += -fshort-enums
173
CFLAGS += -Wall
174
CFLAGS += -Wstrict-prototypes
175
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
176
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
177
 
178
 
179
# Compiler flag to set the C Standard level.
180
#   Unremark just one line below to set the language standard to use.
181
#     c89   = "ANSI" C
182
#     gnu89 = c89 plus GCC extensions
183
#     c99   = ISO C99 standard (not yet fully implemented)
184
#     gnu99 = c99 plus GCC extensions
185
#CFLAGS += -std=c89
186
#CFLAGS += -std=gnu89
187
#CFLAGS += -std=c99
188
CFLAGS += -std=gnu99
189
 
190
CFLAGS += -DF_CPU=$(F_CPU)
191
CFLAGS += -DQUARZ=$(QUARZ)
192
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR)
193
CFLAGS += -DVERSION_MINOR=$(VERSION_MINOR)
194
CFLAGS += -DVERSION_PATCH=$(VERSION_PATCH)
195
CFLAGS += -DVERSION_SERIAL_MAJOR=$(VERSION_SERIAL_MAJOR)
196
CFLAGS += -DVERSION_SERIAL_MINOR=$(VERSION_SERIAL_MINOR)
197
 
198
ifeq ($(BOARD), MMT)
199
 CFLAGS += -DUSE_MMT
200
endif
201
ifeq ($(BOARD), MMB)
202
 CFLAGS += -DUSE_MMB
203
endif
204
ifeq ($(BOARD), MMB1)
205
 CFLAGS += -DUSE_MMB1
206
endif
207
 
208
 
209
# Optional assembler flags.
210
#  -Wa,...:   tell GCC to pass this to the assembler.
211
#  -ahlms:    create listing
212
#  -gstabs:   have the assembler create line number information; note that
213
#             for use in COFF files, additional information about filenames
214
#             and function names needs to be present in the assembler source
215
#             files -- see avr-libc docs [FIXME: not yet described there]
216
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
217
 
218
 
219
 
220
# Optional linker flags.
221
#  -Wl,...:   tell GCC to pass this to linker.
222
#  -Map:      create map file
223
#  --cref:    add cross reference to  map file
224
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
225
 
226
# Additional libraries
227
 
228
# Minimalistic printf version
229
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
230
 
231
# Floating point printf version (requires -lm below)
232
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
233
 
234
# -lm = math library
235
LDFLAGS += -lm
236
 
237
 
238
##LDFLAGS += -T./linkerfile/avr5.x
239
 
240
 
241
 
242
# Programming support using avrdude. Settings and variables.
243
 
244
# Programming hardware:
245
#
246
# Type: avrdude -c ?
247
# to get a full listing.
248
#
249
AVRDUDE_PROGRAMMER = usbasp
250
#falls Ponyser ausgewählt wird, muss sich unsere avrdude-Configdatei im Bin-Verzeichnis des Compilers befinden
251
 
252
#AVRDUDE_PORT = com1    # programmer connected to serial device
253
#AVRDUDE_PORT = lpt1    # programmer connected to parallel port
254
#AVRDUDE_PORT = usb     # programmer connected to USB
255
 
256
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
257
AVRDUDE_WRITE_FUSE = $(FUSE_SETTINGS)
258
AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
259
 
260
#avrdude -c avrispv2 -P usb -p m32 -U flash:w:blink.hex
261
#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
262
AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
263
 
264
# Uncomment the following if you want avrdude's erase cycle counter.
265
# Note that this counter needs to be initialized first using -Yn,
266
# see avrdude manual.
267
#AVRDUDE_ERASE += -y
268
 
269
# Uncomment the following if you do /not/ wish a verification to be
270
# performed after programming the device.
271
AVRDUDE_FLAGS += -V
272
 
273
# Increase verbosity level.  Please use this when submitting bug
274
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
275
# to submit bug reports.
276
#AVRDUDE_FLAGS += -v -v
277
 
278
# ---------------------------------------------------------------------------
279
# Define directories, if needed.
280
#DIRAVR = c:/winavr
281
#DIRAVRBIN = $(DIRAVR)/bin
282
#DIRAVRUTILS = $(DIRAVR)/utils/bin
283
#DIRINC = .
284
#DIRLIB = $(DIRAVR)/avr/lib
285
 
286
 
287
# Define programs and commands.
288
SHELL = sh
289
 
290
CC = avr-gcc
291
 
292
OBJCOPY = avr-objcopy
293
OBJDUMP = avr-objdump
294
SIZE = avr-size
295
 
296
# Programming support using avrdude.
297
AVRDUDE = avrdude
298
 
299
REMOVE = rm -f
300
COPY = cp
301
 
302
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
303
##ELFSIZE = $(SIZE) -A $(TARGET).elf
304
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
305
 
306
# Define Messages
307
# English
308
MSG_ERRORS_NONE = Errors: none
309
MSG_BEGIN = -------- begin --------
310
MSG_END = --------  end  --------
311
MSG_SIZE_BEFORE = Size before:
312
MSG_SIZE_AFTER = Size after:
313
MSG_COFF = Converting to AVR COFF:
314
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
315
MSG_FLASH = Creating load file for Flash:
316
MSG_EEPROM = Creating load file for EEPROM:
317
MSG_EXTENDED_LISTING = Creating Extended Listing:
318
MSG_SYMBOL_TABLE = Creating Symbol Table:
319
MSG_LINKING = Linking:
320
MSG_COMPILING = Compiling:
321
MSG_ASSEMBLING = Assembling:
322
MSG_CLEANING = Cleaning project:
323
 
324
 
325
# Define all object files.
326
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
327
 
328
# Define all listing files.
329
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
330
 
331
# Combine all necessary flags and optional flags.
332
# Add target processor to flags.
333
#ALL_CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. $(CFLAGS)
334
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
335
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
336
 
337
 
338
# Default target.
339
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
340
	$(TARGET).lss $(TARGET).sym sizeafter finished end
341
 
342
 
343
# Eye candy.
344
# AVR Studio 3.x does not check make's exit code but relies on
345
# the following magic strings to be generated by the compile job.
346
begin:
347
	@echo
348
	@echo $(MSG_BEGIN)
349
 
350
finished:
351
	@echo $(MSG_ERRORS_NONE)
352
 
353
end:
354
	@echo $(MSG_END)
355
	@echo
356
 
357
 
358
# Display size of file.
359
sizebefore:
360
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
361
 
362
sizeafter:
363
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
364
 
365
 
366
 
367
# Display compiler version information.
368
gccversion :
369
	@$(CC) --version
370
 
371
 
372
# Convert ELF to COFF for use in debugging / simulating in
373
# AVR Studio or VMLAB.
374
COFFCONVERT=$(OBJCOPY) --debugging \
375
	--change-section-address .data-0x800000 \
376
	--change-section-address .bss-0x800000 \
377
	--change-section-address .noinit-0x800000 \
378
	--change-section-address .eeprom-0x810000
379
 
380
 
381
coff: $(TARGET).elf
382
	@echo
383
	@echo $(MSG_COFF) $(TARGET).cof
384
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
385
 
386
 
387
extcoff: $(TARGET).elf
388
	@echo
389
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
390
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
391
 
392
 
393
 
394
 
395
# Program the device.
396
flash: $(TARGET).hex
397
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
398
 
399
eeprom: $(TARGET).eep
400
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM)
401
 
402
fuse:
403
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FUSE)
404
 
405
reset:
406
	$(AVRDUDE) $(AVRDUDE_FLAGS)
407
 
408
 
409
# Create final output files (.hex, .eep) from ELF output file.
410
%.hex: %.elf
411
	@echo
412
	@echo $(MSG_FLASH) $@
413
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
414
 
415
%.eep: %.elf
416
	@echo
417
	@echo $(MSG_EEPROM) $@
418
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
419
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
420
 
421
# Create extended listing file from ELF output file.
422
%.lss: %.elf
423
	@echo
424
	@echo $(MSG_EXTENDED_LISTING) $@
425
	$(OBJDUMP) -h -S $< > $@
426
 
427
# Create a symbol table from ELF output file.
428
%.sym: %.elf
429
	@echo
430
	@echo $(MSG_SYMBOL_TABLE) $@
431
	avr-nm -n $< > $@
432
 
433
 
434
# Link: create ELF output file from object files.
435
.SECONDARY : $(TARGET).elf
436
.PRECIOUS : $(OBJ)
437
%.elf: $(OBJ)
438
	@echo
439
	@echo $(MSG_LINKING) $@
440
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
441
 
442
 
443
# Compile: create object files from C source files.
444
%.o : %.c
445
	@echo
446
	@echo $(MSG_COMPILING) $<
447
	$(CC) -c $(ALL_CFLAGS) $< -o $@
448
 
449
 
450
# Compile: create assembler files from C source files.
451
%.s : %.c
452
	$(CC) -S $(ALL_CFLAGS) $< -o $@
453
 
454
 
455
# Assemble: create object files from assembler source files.
456
%.o : %.S
457
	@echo
458
	@echo $(MSG_ASSEMBLING) $<
459
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
460
 
461
 
462
# Target: clean project.
463
clean: begin clean_list finished end
464
 
465
clean_list :
466
	@echo
467
	@echo $(MSG_CLEANING)
468
#	$(REMOVE) $(TARGET).hex
469
	$(REMOVE) $(TARGET).eep
470
	$(REMOVE) $(TARGET).obj
471
	$(REMOVE) $(TARGET).cof
472
	$(REMOVE) $(TARGET).elf
473
	$(REMOVE) $(TARGET).map
474
	$(REMOVE) $(TARGET).obj
475
	$(REMOVE) $(TARGET).a90
476
	$(REMOVE) $(TARGET).sym
477
	$(REMOVE) $(TARGET).lnk
478
	$(REMOVE) $(TARGET).lss
479
	$(REMOVE) $(OBJ)
480
	$(REMOVE) $(LST)
481
	$(REMOVE) $(SRC:.c=.s)
482
	$(REMOVE) $(SRC:.c=.d)
483
	@echo
484
 
485
 
486
# Automatically generate C source code dependencies.
487
# (Code originally taken from the GNU make user manual and modified
488
# (See README.txt Credits).)
489
#
490
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
491
# (see the SHELL variable defined above).
492
# This may not work with other shells or other seds.
493
#
494
%.d: %.c
495
	@set -e; $(CC) -MM $(ALL_CFLAGS) $< \
496
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
497
	[ -s $@ ] || rm -f $@
498
 
499
 
500
# Remove the '-' if you want to see the dependency files generated.
501
-include $(SRC:.c=.d)
502
 
503
 
504
# Listing of phony targets.
505
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff clean clean_list flash eeprom fuse reset