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. <<
6 # Released to the Public Domain
8 # Additional material for this makefile was written by:
21 #----------------------------------------------------------------------------
24 # make all = Make software.
26 # make clean = Clean out built project files.
28 # make coff = Convert ELF to AVR COFF.
30 # make extcoff = Convert ELF to AVR Extended COFF.
32 # make program = Download the hex file to the device, using avrdude.
33 # Please customize the avrdude settings below first!
35 # make doxygen = Generate DoxyGen documentation for the project (must have
38 # make debug = Start either simulavr or avarice as specified for debugging,
39 # with avr-gdb or avr-insight as the front end for debugging.
41 # make filename.s = Just compile filename.c into the assembler code only.
43 # make filename.i = Create a preprocessed source file for use in submitting
44 # bug reports to the GCC project.
46 # To rebuild project do "make clean" then "make all".
47 #----------------------------------------------------------------------------
54 # Target board (see library "Board Types" documentation, USER or blank 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.
60 # Processor frequency.
61 # This will define a symbol, F_CPU, in all source code files equal to the
62 # processor frequency. 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.
81 # Input clock frequency.
82 # This will define a symbol, F_CLOCK, in all source code files equal to the
83 # input clock frequency (before any prescaling is performed). This value may
84 # differ from F_CPU if prescaling is used on the latter, and is required as the
85 # raw input clock is fed directly to the PLL sections of the AVR for high speed
86 # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
87 # at the end, this will be done automatically to create a 32-bit value in your
90 # If no clock division is performed on the input clock inside the AVR (via the
91 # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
95 # Output format. (can be srec, ihex, binary)
99 # Target file name (without extension).
100 TARGET = BootloaderDFU
103 # Object files directory
104 # To put object files in current directory, use a dot (.), do NOT make
105 # this an empty or blank macro!
109 # Path to the LUFA library
113 # List C source files here. (C dependencies are automatically generated.)
116 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
117 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
118 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \
119 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/HostChapter9.c \
120 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/LowLevel.c \
121 $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Pipe.c \
122 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/Events.c \
123 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
124 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c \
125 $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c \
128 # List C++ source files here. (C dependencies are automatically generated.)
132 # List Assembler source files here.
133 # Make them always end in a capital .S. Files ending in a lowercase .s
134 # will not be considered source files but generated files (assembler
135 # output from the compiler), and will be deleted upon "make clean"!
136 # Even though the DOS/Win* filesystem matches both .s and .S the same,
137 # it will preserve the spelling of the filenames, and gcc itself does
138 # care about how the name is spelled on its command-line.
142 # Optimization level, can be [0, 1, 2, 3, s].
143 # 0 = turn off optimization. s = optimize for size.
144 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
149 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
150 # AVR Studio 4.10 requires dwarf-2.
151 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
155 # List any extra directories to look for include files here.
156 # Each directory must be seperated by a space.
157 # Use forward slashes for directory separators.
158 # For a directory that has spaces, enclose it in quotes.
159 EXTRAINCDIRS = $(LUFA_PATH)/
162 # Compiler flag to set the C Standard level.
164 # gnu89 = c89 plus GCC extensions
165 # c99 = ISO C99 standard (not yet fully implemented)
166 # gnu99 = c99 plus GCC extensions
167 CSTANDARD = -std=gnu99
170 # Starting byte address of the bootloader
174 # Place -D or -U options here for C sources
175 CDEFS = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD)
176 CDEFS += -DUSB_DEVICE_ONLY -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DCONTROL_ONLY_DEVICE
177 CDEFS += -DFIXED_CONTROL_ENDPOINT_SIZE=32 -DUSE_SINGLE_DEVICE_CONFIGURATION
178 CDEFS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
179 CDEFS += -DUSE_RAM_DESCRIPTORS -DBOOT_START_ADDR=$(BOOT_START)UL
182 # Place -D or -U options here for ASM sources
183 ADEFS = -DF_CPU=$(F_CPU)
186 # Place -D or -U options here for C++ sources
187 CPPDEFS = -DF_CPU=$(F_CPU)UL
188 #CPPDEFS += -D__STDC_LIMIT_MACROS
189 #CPPDEFS += -D__STDC_CONSTANT_MACROS
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
203 CFLAGS += -funsigned-char
204 CFLAGS += -funsigned-bitfields
205 CFLAGS += -ffunction-sections
206 CFLAGS += -fdata-sections
207 CFLAGS += -fpack-struct
208 CFLAGS += -fshort-enums
209 CFLAGS += -fno-inline-small-functions
210 CFLAGS += -fno-reorder-blocks
211 CFLAGS += -fno-reorder-blocks-and-partition
212 CFLAGS += -fno-reorder-functions
213 CFLAGS += -fno-toplevel-reorder
215 CFLAGS += -Wstrict-prototypes
217 #CFLAGS += -fno-unit-at-a-time
218 #CFLAGS += -Wunreachable-code
219 #CFLAGS += -Wsign-compare
220 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
221 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
222 CFLAGS += $(CSTANDARD)
225 #---------------- Compiler Options C++ ----------------
226 # -g*: generate debugging information
227 # -O*: optimization level
228 # -f...: tuning, see GCC manual and avr-libc documentation
229 # -Wall...: warning level
230 # -Wa,...: tell GCC to pass this to the assembler.
231 # -adhlns...: create assembler listing
232 CPPFLAGS = -g$(DEBUG)
233 CPPFLAGS += $(CPPDEFS)
235 CPPFLAGS += -funsigned-char
236 CPPFLAGS += -funsigned-bitfields
237 CPPFLAGS += -fpack-struct
238 CPPFLAGS += -fshort-enums
239 CPPFLAGS += -fno-exceptions
242 #CPPFLAGS += -mshort-calls
243 #CPPFLAGS += -fno-unit-at-a-time
244 #CPPFLAGS += -Wstrict-prototypes
245 #CPPFLAGS += -Wunreachable-code
246 #CPPFLAGS += -Wsign-compare
247 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
248 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
249 #CPPFLAGS += $(CSTANDARD)
252 #---------------- Assembler Options ----------------
253 # -Wa,...: tell GCC to pass this to the assembler.
254 # -adhlns: create listing
255 # -gstabs: have the assembler create line number information; note that
256 # for use in COFF files, additional information about filenames
257 # and function names needs to be present in the assembler source
258 # files -- see avr-libc docs [FIXME: not yet described there]
259 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
260 # dump that will be displayed for a given single line of source input.
261 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
264 #---------------- Library Options ----------------
265 # Minimalistic printf version
266 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
268 # Floating point printf version (requires MATH_LIB = -lm below)
269 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
271 # If this is left blank, then it will use the Standard printf version.
273 #PRINTF_LIB = $(PRINTF_LIB_MIN)
274 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
277 # Minimalistic scanf version
278 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
280 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
281 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
283 # If this is left blank, then it will use the Standard scanf version.
285 #SCANF_LIB = $(SCANF_LIB_MIN)
286 #SCANF_LIB = $(SCANF_LIB_FLOAT)
292 # List any extra directories to look for libraries here.
293 # Each directory must be seperated by a space.
294 # Use forward slashes for directory separators.
295 # For a directory that has spaces, enclose it in quotes.
300 #---------------- External Memory Options ----------------
302 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
303 # used for variables (.data/.bss) and heap (malloc()).
304 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
306 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
307 # only used for heap (malloc()).
308 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
314 #---------------- Linker Options ----------------
315 # -Wl,...: tell GCC to pass this to linker.
316 # -Map: create map file
317 # --cref: add cross reference to map file
318 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
319 LDFLAGS += -Wl,--relax
320 LDFLAGS += -Wl,--gc-sections
321 LDFLAGS += -Wl,--section-start=.text=$(BOOT_START)
322 LDFLAGS += $(EXTMEMOPTS)
323 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
324 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
325 #LDFLAGS += -T linker_script.x
329 #---------------- Programming Options (avrdude) ----------------
331 # Programming hardware: alf avr910 avrisp bascom bsd
332 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
335 # to get a full listing.
337 AVRDUDE_PROGRAMMER = jtagmkII
339 # com1 = serial port. Use lpt1 to connect to parallel port.
342 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
343 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
346 # Uncomment the following if you want avrdude's erase cycle counter.
347 # Note that this counter needs to be initialized first using -Yn,
348 # see avrdude manual.
349 #AVRDUDE_ERASE_COUNTER = -y
351 # Uncomment the following if you do /not/ wish a verification to be
352 # performed after programming the device.
353 AVRDUDE_NO_VERIFY = -V
355 # Increase verbosity level. Please use this when submitting bug
356 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
357 # to submit bug reports.
358 #AVRDUDE_VERBOSE = -v -v
360 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
361 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
362 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
363 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
367 #---------------- Debugging Options ----------------
369 # For simulavr only - target MCU frequency.
370 DEBUG_MFREQ = $(F_CPU)
372 # Set the DEBUG_UI to either gdb or insight.
376 # Set the debugging back-end to either avarice, simulavr.
377 DEBUG_BACKEND = avarice
378 #DEBUG_BACKEND = simulavr
381 GDBINIT_FILE = __avr_gdbinit
383 # When using avarice settings for the JTAG
386 # Debugging port used to communicate between GDB / avarice / simulavr.
389 # Debugging host used to communicate between GDB / avarice / simulavr, normally
390 # just set to localhost unless doing some sort of crazy debugging when
391 # avarice is running on a different computer.
392 DEBUG_HOST = localhost
396 #============================================================================
399 # Define programs and commands.
402 OBJCOPY = avr-objcopy
403 OBJDUMP = avr-objdump
415 MSG_ERRORS_NONE = Errors: none
416 MSG_BEGIN = -------- begin --------
417 MSG_END = -------- end --------
418 MSG_SIZE_BEFORE = Size before:
419 MSG_SIZE_AFTER = Size after:
420 MSG_COFF = Converting to AVR COFF:
421 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
422 MSG_FLASH = Creating load file for Flash:
423 MSG_EEPROM = Creating load file for EEPROM:
424 MSG_EXTENDED_LISTING = Creating Extended Listing:
425 MSG_SYMBOL_TABLE = Creating Symbol Table:
426 MSG_LINKING = Linking:
427 MSG_COMPILING = Compiling C:
428 MSG_COMPILING_CPP = Compiling C++:
429 MSG_ASSEMBLING = Assembling:
430 MSG_CLEANING = Cleaning project:
431 MSG_CREATING_LIBRARY = Creating library:
436 # Define all object files.
437 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
439 # Define all listing files.
440 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
443 # Compiler flags to generate dependency files.
444 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
447 # Combine all necessary flags and optional flags.
448 # Add target processor to flags.
449 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
450 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
451 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
458 all: begin gccversion sizebefore build checkhooks checklibmode checkboard sizeafter end
460 # Change the build target to build a HEX file or a library.
461 build: elf hex eep lss sym
470 LIBNAME=lib$(TARGET).a
476 # AVR Studio 3.x does not check make's exit code but relies on
477 # the following magic strings to be generated by the compile job.
487 # Display size of file.
488 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
489 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
490 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
491 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
494 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
495 2>/dev/null; echo; fi
498 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
499 2>/dev/null; echo; fi
503 @echo ------- Unhooked LUFA Events -------
504 @$(shell) (grep -s '^EVENT_.*LUFA/.*\\.o' $(TARGET).map | \
505 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
507 @echo ------------------------------------
511 @echo ----------- Library Mode -----------
512 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
513 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
514 || echo "No specific mode (both device and host mode allowable)."
515 @echo ------------------------------------
519 @echo ---------- Selected Board ----------
520 @echo Selected board model is $(BOARD).
521 @echo ------------------------------------
523 # Display compiler version information.
529 # Program the device.
530 program: $(TARGET).hex $(TARGET).eep
531 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
534 # Generate avr-gdb config/init file which does the following:
535 # define the reset signal, load the target file, connect to target, and set
536 # a breakpoint at main().
538 @$(REMOVE) $(GDBINIT_FILE)
539 @echo define reset >> $(GDBINIT_FILE)
540 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
541 @echo end >> $(GDBINIT_FILE)
542 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
543 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
544 ifeq ($(DEBUG_BACKEND),simulavr)
545 @echo load >> $(GDBINIT_FILE)
547 @echo break main >> $(GDBINIT_FILE)
549 debug: gdb-config $(TARGET).elf
550 ifeq ($(DEBUG_BACKEND), avarice)
551 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
552 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
553 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
554 @$(WINSHELL) /c pause
557 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
558 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
560 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
565 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
566 COFFCONVERT = $(OBJCOPY) --debugging
567 COFFCONVERT += --change-section-address .data-0x800000
568 COFFCONVERT += --change-section-address .bss-0x800000
569 COFFCONVERT += --change-section-address .noinit-0x800000
570 COFFCONVERT += --change-section-address .eeprom-0x810000
576 @echo $(MSG_COFF) $(TARGET).cof
577 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
580 extcoff: $(TARGET).elf
582 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
583 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
587 # Create final output files (.hex, .eep) from ELF output file.
590 @echo $(MSG_FLASH) $@
591 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
595 @echo $(MSG_EEPROM) $@
596 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
597 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
599 # Create extended listing file from ELF output file.
602 @echo $(MSG_EXTENDED_LISTING) $@
603 $(OBJDUMP) -h -z -S $< > $@
605 # Create a symbol table from ELF output file.
608 @echo $(MSG_SYMBOL_TABLE) $@
613 # Create library from object files.
614 .SECONDARY : $(TARGET).a
618 @echo $(MSG_CREATING_LIBRARY) $@
622 # Link: create ELF output file from object files.
623 .SECONDARY : $(TARGET).elf
627 @echo $(MSG_LINKING) $@
628 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
631 # Compile: create object files from C source files.
634 @echo $(MSG_COMPILING) $<
635 $(CC) -c $(ALL_CFLAGS) $< -o $@
638 # Compile: create object files from C++ source files.
639 $(OBJDIR)/%.o : %.cpp
641 @echo $(MSG_COMPILING_CPP) $<
642 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
645 # Compile: create assembler files from C source files.
647 $(CC) -S $(ALL_CFLAGS) $< -o $@
650 # Compile: create assembler files from C++ source files.
652 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
655 # Assemble: create object files from assembler source files.
658 @echo $(MSG_ASSEMBLING) $<
659 $(CC) -c $(ALL_ASFLAGS) $< -o $@
662 # Create preprocessed source for use in sending a bug report.
664 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
667 # Target: clean project.
668 clean: begin clean_list clean_binary end
671 $(REMOVE) $(TARGET).hex
674 @echo $(MSG_CLEANING)
675 $(REMOVE) $(TARGET).eep
676 $(REMOVE) $(TARGET)eep.hex
677 $(REMOVE) $(TARGET).cof
678 $(REMOVE) $(TARGET).elf
679 $(REMOVE) $(TARGET).map
680 $(REMOVE) $(TARGET).sym
681 $(REMOVE) $(TARGET).lss
682 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
683 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
684 $(REMOVE) $(SRC:.c=.s)
685 $(REMOVE) $(SRC:.c=.d)
686 $(REMOVE) $(SRC:.c=.i)
691 @echo Generating Project Documentation...
692 @doxygen Doxygen.conf
693 @echo Documentation Generation Complete.
698 # Create object files directory
699 $(shell mkdir $(OBJDIR) 2>/dev/null)
702 # Include the dependency files.
703 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
706 # Listing of phony targets.
707 .PHONY : all checkhooks checklibmode checkboard \
708 begin finish end sizebefore sizeafter gccversion \
709 build elf hex eep lss sym coff extcoff clean \
710 clean_list clean_binary program debug gdb-config \