Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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