Subversion Repositories BL-Ctrl

Rev

Rev 69 | 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:
70 jan-hendri 204
MSG_MOVE = Moving Files:
66 jan-hendri 205
 
206
 
207
 
208
 
209
# Define all object files.
210
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
211
 
212
# Define all listing files.
213
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
214
 
215
# Combine all necessary flags and optional flags.
216
# Add target processor to flags.
217
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
218
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
219
 
220
 
221
 
222
# Default target.
223
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
224
	$(TARGET).lss $(TARGET).sym sizeafter tooutdir finished end
225
 
226
 
227
# Eye candy.
228
# AVR Studio 3.x does not check make's exit code but relies on
229
# the following magic strings to be generated by the compile job.
230
begin:
231
	@echo
232
	@echo $(MSG_BEGIN)
233
 
234
finished:
235
	@echo $(MSG_ERRORS_NONE)
236
 
237
end:
238
	@echo $(MSG_END)
239
	@echo
240
 
241
 
242
# Display size of file.
243
sizebefore:
244
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
245
 
246
sizeafter:
247
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
248
 
249
 
250
 
251
# Display compiler version information.
252
gccversion :
253
	@$(CC) --version
254
 
255
 
256
 
257
 
258
# Convert ELF to COFF for use in debugging / simulating in
259
# AVR Studio or VMLAB.
260
COFFCONVERT=$(OBJCOPY) --debugging \
261
	--change-section-address .data-0x800000 \
262
	--change-section-address .bss-0x800000 \
263
	--change-section-address .noinit-0x800000 \
264
	--change-section-address .eeprom-0x810000
265
 
266
 
267
coff: $(TARGET).elf
268
	@echo
269
	@echo $(MSG_COFF) $(TARGET).cof
270
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
271
 
272
 
273
extcoff: $(TARGET).elf
274
	@echo
275
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
276
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
277
 
278
 
279
 
280
 
281
# Program the device.
282
program: $(TARGET).hex $(TARGET).eep
283
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
284
 
285
 
286
 
287
 
288
# Create final output files (.hex, .eep) from ELF output file.
289
%.hex: %.elf
290
	@echo
291
	@echo $(MSG_FLASH) $@
292
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
293
 
294
%.eep: %.elf
295
	@echo
296
	@echo $(MSG_EEPROM) $@
297
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
298
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
299
 
300
# Create extended listing file from ELF output file.
301
%.lss: %.elf
302
	@echo
303
	@echo $(MSG_EXTENDED_LISTING) $@
304
	$(OBJDUMP) -h -S $< > $@
305
 
306
# Create a symbol table from ELF output file.
307
%.sym: %.elf
308
	@echo
309
	@echo $(MSG_SYMBOL_TABLE) $@
310
	avr-nm -n $< > $@
311
 
312
 
313
 
314
# Link: create ELF output file from object files.
315
.SECONDARY : $(TARGET).elf
316
.PRECIOUS : $(OBJ)
317
%.elf: $(OBJ)
318
	@echo
319
	@echo $(MSG_LINKING) $@
320
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
321
 
322
 
323
# Compile: create object files from C source files.
324
%.o : %.c
325
	@echo
326
	@echo $(MSG_COMPILING) $<
327
	$(CC) -c $(ALL_CFLAGS) $< -o $@
328
 
329
 
330
# Compile: create assembler files from C source files.
331
%.s : %.c
332
	$(CC) -S $(ALL_CFLAGS) $< -o $@
333
 
334
 
335
# Assemble: create object files from assembler source files.
336
%.o : %.S
337
	@echo
338
	@echo $(MSG_ASSEMBLING) $<
339
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
340
 
341
 
342
 
343
 
344
 
345
 
346
# Target: clean project.
347
clean: begin clean_list finished end
348
 
349
clean_list :
350
	@echo
351
	@echo $(MSG_CLEANING)
352
	$(REMOVE) ./out/*
353
 
354
tooutdir:
70 jan-hendri 355
	@echo
356
	@echo $(MSG_MOVE)
66 jan-hendri 357
	-$(MOVE) $(TARGET).hex $(OUT)
358
#	-$(MOVE) $(TARGET).eep $(OUT)
359
#	-$(MOVE) $(TARGET).obj $(OUT)
360
#	-$(MOVE) $(TARGET).cof $(OUT)
361
	-$(MOVE) $(TARGET).elf $(OUT)
362
	-$(MOVE) $(TARGET).map $(OUT)
363
#	-$(MOVE) $(TARGET).a90 $(OUT)
364
	-$(MOVE) $(TARGET).sym $(OUT)
365
#	-$(MOVE) $(TARGET).lnk $(OUT)
366
	-$(MOVE) $(TARGET).lss $(OUT)
367
	-$(MOVE) $(OBJ) $(OUT)
368
	-$(MOVE) $(LST) $(OUT)
369
#	-$(MOVE) $(SRC:.c=.s) $(OUT)
68 jan-hendri 370
#	-$(MOVE) $(SRC:.c=.d) $(OUT)
66 jan-hendri 371
 
372
 
373
 
374
# Automatically generate C source code dependencies.
375
# (Code originally taken from the GNU make user manual and modified
376
# (See README.txt Credits).)
377
#
378
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
379
# (see the SHELL variable defined above).
380
# This may not work with other shells or other seds.
381
#
382
#%.d: %.c
383
#	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
384
#	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
385
#	[ -s $@ ] || rm -f $@
386
 
387
 
388
# Remove the '-' if you want to see the dependency files generated.
69 jan-hendri 389
#-include $(SRC:.c=.d)
66 jan-hendri 390
 
391
 
392
 
393
# Listing of phony targets.
394
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
395
	clean clean_list program
396