Subversion Repositories BL-Ctrl

Rev

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