Subversion Repositories BL-Ctrl

Rev

Rev 66 | Rev 69 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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