Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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