Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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