Subversion Repositories MK3Mag

Rev

Rev 29 | Details | Compare with Previous | Last modification | View Log | RSS feed

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