Subversion Repositories MK3Mag

Rev

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