Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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