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 (USBKEY, STK525, STK526, RZUSBSTICK, 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 = AVRISP_Programmer
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.)
111 ../../LUFA/Scheduler/Scheduler.c \
112 ../../LUFA/Drivers/AT90USBXXX/Serial.c \
113 ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \
114 ../../LUFA/Drivers/USB/LowLevel/Endpoint.c \
115 ../../LUFA/Drivers/USB/LowLevel/DevChapter9.c \
116 ../../LUFA/Drivers/USB/HighLevel/USBTask.c \
117 ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \
118 ../../LUFA/Drivers/USB/HighLevel/Events.c \
119 ../../LUFA/Drivers/USB/HighLevel/StdDescriptors.c \
121 # List C++ source files here. (C dependencies are automatically generated.)
125 # List Assembler source files here.
126 # Make them always end in a capital .S. Files ending in a lowercase .s
127 # will not be considered source files but generated files (assembler
128 # output from the compiler), and will be deleted upon "make clean"!
129 # Even though the DOS/Win* filesystem matches both .s and .S the same,
130 # it will preserve the spelling of the filenames, and gcc itself does
131 # care about how the name is spelled on its command-line.
135 # Optimization level, can be [0, 1, 2, 3, s].
136 # 0 = turn off optimization. s = optimize for size.
137 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
142 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
143 # AVR Studio 4.10 requires dwarf-2.
144 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
148 # List any extra directories to look for include files here.
149 # Each directory must be seperated by a space.
150 # Use forward slashes for directory separators.
151 # For a directory that has spaces, enclose it in quotes.
152 EXTRAINCDIRS = ../../
155 # Compiler flag to set the C Standard level.
157 # gnu89 = c89 plus GCC extensions
158 # c99 = ISO C99 standard (not yet fully implemented)
159 # gnu99 = c99 plus GCC extensions
160 CSTANDARD = -std=gnu99
163 # Place -D or -U options here for C sources
164 CDEFS = -DF_CPU=$(F_CPU)UL -DBOARD=BOARD_$(BOARD) -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS
165 CDEFS += -DUSB_DEVICE_ONLY -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
168 # Place -D or -U options here for ASM sources
169 ADEFS = -DF_CPU=$(F_CPU)
172 # Place -D or -U options here for C++ sources
173 CPPDEFS = -DF_CPU=$(F_CPU)UL
174 #CPPDEFS += -D__STDC_LIMIT_MACROS
175 #CPPDEFS += -D__STDC_CONSTANT_MACROS
179 #---------------- Compiler Options C ----------------
180 # -g*: generate debugging information
181 # -O*: optimization level
182 # -f...: tuning, see GCC manual and avr-libc documentation
183 # -Wall...: warning level
184 # -Wa,...: tell GCC to pass this to the assembler.
185 # -adhlns...: create assembler listing
189 CFLAGS += -funsigned-char
190 CFLAGS += -funsigned-bitfields
191 CFLAGS += -ffunction-sections
192 CFLAGS += -fpack-struct
193 CFLAGS += -fshort-enums
194 CFLAGS += -finline-limit=20
196 CFLAGS += -Wstrict-prototypes
198 #CFLAGS += -fno-unit-at-a-time
199 #CFLAGS += -Wunreachable-code
200 #CFLAGS += -Wsign-compare
201 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
202 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
203 CFLAGS += $(CSTANDARD)
206 #---------------- Compiler Options C++ ----------------
207 # -g*: generate debugging information
208 # -O*: optimization level
209 # -f...: tuning, see GCC manual and avr-libc documentation
210 # -Wall...: warning level
211 # -Wa,...: tell GCC to pass this to the assembler.
212 # -adhlns...: create assembler listing
213 CPPFLAGS = -g$(DEBUG)
214 CPPFLAGS += $(CPPDEFS)
216 CPPFLAGS += -funsigned-char
217 CPPFLAGS += -funsigned-bitfields
218 CPPFLAGS += -fpack-struct
219 CPPFLAGS += -fshort-enums
220 CPPFLAGS += -fno-exceptions
223 #CPPFLAGS += -mshort-calls
224 #CPPFLAGS += -fno-unit-at-a-time
225 #CPPFLAGS += -Wstrict-prototypes
226 #CPPFLAGS += -Wunreachable-code
227 #CPPFLAGS += -Wsign-compare
228 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
229 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
230 #CPPFLAGS += $(CSTANDARD)
233 #---------------- Assembler Options ----------------
234 # -Wa,...: tell GCC to pass this to the assembler.
235 # -adhlns: create listing
236 # -gstabs: have the assembler create line number information; note that
237 # for use in COFF files, additional information about filenames
238 # and function names needs to be present in the assembler source
239 # files -- see avr-libc docs [FIXME: not yet described there]
240 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
241 # dump that will be displayed for a given single line of source input.
242 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
245 #---------------- Library Options ----------------
246 # Minimalistic printf version
247 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
249 # Floating point printf version (requires MATH_LIB = -lm below)
250 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
252 # If this is left blank, then it will use the Standard printf version.
254 #PRINTF_LIB = $(PRINTF_LIB_MIN)
255 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
258 # Minimalistic scanf version
259 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
261 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
262 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
264 # If this is left blank, then it will use the Standard scanf version.
266 #SCANF_LIB = $(SCANF_LIB_MIN)
267 #SCANF_LIB = $(SCANF_LIB_FLOAT)
273 # List any extra directories to look for libraries here.
274 # Each directory must be seperated by a space.
275 # Use forward slashes for directory separators.
276 # For a directory that has spaces, enclose it in quotes.
281 #---------------- External Memory Options ----------------
283 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
284 # used for variables (.data/.bss) and heap (malloc()).
285 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
287 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
288 # only used for heap (malloc()).
289 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
295 #---------------- Linker Options ----------------
296 # -Wl,...: tell GCC to pass this to linker.
297 # -Map: create map file
298 # --cref: add cross reference to map file
299 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
300 LDFLAGS += -Wl,--relax
301 LDFLAGS += -Wl,--gc-sections
302 LDFLAGS += $(EXTMEMOPTS)
303 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
304 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
305 #LDFLAGS += -T linker_script.x
309 #---------------- Programming Options (avrdude) ----------------
311 # Programming hardware: alf avr910 avrisp bascom bsd
312 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
315 # to get a full listing.
317 AVRDUDE_PROGRAMMER = jtagmkII
319 # com1 = serial port. Use lpt1 to connect to parallel port.
322 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
323 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
326 # Uncomment the following if you want avrdude's erase cycle counter.
327 # Note that this counter needs to be initialized first using -Yn,
328 # see avrdude manual.
329 #AVRDUDE_ERASE_COUNTER = -y
331 # Uncomment the following if you do /not/ wish a verification to be
332 # performed after programming the device.
333 #AVRDUDE_NO_VERIFY = -V
335 # Increase verbosity level. Please use this when submitting bug
336 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
337 # to submit bug reports.
338 #AVRDUDE_VERBOSE = -v -v
340 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
341 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
342 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
343 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
347 #---------------- Debugging Options ----------------
349 # For simulavr only - target MCU frequency.
350 DEBUG_MFREQ = $(F_CPU)
352 # Set the DEBUG_UI to either gdb or insight.
356 # Set the debugging back-end to either avarice, simulavr.
357 DEBUG_BACKEND = avarice
358 #DEBUG_BACKEND = simulavr
361 GDBINIT_FILE = __avr_gdbinit
363 # When using avarice settings for the JTAG
366 # Debugging port used to communicate between GDB / avarice / simulavr.
369 # Debugging host used to communicate between GDB / avarice / simulavr, normally
370 # just set to localhost unless doing some sort of crazy debugging when
371 # avarice is running on a different computer.
372 DEBUG_HOST = localhost
376 #============================================================================
379 # Define programs and commands.
382 OBJCOPY = avr-objcopy
383 OBJDUMP = avr-objdump
395 MSG_ERRORS_NONE = Errors: none
396 MSG_BEGIN = -------- begin --------
397 MSG_END = -------- end --------
398 MSG_SIZE_BEFORE = Size before:
399 MSG_SIZE_AFTER = Size after:
400 MSG_COFF = Converting to AVR COFF:
401 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
402 MSG_FLASH = Creating load file for Flash:
403 MSG_EEPROM = Creating load file for EEPROM:
404 MSG_EXTENDED_LISTING = Creating Extended Listing:
405 MSG_SYMBOL_TABLE = Creating Symbol Table:
406 MSG_LINKING = Linking:
407 MSG_COMPILING = Compiling C:
408 MSG_COMPILING_CPP = Compiling C++:
409 MSG_ASSEMBLING = Assembling:
410 MSG_CLEANING = Cleaning project:
411 MSG_CREATING_LIBRARY = Creating library:
416 # Define all object files.
417 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
419 # Define all listing files.
420 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
423 # Compiler flags to generate dependency files.
424 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
427 # Combine all necessary flags and optional flags.
428 # Add target processor to flags.
429 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
430 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
431 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
438 all: begin gccversion sizebefore build checkhooks checklibmode sizeafter end
440 # Change the build target to build a HEX file or a library.
441 build: elf hex eep lss sym
450 LIBNAME=lib$(TARGET).a
456 # AVR Studio 3.x does not check make's exit code but relies on
457 # the following magic strings to be generated by the compile job.
467 # Display size of file.
468 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
469 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
470 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
471 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
474 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
475 2>/dev/null; echo; fi
478 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
479 2>/dev/null; echo; fi
483 @echo ------- Unhooked LUFA Events -------
484 @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \
485 cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \
487 @echo ----- End Unhooked LUFA Events -----
491 @echo ----------- Library Mode -----------
492 @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \
493 | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \
494 || echo "No specific mode (both device and host mode allowable)."
495 @echo ------------------------------------
497 # Display compiler version information.
503 # Program the device.
504 program: $(TARGET).hex $(TARGET).eep
505 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
508 batchisp -hardware usb -device $(MCU) -operation erase f
509 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
510 batchisp -hardware usb -device $(MCU) -operation start reset 0
513 dfu-programmer $(MCU) erase
514 dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex
515 dfu-programmer $(MCU) reset
517 flip-ee: $(TARGET).hex $(TARGET).eep
518 copy $(TARGET).eep $(TARGET)eep.hex
519 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
520 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
521 batchisp -hardware usb -device $(MCU) -operation start reset 0
523 dfu-ee: $(TARGET).hex $(TARGET).eep
524 dfu-programmer $(MCU) erase
525 dfu-programmer $(MCU) eeprom --debug 1 $(TARGET).eep
526 dfu-programmer $(MCU) reset
528 # Generate avr-gdb config/init file which does the following:
529 # define the reset signal, load the target file, connect to target, and set
530 # a breakpoint at main().
532 @$(REMOVE) $(GDBINIT_FILE)
533 @echo define reset >> $(GDBINIT_FILE)
534 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
535 @echo end >> $(GDBINIT_FILE)
536 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
537 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
538 ifeq ($(DEBUG_BACKEND),simulavr)
539 @echo load >> $(GDBINIT_FILE)
541 @echo break main >> $(GDBINIT_FILE)
543 debug: gdb-config $(TARGET).elf
544 ifeq ($(DEBUG_BACKEND), avarice)
545 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
546 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
547 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
548 @$(WINSHELL) /c pause
551 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
552 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
554 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
559 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
560 COFFCONVERT = $(OBJCOPY) --debugging
561 COFFCONVERT += --change-section-address .data-0x800000
562 COFFCONVERT += --change-section-address .bss-0x800000
563 COFFCONVERT += --change-section-address .noinit-0x800000
564 COFFCONVERT += --change-section-address .eeprom-0x810000
570 @echo $(MSG_COFF) $(TARGET).cof
571 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
574 extcoff: $(TARGET).elf
576 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
577 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
581 # Create final output files (.hex, .eep) from ELF output file.
584 @echo $(MSG_FLASH) $@
585 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
589 @echo $(MSG_EEPROM) $@
590 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
591 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
593 # Create extended listing file from ELF output file.
596 @echo $(MSG_EXTENDED_LISTING) $@
597 $(OBJDUMP) -h -z -S $< > $@
599 # Create a symbol table from ELF output file.
602 @echo $(MSG_SYMBOL_TABLE) $@
607 # Create library from object files.
608 .SECONDARY : $(TARGET).a
612 @echo $(MSG_CREATING_LIBRARY) $@
616 # Link: create ELF output file from object files.
617 .SECONDARY : $(TARGET).elf
621 @echo $(MSG_LINKING) $@
622 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
625 # Compile: create object files from C source files.
628 @echo $(MSG_COMPILING) $<
629 $(CC) -c $(ALL_CFLAGS) $< -o $@
632 # Compile: create object files from C++ source files.
633 $(OBJDIR)/%.o : %.cpp
635 @echo $(MSG_COMPILING_CPP) $<
636 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
639 # Compile: create assembler files from C source files.
641 $(CC) -S $(ALL_CFLAGS) $< -o $@
644 # Compile: create assembler files from C++ source files.
646 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
649 # Assemble: create object files from assembler source files.
652 @echo $(MSG_ASSEMBLING) $<
653 $(CC) -c $(ALL_ASFLAGS) $< -o $@
656 # Create preprocessed source for use in sending a bug report.
658 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
661 # Target: clean project.
662 clean: begin clean_list clean_binary end
665 $(REMOVE) $(TARGET).hex
668 @echo $(MSG_CLEANING)
669 $(REMOVE) $(TARGET).eep
670 $(REMOVE) $(TARGET).cof
671 $(REMOVE) $(TARGET).elf
672 $(REMOVE) $(TARGET).map
673 $(REMOVE) $(TARGET).sym
674 $(REMOVE) $(TARGET).lss
675 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
676 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
677 $(REMOVE) $(SRC:.c=.s)
678 $(REMOVE) $(SRC:.c=.d)
679 $(REMOVE) $(SRC:.c=.i)
684 @echo Generating Project Documentation...
685 @doxygen Doxygen.conf
686 @echo Documentation Generation Complete.
691 # Create object files directory
692 $(shell mkdir $(OBJDIR) 2>/dev/null)
695 # Include the dependency files.
696 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
699 # Listing of phony targets.
700 .PHONY : all checkhooks checklibmode begin \
701 finish end sizebefore sizeafter gccversion \
702 build elf hex eep lss sym coff extcoff \
703 clean clean_list clean_binary program debug \
704 gdb-config doxygen dfu flip