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).
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/Scheduler/Scheduler.c \
111 ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \
112 ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \
113 ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \
114 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
115 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
116 ../../LUFA/Drivers/USB/HighLevel/Events.c \
117 ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \
119 # List C++ source files here. (C dependencies are automatically generated.)
123 # List Assembler source files here.
124 # Make them always end in a capital .S. Files ending in a lowercase .s
125 # will not be considered source files but generated files (assembler
126 # output from the compiler), and will be deleted upon "make clean"!
127 # Even though the DOS/Win* filesystem matches both .s and .S the same,
128 # it will preserve the spelling of the filenames, and gcc itself does
129 # care about how the name is spelled on its command-line.
133 # Optimization level, can be [0, 1, 2, 3, s].
134 # 0 = turn off optimization. s = optimize for size.
135 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
140 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
141 # AVR Studio 4.10 requires dwarf-2.
142 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
146 # List any extra directories to look for include files here.
147 # Each directory must be seperated by a space.
148 # Use forward slashes for directory separators.
149 # For a directory that has spaces, enclose it in quotes.
150 EXTRAINCDIRS = ../../
153 # Compiler flag to set the C Standard level.
155 # gnu89 = c89 plus GCC extensions
156 # c99 = ISO C99 standard (not yet fully implemented)
157 # gnu99 = c99 plus GCC extensions
158 CSTANDARD = -std=gnu99
161 # Place -D or -U options here for C sources
162 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS
163 CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
166 # Place -D or -U options here for ASM sources
167 ADEFS = -DF_CPU=$(F_CPU)
170 # Place -D or -U options here for C++ sources
171 CPPDEFS = -DF_CPU=$(F_CPU)UL
172 #CPPDEFS += -D__STDC_LIMIT_MACROS
173 #CPPDEFS += -D__STDC_CONSTANT_MACROS
177 #---------------- Compiler Options C ----------------
178 # -g*: generate debugging information
179 # -O*: optimization level
180 # -f...: tuning, see GCC manual and avr-libc documentation
181 # -Wall...: warning level
182 # -Wa,...: tell GCC to pass this to the assembler.
183 # -adhlns...: create assembler listing
187 CFLAGS += -funsigned-char
188 CFLAGS += -funsigned-bitfields
189 CFLAGS += -ffunction-sections
190 CFLAGS += -fpack-struct
191 CFLAGS += -fshort-enums
192 CFLAGS += -finline-limit=20
194 CFLAGS += -Wstrict-prototypes
195 #CFLAGS += -mshort-calls
197 #CFLAGS += -fno-unit-at-a-time
198 #CFLAGS += -Wunreachable-code
199 #CFLAGS += -Wsign-compare
200 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
201 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
202 CFLAGS += $(CSTANDARD)
205 #---------------- Compiler Options C++ ----------------
206 # -g*: generate debugging information
207 # -O*: optimization level
208 # -f...: tuning, see GCC manual and avr-libc documentation
209 # -Wall...: warning level
210 # -Wa,...: tell GCC to pass this to the assembler.
211 # -adhlns...: create assembler listing
212 CPPFLAGS = -g$(DEBUG)
213 CPPFLAGS += $(CPPDEFS)
215 CPPFLAGS += -funsigned-char
216 CPPFLAGS += -funsigned-bitfields
217 CPPFLAGS += -fpack-struct
218 CPPFLAGS += -fshort-enums
219 CPPFLAGS += -fno-exceptions
222 #CPPFLAGS += -mshort-calls
223 #CPPFLAGS += -fno-unit-at-a-time
224 #CPPFLAGS += -Wstrict-prototypes
225 #CPPFLAGS += -Wunreachable-code
226 #CPPFLAGS += -Wsign-compare
227 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
228 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
229 #CPPFLAGS += $(CSTANDARD)
232 #---------------- Assembler Options ----------------
233 # -Wa,...: tell GCC to pass this to the assembler.
234 # -adhlns: create listing
235 # -gstabs: have the assembler create line number information; note that
236 # for use in COFF files, additional information about filenames
237 # and function names needs to be present in the assembler source
238 # files -- see avr-libc docs [FIXME: not yet described there]
239 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
240 # dump that will be displayed for a given single line of source input.
241 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
244 #---------------- Library Options ----------------
245 # Minimalistic printf version
246 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
248 # Floating point printf version (requires MATH_LIB = -lm below)
249 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
251 # If this is left blank, then it will use the Standard printf version.
253 #PRINTF_LIB = $(PRINTF_LIB_MIN)
254 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
257 # Minimalistic scanf version
258 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
260 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
261 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
263 # If this is left blank, then it will use the Standard scanf version.
265 #SCANF_LIB = $(SCANF_LIB_MIN)
266 #SCANF_LIB = $(SCANF_LIB_FLOAT)
272 # List any extra directories to look for libraries here.
273 # Each directory must be seperated by a space.
274 # Use forward slashes for directory separators.
275 # For a directory that has spaces, enclose it in quotes.
280 #---------------- External Memory Options ----------------
282 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
283 # used for variables (.data/.bss) and heap (malloc()).
284 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
286 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
287 # only used for heap (malloc()).
288 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
294 #---------------- Linker Options ----------------
295 # -Wl,...: tell GCC to pass this to linker.
296 # -Map: create map file
297 # --cref: add cross reference to map file
298 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
299 LDFLAGS += -Wl,--relax
300 LDFLAGS += -Wl,--gc-sections
301 LDFLAGS += $(EXTMEMOPTS)
302 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
303 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
304 #LDFLAGS += -T linker_script.x
308 #---------------- Programming Options (avrdude) ----------------
310 # Programming hardware: alf avr910 avrisp bascom bsd
311 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
314 # to get a full listing.
316 AVRDUDE_PROGRAMMER = jtagmkII
318 # com1 = serial port. Use lpt1 to connect to parallel port.
321 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
322 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
325 # Uncomment the following if you want avrdude's erase cycle counter.
326 # Note that this counter needs to be initialized first using -Yn,
327 # see avrdude manual.
328 #AVRDUDE_ERASE_COUNTER = -y
330 # Uncomment the following if you do /not/ wish a verification to be
331 # performed after programming the device.
332 #AVRDUDE_NO_VERIFY = -V
334 # Increase verbosity level. Please use this when submitting bug
335 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
336 # to submit bug reports.
337 #AVRDUDE_VERBOSE = -v -v
339 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
340 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
341 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
342 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
346 #---------------- Debugging Options ----------------
348 # For simulavr only - target MCU frequency.
349 DEBUG_MFREQ = $(F_CPU)
351 # Set the DEBUG_UI to either gdb or insight.
355 # Set the debugging back-end to either avarice, simulavr.
356 DEBUG_BACKEND = avarice
357 #DEBUG_BACKEND = simulavr
360 GDBINIT_FILE = __avr_gdbinit
362 # When using avarice settings for the JTAG
365 # Debugging port used to communicate between GDB / avarice / simulavr.
368 # Debugging host used to communicate between GDB / avarice / simulavr, normally
369 # just set to localhost unless doing some sort of crazy debugging when
370 # avarice is running on a different computer.
371 DEBUG_HOST = localhost
375 #============================================================================
378 # Define programs and commands.
381 OBJCOPY = avr-objcopy
382 OBJDUMP = avr-objdump
394 MSG_ERRORS_NONE = Errors: none
395 MSG_BEGIN = -------- begin --------
396 MSG_END = -------- end --------
397 MSG_SIZE_BEFORE = Size before:
398 MSG_SIZE_AFTER = Size after:
399 MSG_COFF = Converting to AVR COFF:
400 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
401 MSG_FLASH = Creating load file for Flash:
402 MSG_EEPROM = Creating load file for EEPROM:
403 MSG_EXTENDED_LISTING = Creating Extended Listing:
404 MSG_SYMBOL_TABLE = Creating Symbol Table:
405 MSG_LINKING = Linking:
406 MSG_COMPILING = Compiling C:
407 MSG_COMPILING_CPP = Compiling C++:
408 MSG_ASSEMBLING = Assembling:
409 MSG_CLEANING = Cleaning project:
410 MSG_CREATING_LIBRARY = Creating library:
415 # Define all object files.
416 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
418 # Define all listing files.
419 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
422 # Compiler flags to generate dependency files.
423 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
426 # Combine all necessary flags and optional flags.
427 # Add target processor to flags.
428 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
429 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
430 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
437 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
439 # Change the build target to build a HEX file or a library.
440 build: elf hex eep lss sym
449 LIBNAME=lib$(TARGET).a
455 # AVR Studio 3.x does not check make's exit code but relies on
456 # the following magic strings to be generated by the compile job.
466 # Display size of file.
467 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
468 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
469 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
470 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
473 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
474 2>/dev/null; echo; fi
477 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
478 2>/dev/null; echo; fi
482 @echo ------- Unhooked LUFA Events -------
483 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
484 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
486 @echo ----- End Unhooked LUFA Events -----
490 @echo ----------- Library Mode -----------
491 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
492 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
493 || echo "No specific mode (both device and host mode allowable)."
494 @echo ------------------------------------
496 # Display compiler version information.
502 # Program the device.
503 program: $(TARGET).hex $(TARGET).eep
504 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
507 batchisp -hardware usb -device $(MCU) -operation erase f
508 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
509 batchisp -hardware usb -device $(MCU) -operation start reset 0
512 dfu-programmer $(MCU) erase
513 dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex
514 dfu-programmer $(MCU) reset
516 flip-ee: $(TARGET).hex $(TARGET).eep
517 copy $(TARGET).eep $(TARGET)eep.hex
518 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
519 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
520 batchisp -hardware usb -device $(MCU) -operation start reset 0
522 dfu-ee: $(TARGET).hex $(TARGET).eep
523 dfu-programmer $(MCU) erase
524 dfu-programmer $(MCU) eeprom --debug 1 $(TARGET).eep
525 dfu-programmer $(MCU) reset
527 # Generate avr-gdb config/init file which does the following:
528 # define the reset signal, load the target file, connect to target, and set
529 # a breakpoint at main().
531 @$(REMOVE) $(GDBINIT_FILE)
532 @echo define reset >> $(GDBINIT_FILE)
533 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
534 @echo end >> $(GDBINIT_FILE)
535 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
536 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
537 ifeq ($(DEBUG_BACKEND),simulavr)
538 @echo load >> $(GDBINIT_FILE)
540 @echo break main >> $(GDBINIT_FILE)
542 debug: gdb-config $(TARGET).elf
543 ifeq ($(DEBUG_BACKEND), avarice)
544 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
545 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
546 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
547 @$(WINSHELL) /c pause
550 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
551 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
553 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
558 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
559 COFFCONVERT = $(OBJCOPY) --debugging
560 COFFCONVERT += --change-section-address .data-0x800000
561 COFFCONVERT += --change-section-address .bss-0x800000
562 COFFCONVERT += --change-section-address .noinit-0x800000
563 COFFCONVERT += --change-section-address .eeprom-0x810000
569 @echo $(MSG_COFF) $(TARGET).cof
570 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
573 extcoff: $(TARGET).elf
575 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
576 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
580 # Create final output files (.hex, .eep) from ELF output file.
583 @echo $(MSG_FLASH) $@
584 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
588 @echo $(MSG_EEPROM) $@
589 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
590 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
592 # Create extended listing file from ELF output file.
595 @echo $(MSG_EXTENDED_LISTING) $@
596 $(OBJDUMP) -h -z -S $< > $@
598 # Create a symbol table from ELF output file.
601 @echo $(MSG_SYMBOL_TABLE) $@
606 # Create library from object files.
607 .SECONDARY : $(TARGET).a
611 @echo $(MSG_CREATING_LIBRARY) $@
615 # Link: create ELF output file from object files.
616 .SECONDARY : $(TARGET).elf
620 @echo $(MSG_LINKING) $@
621 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
624 # Compile: create object files from C source files.
627 @echo $(MSG_COMPILING) $<
628 $(CC) -c $(ALL_CFLAGS) $< -o $@
631 # Compile: create object files from C++ source files.
632 $(OBJDIR)/%.o : %.cpp
634 @echo $(MSG_COMPILING_CPP) $<
635 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
638 # Compile: create assembler files from C source files.
640 $(CC) -S $(ALL_CFLAGS) $< -o $@
643 # Compile: create assembler files from C++ source files.
645 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
648 # Assemble: create object files from assembler source files.
651 @echo $(MSG_ASSEMBLING) $<
652 $(CC) -c $(ALL_ASFLAGS) $< -o $@
655 # Create preprocessed source for use in sending a bug report.
657 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
660 # Target: clean project.
661 clean: begin clean_list clean_binary end
664 $(REMOVE) $(TARGET).hex
667 @echo $(MSG_CLEANING)
668 $(REMOVE) $(TARGET).eep
669 $(REMOVE) $(TARGET).cof
670 $(REMOVE) $(TARGET).elf
671 $(REMOVE) $(TARGET).map
672 $(REMOVE) $(TARGET).sym
673 $(REMOVE) $(TARGET).lss
674 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
675 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
676 $(REMOVE) $(SRC:.c=.s)
677 $(REMOVE) $(SRC:.c=.d)
678 $(REMOVE) $(SRC:.c=.i)
683 @echo Generating Project Documentation...
684 @doxygen Doxygen.conf
685 @echo Documentation Generation Complete.
690 # Create object files directory
691 $(shell mkdir $(OBJDIR) 2>/dev/null)
694 # Include the dependency files.
695 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
698 # Listing of phony targets.
699 .PHONY : all checkhooks checklibmode begin \
700 finish end sizebefore sizeafter gccversion \
701 build elf hex eep lss sym coff extcoff \
702 clean clean_list clean_binary program debug \
703 gdb-config doxygen dfu flip