Subversion Repositories MK3Mag

Rev

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

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