Ensure the DFU bootloader disables and clears the activity LED toggle timer when...
[pub/USBasp.git] / BuildTests / BoardDriverTest / makefile.uc3
1 # Hey Emacs, this is a -*- makefile -*-
2 #----------------------------------------------------------------------------
3 # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
4 # >> Modified for use with the LUFA project. <<
5 #
6 # Released to the Public Domain
7 #
8 # Additional material for this makefile was written by:
9 # Peter Fleury
10 # Tim Henigan
11 # Colin O'Flynn
12 # Reiner Patommel
13 # Markus Pfaff
14 # Sander Pool
15 # Frederik Rouleau
16 # Carlos Lamas
17 # Dean Camera
18 # Opendous Inc.
19 # Denver Gingerich
20 #
21 #----------------------------------------------------------------------------
22 # On command line:
23 #
24 # make all = Make software.
25 #
26 # make clean = Clean out built project files.
27 #
28 # make dfu = Download the hex file to the device, using dfu-programmer (must
29 # have dfu-programmer installed).
30 #
31 # make flip = Download the hex file to the device, using Atmel FLIP (must
32 # have Atmel FLIP installed).
33 #
34 # make doxygen = Generate DoxyGen documentation for the project (must have
35 # DoxyGen installed)
36 #
37 # make filename.s = Just compile filename.c into the assembler code only.
38 #
39 # make filename.i = Create a preprocessed source file for use in submitting
40 # bug reports to the GCC project.
41 #
42 # To rebuild project do "make clean" then "make all".
43 #----------------------------------------------------------------------------
44
45
46 # MCU name
47 MCU = uc3a3256
48
49
50 # Targeted chip architecture (see library "Architectures" documentation)
51 ARCH = UC3
52
53
54 # Target board (see library "Board Types" documentation, NONE for projects not requiring
55 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called
56 # "Board" inside the application directory.
57 BOARD = NONE
58
59
60 # Processor frequency.
61 # This will define a symbol, F_CPU, in all source code files equal to the
62 # processor frequency in Hz. You can then use this symbol in your source code to
63 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
64 # automatically to create a 32-bit value in your source code.
65 #
66 # This should be the frequency the system core runs at, after the system clock
67 # has been set up correctly and started.
68 F_CPU = 12000000
69
70
71 # USB controller master clock frequency.
72 # This will define a symbol, F_USB, in all source code files equal to the
73 # input clock frequency of the USB controller's clock generator in Hz.
74 #
75 # For the UC3 chips, this should be equal to 48MHz or 96MHz.
76 F_USB = 48000000
77
78
79 # Output format. (can be srec, ihex, binary)
80 FORMAT = ihex
81
82
83 # Target file name (without extension).
84 TARGET = Test
85
86
87 # Object files directory
88 # To put object files in current directory, use a dot (.), do NOT make
89 # this an empty or blank macro!
90 OBJDIR = .
91
92
93 # Path to the LUFA library
94 LUFA_PATH = ../..
95
96
97 # LUFA library compile-time options and predefined tokens (add '-D' before each token)
98 LUFA_OPTS =
99
100
101 # Create the LUFA source path variables by including the LUFA root makefile
102 include $(LUFA_PATH)/LUFA/makefile
103
104
105 # List C source files here. (C dependencies are automatically generated.)
106 SRC = Test.c
107
108
109 # List C++ source files here. (C dependencies are automatically generated.)
110 CPPSRC =
111
112
113 # List Assembler source files here.
114 # Make them always end in a capital .S. Files ending in a lowercase .s
115 # will not be considered source files but generated files (assembler
116 # output from the compiler), and will be deleted upon "make clean"!
117 # Even though the DOS/Win* filesystem matches both .s and .S the same,
118 # it will preserve the spelling of the filenames, and gcc itself does
119 # care about how the name is spelled on its command-line.
120 ASRC =
121
122
123 # Optimization level, can be [0, 1, 2, 3, s].
124 # 0 = turn off optimization. s = optimize for size.
125 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
126 OPT = 1
127
128
129 # List any extra directories to look for include files here.
130 # Each directory must be seperated by a space.
131 # Use forward slashes for directory separators.
132 # For a directory that has spaces, enclose it in quotes.
133 EXTRAINCDIRS = $(LUFA_PATH)/
134
135
136 # Compiler flag to set the C Standard level.
137 # c89 = "ANSI" C
138 # gnu89 = c89 plus GCC extensions
139 # c99 = ISO C99 standard (not yet fully implemented)
140 # gnu99 = c99 plus GCC extensions
141 CSTANDARD = -std=gnu99
142
143
144 # Place -D or -U options here for C sources
145 CDEFS = -DF_CPU=$(F_CPU)UL
146 CDEFS += -DF_USB=$(F_USB)UL
147 CDEFS += -DBOARD=BOARD_$(BOARD)
148 CDEFS += -DARCH=ARCH_$(ARCH)
149 CDEFS += $(LUFA_OPTS)
150
151
152 # Place -D or -U options here for ASM sources
153 ADEFS = -DF_CPU=$(F_CPU)
154 ADEFS += -DF_USB=$(F_USB)UL
155 ADEFS += -DBOARD=BOARD_$(BOARD)
156 ADEFS += -DARCH=ARCH_$(ARCH)
157 ADEFS += $(LUFA_OPTS)
158
159 # Place -D or -U options here for C++ sources
160 CPPDEFS = -DF_CPU=$(F_CPU)UL
161 CPPDEFS += -DF_USB=$(F_USB)UL
162 CPPDEFS += -DBOARD=BOARD_$(BOARD)
163 CPPDEFS += -DARCH=ARCH_$(ARCH)
164 CPPDEFS += $(LUFA_OPTS)
165
166
167 # Debugging level.
168 DEBUG = 3
169
170
171 #---------------- Compiler Options C ----------------
172 # -g*: generate debugging information
173 # -O*: optimization level
174 # -f...: tuning, see GCC manual and avr-libc documentation
175 # -Wall...: warning level
176 # -Wa,...: tell GCC to pass this to the assembler.
177 # -adhlns...: create assembler listing
178 CFLAGS = -g$(DEBUG)
179 CFLAGS += $(CDEFS)
180 CFLAGS += -O$(OPT)
181 CFLAGS += -funsigned-char
182 CFLAGS += -funsigned-bitfields
183 CFLAGS += -ffunction-sections
184 CFLAGS += -fno-strict-aliasing
185 CFLAGS += -Wall
186 CFLAGS += -Wstrict-prototypes
187 CFLAGS += -masm-addr-pseudos
188 #CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
189 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
190 CFLAGS += $(CSTANDARD)
191
192
193 #---------------- Compiler Options C++ ----------------
194 # -g*: generate debugging information
195 # -O*: optimization level
196 # -f...: tuning, see GCC manual and avr-libc documentation
197 # -Wall...: warning level
198 # -Wa,...: tell GCC to pass this to the assembler.
199 # -adhlns...: create assembler listing
200 CPPFLAGS = -g$(DEBUG)
201 CPPFLAGS += $(CPPDEFS)
202 CPPFLAGS += -O$(OPT)
203 CPPFLAGS += -funsigned-char
204 CPPFLAGS += -funsigned-bitfields
205 CPPFLAGS += -ffunction-sections
206 CPPFLAGS += -fno-strict-aliasing
207 CPPFLAGS += -fno-exceptions
208 CPPFLAGS += -masm-addr-pseudos
209 CPPFLAGS += -Wall
210 CPPFLAGS += -Wundef
211 #CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
212 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
213 #CPPFLAGS += $(CSTANDARD)
214
215
216 #---------------- Assembler Options ----------------
217 # -Wa,...: tell GCC to pass this to the assembler.
218 # -adhlns: create listing
219 # -gstabs: have the assembler create line number information; note that
220 # for use in COFF files, additional information about filenames
221 # and function names needs to be present in the assembler source
222 # files -- see avr-libc docs [FIXME: not yet described there]
223 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
224 # dump that will be displayed for a given single line of source input.
225 ASFLAGS = $(ADEFS)
226 #ASFLAGS += -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
227
228
229 #---------------- Linker Options ----------------
230 # -Wl,...: tell GCC to pass this to linker.
231 # -Map: create map file
232 # --cref: add cross reference to map file
233 #LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
234 LDFLAGS += -Wl,--gc-sections --rodata-writable
235 LDFLAGS += -Wl,--direct-data
236 #LDFLAGS += -T linker_script.x
237
238
239 #============================================================================
240
241
242 # Define programs and commands.
243 SHELL = sh
244 CC = avr32-gcc
245 OBJCOPY = avr32-objcopy
246 OBJDUMP = avr32-objdump
247 SIZE = avr32-size
248 AR = avr32-ar rcs
249 NM = avr32-nm
250 REMOVE = rm -f
251 REMOVEDIR = rm -rf
252 COPY = cp
253 WINSHELL = cmd
254
255
256 # Define Messages
257 # English
258 MSG_ERRORS_NONE = Errors: none
259 MSG_BEGIN = -------- begin --------
260 MSG_END = -------- end --------
261 MSG_SIZE_BEFORE = Size before:
262 MSG_SIZE_AFTER = Size after:
263 MSG_COFF = Converting to AVR COFF:
264 MSG_FLASH = Creating load file for Flash:
265 MSG_EEPROM = Creating load file for EEPROM:
266 MSG_EXTENDED_LISTING = Creating Extended Listing:
267 MSG_SYMBOL_TABLE = Creating Symbol Table:
268 MSG_LINKING = Linking:
269 MSG_COMPILING = Compiling C:
270 MSG_COMPILING_CPP = Compiling C++:
271 MSG_ASSEMBLING = Assembling:
272 MSG_CLEANING = Cleaning project:
273 MSG_CREATING_LIBRARY = Creating library:
274
275
276
277
278 # Define all object files.
279 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
280
281 # Define all listing files.
282 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
283
284
285 # Compiler flags to generate dependency files.
286 #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
287
288
289 # Combine all necessary flags and optional flags.
290 # Add target processor to flags.
291 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
292 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
293 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
294
295
296
297
298
299 # Default target.
300 all: begin gccversion sizebefore build sizeafter end
301
302 # Change the build target to build a HEX file or a library.
303 build: elf hex lss sym
304 #build: lib
305
306
307 elf: $(TARGET).elf
308 hex: $(TARGET).hex
309 lss: $(TARGET).lss
310 sym: $(TARGET).sym
311 LIBNAME=lib$(TARGET).a
312 lib: $(LIBNAME)
313
314
315
316 # Eye candy.
317 # AVR Studio 3.x does not check make's exit code but relies on
318 # the following magic strings to be generated by the compile job.
319 begin:
320 @echo
321 @echo $(MSG_BEGIN)
322
323 end:
324 @echo $(MSG_END)
325 @echo
326
327
328 # Display size of file.
329 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
330 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
331 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
332 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
333
334
335 sizebefore:
336 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
337 2>/dev/null; echo; fi
338
339 sizeafter:
340 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
341 2>/dev/null; echo; fi
342
343
344
345 # Display compiler version information.
346 gccversion :
347 @$(CC) --version
348
349
350 # Program the device.
351 flip: $(TARGET).hex
352 batchisp -hardware usb -device $(MCU) -operation erase f
353 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
354 batchisp -hardware usb -device $(MCU) -operation start reset 0
355
356 dfu: $(TARGET).hex
357 dfu-programmer $(MCU) erase
358 dfu-programmer $(MCU) flash $(TARGET).hex
359 dfu-programmer $(MCU) reset
360
361
362 # Create final output files (.hex, .eep) from ELF output file.
363 %.hex: %.elf
364 @echo
365 @echo $(MSG_FLASH) $@
366 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
367
368 # Create extended listing file from ELF output file.
369 %.lss: %.elf
370 @echo
371 @echo $(MSG_EXTENDED_LISTING) $@
372 $(OBJDUMP) -h -S -z $< > $@
373
374 # Create a symbol table from ELF output file.
375 %.sym: %.elf
376 @echo
377 @echo $(MSG_SYMBOL_TABLE) $@
378 $(NM) -n $< > $@
379
380
381
382 # Create library from object files.
383 .SECONDARY : $(TARGET).a
384 .PRECIOUS : $(OBJ)
385 %.a: $(OBJ)
386 @echo
387 @echo $(MSG_CREATING_LIBRARY) $@
388 $(AR) $@ $(OBJ)
389
390
391 # Link: create ELF output file from object files.
392 .SECONDARY : $(TARGET).elf
393 .PRECIOUS : $(OBJ)
394 %.elf: $(OBJ)
395 @echo
396 @echo $(MSG_LINKING) $@
397 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
398
399
400 # Compile: create object files from C source files.
401 $(OBJDIR)/%.o : %.c
402 @echo
403 @echo $(MSG_COMPILING) $<
404 $(CC) -c $(ALL_CFLAGS) $< -o $@
405
406
407 # Compile: create object files from C++ source files.
408 $(OBJDIR)/%.o : %.cpp
409 @echo
410 @echo $(MSG_COMPILING_CPP) $<
411 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
412
413
414 # Compile: create assembler files from C source files.
415 %.s : %.c
416 $(CC) -S $(ALL_CFLAGS) $< -o $@
417
418
419 # Compile: create assembler files from C++ source files.
420 %.s : %.cpp
421 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
422
423
424 # Assemble: create object files from assembler source files.
425 $(OBJDIR)/%.o : %.S
426 @echo
427 @echo $(MSG_ASSEMBLING) $<
428 $(CC) -c $(ALL_ASFLAGS) $< -o $@
429
430
431 # Create preprocessed source for use in sending a bug report.
432 %.i : %.c
433 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
434
435
436 # Target: clean project.
437 clean: begin clean_list end
438
439 clean_list :
440 @echo
441 @echo $(MSG_CLEANING)
442 $(REMOVE) $(TARGET).hex
443 $(REMOVE) $(TARGET).cof
444 $(REMOVE) $(TARGET).elf
445 $(REMOVE) $(TARGET).map
446 $(REMOVE) $(TARGET).sym
447 $(REMOVE) $(TARGET).lss
448 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
449 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
450 $(REMOVE) $(SRC:.c=.s)
451 $(REMOVE) $(SRC:.c=.d)
452 $(REMOVE) $(SRC:.c=.i)
453 $(REMOVEDIR) .dep
454
455 doxygen:
456 @echo Generating Project Documentation \($(TARGET)\)...
457 @if ( ( cat Doxygen.conf ; echo "HTML_STYLESHEET=$(LUFA_PATH)/LUFA/DoxygenPages/Style/Style.css" ) | doxygen - 2>&1 | grep -v "warning: ignoring unsupported tag" ;); then \
458 exit 1; \
459 fi;
460 @echo Documentation Generation Complete.
461
462 clean_doxygen:
463 rm -rf Documentation
464
465 checksource:
466 @for f in $(SRC) $(CPPSRC) $(ASRC); do \
467 if [ -f $$f ]; then \
468 echo "Found Source File: $$f" ; \
469 else \
470 echo "Source File Not Found: $$f" ; \
471 fi; done
472
473
474 # Create object files directory
475 $(shell mkdir $(OBJDIR) 2>/dev/null)
476
477
478 # Include the dependency files.
479 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
480
481
482 # Listing of phony targets.
483 .PHONY : all begin finish end sizebefore sizeafter gccversion \
484 build elf hex lss sym doxygen clean clean_list clean_doxygen \
485 dfu flip checksource
486