Subversion Repositories MK3Mag

Rev

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

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