Subversion Repositories FlightCtrl

Rev

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

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