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, 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.
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.
66 # This will be an integer division of F_CLOCK below, as it is sourced by
67 # F_CLOCK after it has run through any CPU prescalers. Note that this value
68 # does not *change* the processor frequency - it should merely be updated to
69 # reflect the processor speed set externally so that the code can use accurate
74 # Input clock frequency.
75 # This will define a symbol, F_CLOCK, in all source code files equal to the
76 # input clock frequency (before any prescaling is performed) in Hz. This value may
77 # differ from F_CPU if prescaling is used on the latter, and is required as the
78 # raw input clock is fed directly to the PLL sections of the AVR for high speed
79 # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
80 # at the end, this will be done automatically to create a 32-bit value in your
83 # If no clock division is performed on the input clock inside the AVR (via the
84 # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
88 # Starting byte address of the bootloader, as a byte address. Note that the address given
89 # in the AVRStudio fuse programming dialogue uses word addresses, which will have to be
90 # doubled to obtain the starting byte address of the bootloader section.
94 # Output format. (can be srec, ihex, binary)
98 # Target file name (without extension).
99 TARGET = BootloaderCDC
102 # Object files directory
103 # To put object files in current directory, use a dot (.), do NOT make
104 # this an empty or blank macro!
108 # Path to the LUFA library
112 # LUFA library compile-time options and predefined tokens
113 LUFA_OPTS = -D USB_DEVICE_ONLY
114 LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
115 LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
116 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
117 LUFA_OPTS += -D USE_RAM_DESCRIPTORS
118 LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
119 LUFA_OPTS += -D NO_INTERNAL_SERIAL
120 LUFA_OPTS += -D NO_DEVICE_SELF_POWER
121 LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP
124 # Create the LUFA source path variables by including the LUFA root makefile
125 include $(LUFA_PATH)/LUFA/makefile
128 # List C source files here. (C dependencies are automatically generated.)
134 # List C++ source files here. (C dependencies are automatically generated.)
138 # List Assembler source files here.
139 # Make them always end in a capital .S. Files ending in a lowercase .s
140 # will not be considered source files but generated files (assembler
141 # output from the compiler), and will be deleted upon "make clean"!
142 # Even though the DOS/Win* filesystem matches both .s and .S the same,
143 # it will preserve the spelling of the filenames, and gcc itself does
144 # care about how the name is spelled on its command-line.
148 # Optimization level, can be [0, 1, 2, 3, s].
149 # 0 = turn off optimization. s = optimize for size.
150 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
155 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
156 # AVR Studio 4.10 requires dwarf-2.
157 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
161 # List any extra directories to look for include files here.
162 # Each directory must be seperated by a space.
163 # Use forward slashes for directory separators.
164 # For a directory that has spaces, enclose it in quotes.
165 EXTRAINCDIRS = $(LUFA_PATH)/
168 # Compiler flag to set the C Standard level.
170 # gnu89 = c89 plus GCC extensions
171 # c99 = ISO C99 standard (not yet fully implemented)
172 # gnu99 = c99 plus GCC extensions
176 # Place -D or -U options here for C sources
177 CDEFS = -DF_CPU=$(F_CPU)UL
178 CDEFS += -DF_CLOCK=$(F_CLOCK)UL
179 CDEFS += -DBOARD=BOARD_$(BOARD)
180 CDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
181 CDEFS += $(LUFA_OPTS)
184 # Place -D or -U options here for ASM sources
185 ADEFS = -DF_CPU=$(F_CPU)
186 ADEFS += -DF_CLOCK=$(F_CLOCK)UL
187 ADEFS += -DBOARD=BOARD_$(BOARD)
188 CDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
189 ADEFS += $(LUFA_OPTS)
191 # Place -D or -U options here for C++ sources
192 CPPDEFS = -DF_CPU=$(F_CPU)UL
193 CPPDEFS += -DF_CLOCK=$(F_CLOCK)UL
194 CPPDEFS += -DBOARD=BOARD_$(BOARD)
195 CDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
196 CPPDEFS += $(LUFA_OPTS)
197 #CPPDEFS += -D__STDC_LIMIT_MACROS
198 #CPPDEFS += -D__STDC_CONSTANT_MACROS
202 #---------------- Compiler Options C ----------------
203 # -g*: generate debugging information
204 # -O*: optimization level
205 # -f...: tuning, see GCC manual and avr-libc documentation
206 # -Wall...: warning level
207 # -Wa,...: tell GCC to pass this to the assembler.
208 # -adhlns...: create assembler listing
212 CFLAGS += -funsigned-char
213 CFLAGS += -funsigned-bitfields
214 CFLAGS += -ffunction-sections
215 CFLAGS += -fno-inline-small-functions
216 CFLAGS += -fpack-struct
217 CFLAGS += -fshort-enums
218 CFLAGS += -fno-strict-aliasing
220 CFLAGS += -Wstrict-prototypes
221 #CFLAGS += -mshort-calls
222 #CFLAGS += -fno-unit-at-a-time
224 #CFLAGS += -Wunreachable-code
225 #CFLAGS += -Wsign-compare
226 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
227 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
228 CFLAGS += $(CSTANDARD)
231 #---------------- Compiler Options C++ ----------------
232 # -g*: generate debugging information
233 # -O*: optimization level
234 # -f...: tuning, see GCC manual and avr-libc documentation
235 # -Wall...: warning level
236 # -Wa,...: tell GCC to pass this to the assembler.
237 # -adhlns...: create assembler listing
238 CPPFLAGS = -g$(DEBUG)
239 CPPFLAGS += $(CPPDEFS)
241 CPPFLAGS += -funsigned-char
242 CPPFLAGS += -funsigned-bitfields
243 CPPFLAGS += -fpack-struct
244 CPPFLAGS += -fshort-enums
245 CPPFLAGS += -fno-exceptions
248 #CPPFLAGS += -mshort-calls
249 #CPPFLAGS += -fno-unit-at-a-time
250 #CPPFLAGS += -Wstrict-prototypes
251 #CPPFLAGS += -Wunreachable-code
252 #CPPFLAGS += -Wsign-compare
253 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
254 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
255 #CPPFLAGS += $(CSTANDARD)
258 #---------------- Assembler Options ----------------
259 # -Wa,...: tell GCC to pass this to the assembler.
260 # -adhlns: create listing
261 # -gstabs: have the assembler create line number information; note that
262 # for use in COFF files, additional information about filenames
263 # and function names needs to be present in the assembler source
264 # files -- see avr-libc docs [FIXME: not yet described there]
265 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
266 # dump that will be displayed for a given single line of source input.
267 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
270 #---------------- Library Options ----------------
271 # Minimalistic printf version
272 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
274 # Floating point printf version (requires MATH_LIB = -lm below)
275 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
277 # If this is left blank, then it will use the Standard printf version.
279 #PRINTF_LIB = $(PRINTF_LIB_MIN)
280 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
283 # Minimalistic scanf version
284 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
286 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
287 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
289 # If this is left blank, then it will use the Standard scanf version.
291 #SCANF_LIB = $(SCANF_LIB_MIN)
292 #SCANF_LIB = $(SCANF_LIB_FLOAT)
298 # List any extra directories to look for libraries here.
299 # Each directory must be seperated by a space.
300 # Use forward slashes for directory separators.
301 # For a directory that has spaces, enclose it in quotes.
306 #---------------- External Memory Options ----------------
308 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
309 # used for variables (.data/.bss) and heap (malloc()).
310 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
312 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
313 # only used for heap (malloc()).
314 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
320 #---------------- Linker Options ----------------
321 # -Wl,...: tell GCC to pass this to linker.
322 # -Map: create map file
323 # --cref: add cross reference to map file
324 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
325 LDFLAGS += -Wl,--relax
326 LDFLAGS += -Wl,--gc-sections
327 LDFLAGS += $(EXTMEMOPTS)
328 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
329 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
330 #LDFLAGS += -T linker_script.x
334 #---------------- Programming Options (avrdude) ----------------
336 # Programming hardware
338 # to get a full listing.
340 AVRDUDE_PROGRAMMER = jtagmkII
342 # com1 = serial port. Use lpt1 to connect to parallel port.
345 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
346 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
349 # Uncomment the following if you want avrdude's erase cycle counter.
350 # Note that this counter needs to be initialized first using -Yn,
351 # see avrdude manual.
352 #AVRDUDE_ERASE_COUNTER = -y
354 # Uncomment the following if you do /not/ wish a verification to be
355 # performed after programming the device.
356 #AVRDUDE_NO_VERIFY = -V
358 # Increase verbosity level. Please use this when submitting bug
359 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
360 # to submit bug reports.
361 #AVRDUDE_VERBOSE = -v -v
363 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
364 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
365 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
366 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
370 #---------------- Debugging Options ----------------
372 # For simulavr only - target MCU frequency.
373 DEBUG_MFREQ = $(F_CPU)
375 # Set the DEBUG_UI to either gdb or insight.
379 # Set the debugging back-end to either avarice, simulavr.
380 DEBUG_BACKEND = avarice
381 #DEBUG_BACKEND = simulavr
384 GDBINIT_FILE = __avr_gdbinit
386 # When using avarice settings for the JTAG
389 # Debugging port used to communicate between GDB / avarice / simulavr.
392 # Debugging host used to communicate between GDB / avarice / simulavr, normally
393 # just set to localhost unless doing some sort of crazy debugging when
394 # avarice is running on a different computer.
395 DEBUG_HOST = localhost
399 #============================================================================
402 # Define programs and commands.
405 OBJCOPY = avr-objcopy
406 OBJDUMP = avr-objdump
419 MSG_ERRORS_NONE = Errors: none
420 MSG_BEGIN = -------- begin --------
421 MSG_END = -------- end --------
422 MSG_SIZE_BEFORE = Size before:
423 MSG_SIZE_AFTER = Size after:
424 MSG_COFF = Converting to AVR COFF:
425 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
426 MSG_FLASH = Creating load file for Flash:
427 MSG_EEPROM = Creating load file for EEPROM:
428 MSG_EXTENDED_LISTING = Creating Extended Listing:
429 MSG_SYMBOL_TABLE = Creating Symbol Table:
430 MSG_LINKING = Linking:
431 MSG_COMPILING = Compiling C:
432 MSG_COMPILING_CPP = Compiling C++:
433 MSG_ASSEMBLING = Assembling:
434 MSG_CLEANING = Cleaning project:
435 MSG_CREATING_LIBRARY = Creating library:
440 # Define all object files.
441 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
443 # Define all listing files.
444 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
447 # Compiler flags to generate dependency files.
448 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
451 # Combine all necessary flags and optional flags.
452 # Add target processor to flags.
453 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
454 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
455 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
462 all: begin gccversion sizebefore build sizeafter end
464 # Change the build target to build a HEX file or a library.
465 build: elf hex eep lss sym
474 LIBNAME=lib$(TARGET).a
480 # AVR Studio 3.x does not check make's exit code but relies on
481 # the following magic strings to be generated by the compile job.
491 # Display size of file.
492 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
493 ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
496 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
497 2>/dev/null; echo; fi
500 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
501 2>/dev/null; echo; fi
505 # Display compiler version information.
510 # Program the device.
511 program: $(TARGET).hex $(TARGET).eep
512 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
515 # Generate avr-gdb config/init file which does the following:
516 # define the reset signal, load the target file, connect to target, and set
517 # a breakpoint at main().
519 @$(REMOVE) $(GDBINIT_FILE)
520 @echo define reset >> $(GDBINIT_FILE)
521 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
522 @echo end >> $(GDBINIT_FILE)
523 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
524 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
525 ifeq ($(DEBUG_BACKEND),simulavr)
526 @echo load >> $(GDBINIT_FILE)
528 @echo break main >> $(GDBINIT_FILE)
530 debug: gdb-config $(TARGET).elf
531 ifeq ($(DEBUG_BACKEND), avarice)
532 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
533 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
534 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
535 @$(WINSHELL) /c pause
538 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
539 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
541 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
546 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
547 COFFCONVERT = $(OBJCOPY) --debugging
548 COFFCONVERT += --change-section-address .data-0x800000
549 COFFCONVERT += --change-section-address .bss-0x800000
550 COFFCONVERT += --change-section-address .noinit-0x800000
551 COFFCONVERT += --change-section-address .eeprom-0x810000
557 @echo $(MSG_COFF) $(TARGET).cof
558 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
561 extcoff: $(TARGET).elf
563 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
564 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
568 # Create final output files (.hex, .eep) from ELF output file.
571 @echo $(MSG_FLASH) $@
572 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@
576 @echo $(MSG_EEPROM) $@
577 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
578 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
580 # Create extended listing file from ELF output file.
583 @echo $(MSG_EXTENDED_LISTING) $@
584 $(OBJDUMP) -h -S -z $< > $@
586 # Create a symbol table from ELF output file.
589 @echo $(MSG_SYMBOL_TABLE) $@
594 # Create library from object files.
595 .SECONDARY : $(TARGET).a
599 @echo $(MSG_CREATING_LIBRARY) $@
603 # Link: create ELF output file from object files.
604 .SECONDARY : $(TARGET).elf
608 @echo $(MSG_LINKING) $@
609 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
612 # Compile: create object files from C source files.
615 @echo $(MSG_COMPILING) $<
616 $(CC) -c $(ALL_CFLAGS) $< -o $@
619 # Compile: create object files from C++ source files.
620 $(OBJDIR)/%.o : %.cpp
622 @echo $(MSG_COMPILING_CPP) $<
623 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
626 # Compile: create assembler files from C source files.
628 $(CC) -S $(ALL_CFLAGS) $< -o $@
631 # Compile: create assembler files from C++ source files.
633 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
636 # Assemble: create object files from assembler source files.
639 @echo $(MSG_ASSEMBLING) $<
640 $(CC) -c $(ALL_ASFLAGS) $< -o $@
643 # Create preprocessed source for use in sending a bug report.
645 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
648 # Target: clean project.
649 clean: begin clean_list end
653 @echo $(MSG_CLEANING)
654 $(REMOVE) $(TARGET).hex
655 $(REMOVE) $(TARGET).eep
656 $(REMOVE) $(TARGET).cof
657 $(REMOVE) $(TARGET).elf
658 $(REMOVE) $(TARGET).map
659 $(REMOVE) $(TARGET).sym
660 $(REMOVE) $(TARGET).lss
661 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
662 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
663 $(REMOVE) $(SRC:.c=.s)
664 $(REMOVE) $(SRC:.c=.d)
665 $(REMOVE) $(SRC:.c=.i)
669 @echo Generating Project Documentation...
670 @doxygen Doxygen.conf
671 @echo Documentation Generation Complete.
676 # Create object files directory
677 $(shell mkdir $(OBJDIR) 2>/dev/null)
680 # Include the dependency files.
681 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
684 # Listing of phony targets.
685 .PHONY : all begin finish end sizebefore sizeafter gccversion \
686 build elf hex eep lss sym coff extcoff doxygen clean \
687 clean_list clean_doxygen program debug gdb-config