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 dfu = Download the hex file to the device, using dfu-programmer (must
36 # have dfu-programmer installed).
38 # make flip = Download the hex file to the device, using Atmel FLIP (must
39 # have Atmel FLIP installed).
41 # make dfu-ee = Download the eeprom file to the device, using dfu-programmer
42 # (must have dfu-programmer installed).
44 # make flip-ee = Download the eeprom file to the device, using Atmel FLIP
45 # (must have Atmel FLIP installed).
47 # make doxygen = Generate DoxyGen documentation for the project (must have
50 # make debug = Start either simulavr or avarice as specified for debugging,
51 # with avr-gdb or avr-insight as the front end for debugging.
53 # make filename.s = Just compile filename.c into the assembler code only.
55 # make filename.i = Create a preprocessed source file for use in submitting
56 # bug reports to the GCC project.
58 # To rebuild project do "make clean" then "make all".
59 #----------------------------------------------------------------------------
66 # Target board (see library BoardTypes.h documentation, USER or blank for projects not requiring
67 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called
68 # "Board" inside the application directory.
72 # Processor frequency.
73 # This will define a symbol, F_CPU, in all source code files equal to the
74 # processor frequency. You can then use this symbol in your source code to
75 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
76 # automatically to create a 32-bit value in your source code.
93 # Output format. (can be srec, ihex, binary)
97 # Target file name (without extension).
98 TARGET = BootloaderDFU
101 # Object files directory
102 # To put object files in current directory, use a dot (.), do NOT make
103 # this an empty or blank macro!
107 # List C source files here. (C dependencies are automatically generated.)
110 ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \
111 ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \
112 ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \
113 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
114 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
115 ../../LUFA/Drivers/USB/HighLevel/Events.c \
116 ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \
118 # List C++ source files here. (C dependencies are automatically generated.)
122 # List Assembler source files here.
123 # Make them always end in a capital .S. Files ending in a lowercase .s
124 # will not be considered source files but generated files (assembler
125 # output from the compiler), and will be deleted upon "make clean"!
126 # Even though the DOS/Win* filesystem matches both .s and .S the same,
127 # it will preserve the spelling of the filenames, and gcc itself does
128 # care about how the name is spelled on its command-line.
132 # Optimization level, can be [0, 1, 2, 3, s].
133 # 0 = turn off optimization. s = optimize for size.
134 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
139 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
140 # AVR Studio 4.10 requires dwarf-2.
141 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
145 # List any extra directories to look for include files here.
146 # Each directory must be seperated by a space.
147 # Use forward slashes for directory separators.
148 # For a directory that has spaces, enclose it in quotes.
149 EXTRAINCDIRS = ../../
152 # Compiler flag to set the C Standard level.
154 # gnu89 = c89 plus GCC extensions
155 # c99 = ISO C99 standard (not yet fully implemented)
156 # gnu99 = c99 plus GCC extensions
157 CSTANDARD = -std=gnu99
160 # Starting byte address of the bootloader
164 # Place -D or -U options here for C sources
165 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DSTATIC_ENDPOINT_CONFIGURATION
166 CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
167 CDEFS += -DUSE_RAM_DESCRIPTORS -DBOOT_START_ADDR=$(BOOT_START)UL -DFIXED_CONTROL_ENDPOINT_SIZE=32 -DUSE_SINGLE_DEVICE_CONFIGURATION
168 CDEFS += -DNO_CLEARSET_FEATURE_REQUEST
170 # Place -D or -U options here for ASM sources
171 ADEFS = -DF_CPU=$(F_CPU)
174 # Place -D or -U options here for C++ sources
175 CPPDEFS = -DF_CPU=$(F_CPU)UL
176 #CPPDEFS += -D__STDC_LIMIT_MACROS
177 #CPPDEFS += -D__STDC_CONSTANT_MACROS
181 #---------------- Compiler Options C ----------------
182 # -g*: generate debugging information
183 # -O*: optimization level
184 # -f...: tuning, see GCC manual and avr-libc documentation
185 # -Wall...: warning level
186 # -Wa,...: tell GCC to pass this to the assembler.
187 # -adhlns...: create assembler listing
191 CFLAGS += -funsigned-char
192 CFLAGS += -funsigned-bitfields
193 CFLAGS += -ffunction-sections
194 CFLAGS += -fdata-sections
195 CFLAGS += -fpack-struct
196 CFLAGS += -fshort-enums
197 CFLAGS += -fno-inline-small-functions
198 CFLAGS += -fno-reorder-blocks
199 CFLAGS += -fno-reorder-blocks-and-partition
200 CFLAGS += -fno-reorder-functions
201 CFLAGS += -fno-toplevel-reorder
203 CFLAGS += -Wstrict-prototypes
205 #CFLAGS += -fno-unit-at-a-time
206 #CFLAGS += -Wunreachable-code
207 #CFLAGS += -Wsign-compare
208 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
209 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
210 CFLAGS += $(CSTANDARD)
213 #---------------- Compiler Options C++ ----------------
214 # -g*: generate debugging information
215 # -O*: optimization level
216 # -f...: tuning, see GCC manual and avr-libc documentation
217 # -Wall...: warning level
218 # -Wa,...: tell GCC to pass this to the assembler.
219 # -adhlns...: create assembler listing
220 CPPFLAGS = -g$(DEBUG)
221 CPPFLAGS += $(CPPDEFS)
223 CPPFLAGS += -funsigned-char
224 CPPFLAGS += -funsigned-bitfields
225 CPPFLAGS += -fpack-struct
226 CPPFLAGS += -fshort-enums
227 CPPFLAGS += -fno-exceptions
230 #CPPFLAGS += -mshort-calls
231 #CPPFLAGS += -fno-unit-at-a-time
232 #CPPFLAGS += -Wstrict-prototypes
233 #CPPFLAGS += -Wunreachable-code
234 #CPPFLAGS += -Wsign-compare
235 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
236 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
237 #CPPFLAGS += $(CSTANDARD)
240 #---------------- Assembler Options ----------------
241 # -Wa,...: tell GCC to pass this to the assembler.
242 # -adhlns: create listing
243 # -gstabs: have the assembler create line number information; note that
244 # for use in COFF files, additional information about filenames
245 # and function names needs to be present in the assembler source
246 # files -- see avr-libc docs [FIXME: not yet described there]
247 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
248 # dump that will be displayed for a given single line of source input.
249 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
252 #---------------- Library Options ----------------
253 # Minimalistic printf version
254 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
256 # Floating point printf version (requires MATH_LIB = -lm below)
257 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
259 # If this is left blank, then it will use the Standard printf version.
261 #PRINTF_LIB = $(PRINTF_LIB_MIN)
262 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
265 # Minimalistic scanf version
266 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
268 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
269 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
271 # If this is left blank, then it will use the Standard scanf version.
273 #SCANF_LIB = $(SCANF_LIB_MIN)
274 #SCANF_LIB = $(SCANF_LIB_FLOAT)
280 # List any extra directories to look for libraries here.
281 # Each directory must be seperated by a space.
282 # Use forward slashes for directory separators.
283 # For a directory that has spaces, enclose it in quotes.
288 #---------------- External Memory Options ----------------
290 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
291 # used for variables (.data/.bss) and heap (malloc()).
292 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
294 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
295 # only used for heap (malloc()).
296 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
302 #---------------- Linker Options ----------------
303 # -Wl,...: tell GCC to pass this to linker.
304 # -Map: create map file
305 # --cref: add cross reference to map file
306 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
307 LDFLAGS += -Wl,--relax
308 LDFLAGS += -Wl,--gc-sections
309 LDFLAGS += -Wl,--section-start=.text=$(BOOT_START)
310 LDFLAGS += $(EXTMEMOPTS)
311 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
312 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
313 #LDFLAGS += -T linker_script.x
317 #---------------- Programming Options (avrdude) ----------------
319 # Programming hardware: alf avr910 avrisp bascom bsd
320 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
323 # to get a full listing.
325 AVRDUDE_PROGRAMMER = jtagmkII
327 # com1 = serial port. Use lpt1 to connect to parallel port.
330 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
331 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
334 # Uncomment the following if you want avrdude's erase cycle counter.
335 # Note that this counter needs to be initialized first using -Yn,
336 # see avrdude manual.
337 #AVRDUDE_ERASE_COUNTER = -y
339 # Uncomment the following if you do /not/ wish a verification to be
340 # performed after programming the device.
341 AVRDUDE_NO_VERIFY = -V
343 # Increase verbosity level. Please use this when submitting bug
344 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
345 # to submit bug reports.
346 #AVRDUDE_VERBOSE = -v -v
348 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
349 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
350 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
351 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
355 #---------------- Debugging Options ----------------
357 # For simulavr only - target MCU frequency.
358 DEBUG_MFREQ = $(F_CPU)
360 # Set the DEBUG_UI to either gdb or insight.
364 # Set the debugging back-end to either avarice, simulavr.
365 DEBUG_BACKEND = avarice
366 #DEBUG_BACKEND = simulavr
369 GDBINIT_FILE = __avr_gdbinit
371 # When using avarice settings for the JTAG
374 # Debugging port used to communicate between GDB / avarice / simulavr.
377 # Debugging host used to communicate between GDB / avarice / simulavr, normally
378 # just set to localhost unless doing some sort of crazy debugging when
379 # avarice is running on a different computer.
380 DEBUG_HOST = localhost
384 #============================================================================
387 # Define programs and commands.
390 OBJCOPY = avr-objcopy
391 OBJDUMP = avr-objdump
403 MSG_ERRORS_NONE = Errors: none
404 MSG_BEGIN = -------- begin --------
405 MSG_END = -------- end --------
406 MSG_SIZE_BEFORE = Size before:
407 MSG_SIZE_AFTER = Size after:
408 MSG_COFF = Converting to AVR COFF:
409 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
410 MSG_FLASH = Creating load file for Flash:
411 MSG_EEPROM = Creating load file for EEPROM:
412 MSG_EXTENDED_LISTING = Creating Extended Listing:
413 MSG_SYMBOL_TABLE = Creating Symbol Table:
414 MSG_LINKING = Linking:
415 MSG_COMPILING = Compiling C:
416 MSG_COMPILING_CPP = Compiling C++:
417 MSG_ASSEMBLING = Assembling:
418 MSG_CLEANING = Cleaning project:
419 MSG_CREATING_LIBRARY = Creating library:
424 # Define all object files.
425 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
427 # Define all listing files.
428 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
431 # Compiler flags to generate dependency files.
432 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
435 # Combine all necessary flags and optional flags.
436 # Add target processor to flags.
437 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
438 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
439 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
446 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
448 # Change the build target to build a HEX file or a library.
449 build: elf hex eep lss sym
458 LIBNAME=lib$(TARGET).a
464 # AVR Studio 3.x does not check make's exit code but relies on
465 # the following magic strings to be generated by the compile job.
475 # Display size of file.
476 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
477 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
478 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
479 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
482 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
483 2>/dev/null; echo; fi
486 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
487 2>/dev/null; echo; fi
491 @echo ------- Unhooked LUFA Events -------
492 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
493 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
495 @echo ----- End Unhooked LUFA Events -----
499 @echo ----------- Library Mode -----------
500 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
501 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
502 || echo "No specific mode (both device and host mode allowable)."
503 @echo ------------------------------------
505 # Display compiler version information.
511 # Program the device.
512 program: $(TARGET).hex $(TARGET).eep
513 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
516 batchisp -hardware usb -device $(MCU) -operation erase f
517 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
518 batchisp -hardware usb -device $(MCU) -operation start reset 0
521 dfu-programmer $(MCU) erase
522 dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex
523 dfu-programmer $(MCU) reset
525 flip-ee: $(TARGET).hex $(TARGET).eep
526 copy $(TARGET).eep $(TARGET)eep.hex
527 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
528 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
529 batchisp -hardware usb -device $(MCU) -operation start reset 0
531 dfu-ee: $(TARGET).hex $(TARGET).eep
532 dfu-programmer $(MCU) erase
533 dfu-programmer $(MCU) eeprom --debug 1 $(TARGET).eep
534 dfu-programmer $(MCU) reset
536 # Generate avr-gdb config/init file which does the following:
537 # define the reset signal, load the target file, connect to target, and set
538 # a breakpoint at main().
540 @$(REMOVE) $(GDBINIT_FILE)
541 @echo define reset >> $(GDBINIT_FILE)
542 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
543 @echo end >> $(GDBINIT_FILE)
544 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
545 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
546 ifeq ($(DEBUG_BACKEND),simulavr)
547 @echo load >> $(GDBINIT_FILE)
549 @echo break main >> $(GDBINIT_FILE)
551 debug: gdb-config $(TARGET).elf
552 ifeq ($(DEBUG_BACKEND), avarice)
553 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
554 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
555 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
556 @$(WINSHELL) /c pause
559 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
560 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
562 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
567 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
568 COFFCONVERT = $(OBJCOPY) --debugging
569 COFFCONVERT += --change-section-address .data-0x800000
570 COFFCONVERT += --change-section-address .bss-0x800000
571 COFFCONVERT += --change-section-address .noinit-0x800000
572 COFFCONVERT += --change-section-address .eeprom-0x810000
578 @echo $(MSG_COFF) $(TARGET).cof
579 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
582 extcoff: $(TARGET).elf
584 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
585 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
589 # Create final output files (.hex, .eep) from ELF output file.
592 @echo $(MSG_FLASH) $@
593 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
597 @echo $(MSG_EEPROM) $@
598 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
599 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
601 # Create extended listing file from ELF output file.
604 @echo $(MSG_EXTENDED_LISTING) $@
605 $(OBJDUMP) -h -z -S $< > $@
607 # Create a symbol table from ELF output file.
610 @echo $(MSG_SYMBOL_TABLE) $@
615 # Create library from object files.
616 .SECONDARY : $(TARGET).a
620 @echo $(MSG_CREATING_LIBRARY) $@
624 # Link: create ELF output file from object files.
625 .SECONDARY : $(TARGET).elf
629 @echo $(MSG_LINKING) $@
630 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
633 # Compile: create object files from C source files.
636 @echo $(MSG_COMPILING) $<
637 $(CC) -c $(ALL_CFLAGS) $< -o $@
640 # Compile: create object files from C++ source files.
641 $(OBJDIR)/%.o : %.cpp
643 @echo $(MSG_COMPILING_CPP) $<
644 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
647 # Compile: create assembler files from C source files.
649 $(CC) -S $(ALL_CFLAGS) $< -o $@
652 # Compile: create assembler files from C++ source files.
654 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
657 # Assemble: create object files from assembler source files.
660 @echo $(MSG_ASSEMBLING) $<
661 $(CC) -c $(ALL_ASFLAGS) $< -o $@
664 # Create preprocessed source for use in sending a bug report.
666 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
669 # Target: clean project.
670 clean: begin clean_list clean_binary end
673 $(REMOVE) $(TARGET).hex
676 @echo $(MSG_CLEANING)
677 $(REMOVE) $(TARGET).eep
678 $(REMOVE) $(TARGET).cof
679 $(REMOVE) $(TARGET).elf
680 $(REMOVE) $(TARGET).map
681 $(REMOVE) $(TARGET).sym
682 $(REMOVE) $(TARGET).lss
683 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
684 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
685 $(REMOVE) $(ASRC:%.S=$(OBJDIR)/%.o)
686 $(REMOVE) $(ASRC:%.S=$(OBJDIR)/%.lst)
687 $(REMOVE) $(SRC:.c=.s)
688 $(REMOVE) $(SRC:.c=.d)
689 $(REMOVE) $(SRC:.c=.i)
694 @echo Generating Project Documentation...
695 @doxygen Doxygen.conf
696 @echo Documentation Generation Complete.
701 # Create object files directory
702 $(shell mkdir $(OBJDIR) 2>/dev/null)
705 # Include the dependency files.
706 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
709 # Listing of phony targets.
710 .PHONY : all checkhooks checklibmode begin \
711 finish end sizebefore sizeafter gccversion \
712 build elf hex eep lss sym coff extcoff \
713 clean clean_list clean_binary program debug \
714 gdb-config doxygen clean_doxygen