Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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