Subversion Repositories BL-Ctrl

Rev

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

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