Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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