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. <<
5#
6# Released to the Public Domain
7#
8# Additional material for this makefile was written by:
9# Peter Fleury
10# Tim Henigan
11# Colin O'Flynn
12# Reiner Patommel
13# Markus Pfaff
14# Sander Pool
15# Frederik Rouleau
16# Carlos Lamas
17# Dean Camera
18# Opendous Inc.
19# Denver Gingerich
20#
21#----------------------------------------------------------------------------
22# On command line:
23#
24# make all = Make software.
25#
26# make clean = Clean out built project files.
27#
28# make coff = Convert ELF to AVR COFF.
29#
30# make extcoff = Convert ELF to AVR Extended COFF.
31#
32# make program = Download the hex file to the device, using avrdude.
33#                Please customize the avrdude settings below first!
34#
35# make dfu = Download the hex file to the device, using dfu-programmer (must
36#            have dfu-programmer installed).
37#
38# make flip = Download the hex file to the device, using Atmel FLIP (must
39#             have Atmel FLIP installed).
40#
41# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
42#               (must have dfu-programmer installed).
43#
44# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
45#                (must have Atmel FLIP installed).
46#
47# make doxygen = Generate DoxyGen documentation for the project (must have
48#                DoxyGen installed)
49#
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.
52#
53# make filename.s = Just compile filename.c into the assembler code only.
54#
55# make filename.i = Create a preprocessed source file for use in submitting
56#                   bug reports to the GCC project.
57#
58# To rebuild project do "make clean" then "make all".
59#----------------------------------------------------------------------------
60
61# MCU name(s)
62# 	Since the ATMEGA8U2 part is not directly supported by the current
63#	versions of either avrdude or dfu-programmer, we specify a dummy
64#	part; AT90USB82 which is close enough in memory size and organization
65
66#MCU = atmega8u2
67MCU = atmega16u2
68#MCU = atmega32u2
69
70# MCU_AVRDUDE = at90usb82
71# MCU_DFU = at90usb82
72MCU_AVRDUDE = $(MCU)
73MCU_DFU = $(MCU)
74
75# Specify the Arduino model using the assigned PID.  This is used by Descriptors.c
76#   to set PID and product descriptor string
77# Uno PID:
78#ARDUINO_MODEL_PID = 0x0001
79# Mega 2560 PID:
80#ARDUINO_MODEL_PID = 0x0010
81# Due PID:
82ARDUINO_MODEL_PID = 0x003D
83
84
85
86# Target board (see library "Board Types" documentation, NONE for projects not requiring
87# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
88# "Board" inside the application directory.
89BOARD  = USER
90
91
92# Processor frequency.
93#     This will define a symbol, F_CPU, in all source code files equal to the
94#     processor frequency in Hz. You can then use this symbol in your source code to
95#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
96#     automatically to create a 32-bit value in your source code.
97#
98#     This will be an integer division of F_CLOCK below, as it is sourced by
99#     F_CLOCK after it has run through any CPU prescalers. Note that this value
100#     does not *change* the processor frequency - it should merely be updated to
101#     reflect the processor speed set externally so that the code can use accurate
102#     software delays.
103#F_CPU = 8000000
104F_CPU = 16000000
105
106
107# Input clock frequency.
108#     This will define a symbol, F_CLOCK, in all source code files equal to the
109#     input clock frequency (before any prescaling is performed) in Hz. This value may
110#     differ from F_CPU if prescaling is used on the latter, and is required as the
111#     raw input clock is fed directly to the PLL sections of the AVR for high speed
112#     clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
113#     at the end, this will be done automatically to create a 32-bit value in your
114#     source code.
115#
116#     If no clock division is performed on the input clock inside the AVR (via the
117#     CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
118F_CLOCK = $(F_CPU)
119
120
121# Output format. (can be srec, ihex, binary)
122FORMAT = ihex
123
124
125# Target file name (without extension).
126TARGET = Arduino-usbserial
127
128
129# Object files directory
130#     To put object files in current directory, use a dot (.), do NOT make
131#     this an empty or blank macro!
132OBJDIR = .
133
134
135# Path to the LUFA library
136LUFA_PATH = ../..
137
138
139# LUFA library compile-time options
140LUFA_OPTS  = -D USB_DEVICE_ONLY
141LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
142LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
143LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
144LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT
145LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
146LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
147
148
149# Create the LUFA source path variables by including the LUFA root makefile
150include $(LUFA_PATH)/LUFA/makefile
151
152
153# List C source files here. (C dependencies are automatically generated.)
154SRC = $(TARGET).c                                                 \
155	  Descriptors.c                                               \
156	  $(LUFA_SRC_USB)                                             \
157	  $(LUFA_SRC_USBCLASS)										  \
158	  $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Device.c			  \
159	  $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c           \
160	  $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/HostStandardReq.c	  \
161	  $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c               \
162 	  $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Pipe.c               \
163 	  $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/USBController.c      \
164	  $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/Events.c            \
165	  $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/USBInterrupt.c       \
166	  $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \
167	  $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c \
168	  $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \
169	  $(LUFA_PATH)/LUFA/Drivers/USB/Class/Device/CDC.c            \
170	  $(LUFA_PATH)/LUFA/Drivers/USB/Class/Host/CDC.c
171
172
173# List C++ source files here. (C dependencies are automatically generated.)
174CPPSRC =
175
176
177# List Assembler source files here.
178#     Make them always end in a capital .S.  Files ending in a lowercase .s
179#     will not be considered source files but generated files (assembler
180#     output from the compiler), and will be deleted upon "make clean"!
181#     Even though the DOS/Win* filesystem matches both .s and .S the same,
182#     it will preserve the spelling of the filenames, and gcc itself does
183#     care about how the name is spelled on its command-line.
184ASRC =
185
186
187# Optimization level, can be [0, 1, 2, 3, s].
188#     0 = turn off optimization. s = optimize for size.
189#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
190OPT = s
191
192
193# Debugging format.
194#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
195#     AVR Studio 4.10 requires dwarf-2.
196#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
197DEBUG = dwarf-2
198
199
200# List any extra directories to look for include files here.
201#     Each directory must be seperated by a space.
202#     Use forward slashes for directory separators.
203#     For a directory that has spaces, enclose it in quotes.
204EXTRAINCDIRS = $(LUFA_PATH)/
205
206
207# Compiler flag to set the C Standard level.
208#     c89   = "ANSI" C
209#     gnu89 = c89 plus GCC extensions
210#     c99   = ISO C99 standard (not yet fully implemented)
211#     gnu99 = c99 plus GCC extensions
212CSTANDARD = -std=gnu99
213
214
215# Place -D or -U options here for C sources
216CDEFS  = -DF_CPU=$(F_CPU)UL
217CDEFS += -DF_CLOCK=$(F_CLOCK)UL
218CDEFS += -DARDUINO_MODEL_PID=$(ARDUINO_MODEL_PID)
219CDEFS += -DBOARD=BOARD_$(BOARD)
220CDEFS += $(LUFA_OPTS)
221
222CDEFS += -DAVR_RESET_LINE_PORT="PORTC"
223CDEFS += -DAVR_RESET_LINE_DDR="DDRC"
224CDEFS += -DAVR_RESET_LINE_MASK="(1 << 7)"
225
226CDEFS += -DAVR_ERASE_LINE_PORT="PORTC"
227CDEFS += -DAVR_ERASE_LINE_DDR="DDRC"
228CDEFS += -DAVR_ERASE_LINE_MASK="(1 << 6)"
229
230CDEFS += -DTX_RX_LED_PULSE_MS=3
231CDEFS += -DPING_PONG_LED_PULSE_MS=100
232
233# Place -D or -U options here for ASM sources
234ADEFS  = -DF_CPU=$(F_CPU)
235ADEFS += -DF_CLOCK=$(F_CLOCK)UL
236ADEFS += -DBOARD=BOARD_$(BOARD)
237ADEFS += $(LUFA_OPTS)
238
239# Place -D or -U options here for C++ sources
240CPPDEFS  = -DF_CPU=$(F_CPU)UL
241CPPDEFS += -DF_CLOCK=$(F_CLOCK)UL
242CPPDEFS += -DBOARD=BOARD_$(BOARD)
243CPPDEFS += $(LUFA_OPTS)
244#CPPDEFS += -D__STDC_LIMIT_MACROS
245#CPPDEFS += -D__STDC_CONSTANT_MACROS
246
247
248
249#---------------- Compiler Options C ----------------
250#  -g*:          generate debugging information
251#  -O*:          optimization level
252#  -f...:        tuning, see GCC manual and avr-libc documentation
253#  -Wall...:     warning level
254#  -Wa,...:      tell GCC to pass this to the assembler.
255#    -adhlns...: create assembler listing
256CFLAGS = -g$(DEBUG)
257CFLAGS += $(CDEFS)
258CFLAGS += -O$(OPT)
259CFLAGS += -funsigned-char
260CFLAGS += -funsigned-bitfields
261CFLAGS += -ffunction-sections
262CFLAGS += -fno-inline-small-functions
263CFLAGS += -fpack-struct
264CFLAGS += -fshort-enums
265CFLAGS += -fno-strict-aliasing
266CFLAGS += -Wall
267CFLAGS += -Wstrict-prototypes
268#CFLAGS += -mshort-calls
269#CFLAGS += -fno-unit-at-a-time
270#CFLAGS += -Wundef
271#CFLAGS += -Wunreachable-code
272#CFLAGS += -Wsign-compare
273CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
274CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
275CFLAGS += $(CSTANDARD)
276
277
278#---------------- Compiler Options C++ ----------------
279#  -g*:          generate debugging information
280#  -O*:          optimization level
281#  -f...:        tuning, see GCC manual and avr-libc documentation
282#  -Wall...:     warning level
283#  -Wa,...:      tell GCC to pass this to the assembler.
284#    -adhlns...: create assembler listing
285CPPFLAGS = -g$(DEBUG)
286CPPFLAGS += $(CPPDEFS)
287CPPFLAGS += -O$(OPT)
288CPPFLAGS += -funsigned-char
289CPPFLAGS += -funsigned-bitfields
290CPPFLAGS += -fpack-struct
291CPPFLAGS += -fshort-enums
292CPPFLAGS += -fno-exceptions
293CPPFLAGS += -Wall
294CPPFLAGS += -Wundef
295CFLAGS += -Wundef
296#CPPFLAGS += -mshort-calls
297#CPPFLAGS += -fno-unit-at-a-time
298#CPPFLAGS += -Wstrict-prototypes
299#CPPFLAGS += -Wunreachable-code
300#CPPFLAGS += -Wsign-compare
301CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
302CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
303#CPPFLAGS += $(CSTANDARD)
304
305
306#---------------- Assembler Options ----------------
307#  -Wa,...:   tell GCC to pass this to the assembler.
308#  -adhlns:   create listing
309#  -gstabs:   have the assembler create line number information; note that
310#             for use in COFF files, additional information about filenames
311#             and function names needs to be present in the assembler source
312#             files -- see avr-libc docs [FIXME: not yet described there]
313#  -listing-cont-lines: Sets the maximum number of continuation lines of hex
314#       dump that will be displayed for a given single line of source input.
315ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
316
317
318#---------------- Library Options ----------------
319# Minimalistic printf version
320PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
321
322# Floating point printf version (requires MATH_LIB = -lm below)
323PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
324
325# If this is left blank, then it will use the Standard printf version.
326PRINTF_LIB =
327#PRINTF_LIB = $(PRINTF_LIB_MIN)
328#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
329
330
331# Minimalistic scanf version
332SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
333
334# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
335SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
336
337# If this is left blank, then it will use the Standard scanf version.
338SCANF_LIB =
339#SCANF_LIB = $(SCANF_LIB_MIN)
340#SCANF_LIB = $(SCANF_LIB_FLOAT)
341
342
343MATH_LIB = -lm
344
345
346# List any extra directories to look for libraries here.
347#     Each directory must be seperated by a space.
348#     Use forward slashes for directory separators.
349#     For a directory that has spaces, enclose it in quotes.
350EXTRALIBDIRS =
351
352
353
354#---------------- External Memory Options ----------------
355
356# 64 KB of external RAM, starting after internal RAM (ATmega128!),
357# used for variables (.data/.bss) and heap (malloc()).
358#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
359
360# 64 KB of external RAM, starting after internal RAM (ATmega128!),
361# only used for heap (malloc()).
362#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
363
364EXTMEMOPTS =
365
366
367
368#---------------- Linker Options ----------------
369#  -Wl,...:     tell GCC to pass this to linker.
370#    -Map:      create map file
371#    --cref:    add cross reference to  map file
372LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref
373LDFLAGS += -Wl,--relax
374LDFLAGS += -Wl,--gc-sections
375LDFLAGS += $(EXTMEMOPTS)
376LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
377LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
378#LDFLAGS += -T linker_script.x
379
380
381
382#---------------- Programming Options (avrdude) ----------------
383
384# Programming hardware
385# Type: avrdude -c ?
386# to get a full listing.
387#
388AVRDUDE_PROGRAMMER = avrispmkii
389
390# com1 = serial port. Use lpt1 to connect to parallel port.
391AVRDUDE_PORT = usb
392
393AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
394#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
395
396
397# Uncomment the following if you want avrdude's erase cycle counter.
398# Note that this counter needs to be initialized first using -Yn,
399# see avrdude manual.
400#AVRDUDE_ERASE_COUNTER = -y
401
402# Uncomment the following if you do /not/ wish a verification to be
403# performed after programming the device.
404#AVRDUDE_NO_VERIFY = -V
405
406# Increase verbosity level.  Please use this when submitting bug
407# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
408# to submit bug reports.
409#AVRDUDE_VERBOSE = -v -v
410
411AVRDUDE_FORCE = -F
412
413AVRDUDE_FLAGS = -p $(MCU_AVRDUDE) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
414AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
415AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
416AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
417AVRDUDE_FLAGS += $(AVRDUDE_FORCE)
418
419
420
421#---------------- Debugging Options ----------------
422
423# For simulavr only - target MCU frequency.
424DEBUG_MFREQ = $(F_CPU)
425
426# Set the DEBUG_UI to either gdb or insight.
427# DEBUG_UI = gdb
428DEBUG_UI = insight
429
430# Set the debugging back-end to either avarice, simulavr.
431DEBUG_BACKEND = avarice
432#DEBUG_BACKEND = simulavr
433
434# GDB Init Filename.
435GDBINIT_FILE = __avr_gdbinit
436
437# When using avarice settings for the JTAG
438JTAG_DEV = /dev/com1
439
440# Debugging port used to communicate between GDB / avarice / simulavr.
441DEBUG_PORT = 4242
442
443# Debugging host used to communicate between GDB / avarice / simulavr, normally
444#     just set to localhost unless doing some sort of crazy debugging when
445#     avarice is running on a different computer.
446DEBUG_HOST = localhost
447
448
449
450#============================================================================
451
452
453# Define programs and commands.
454SHELL = sh
455CC = avr-gcc
456OBJCOPY = avr-objcopy
457OBJDUMP = avr-objdump
458SIZE = avr-size
459AR = avr-ar rcs
460NM = avr-nm
461AVRDUDE = avrdude
462REMOVE = rm -f
463REMOVEDIR = rm -rf
464COPY = cp
465WINSHELL = cmd
466
467# Define Messages
468# English
469MSG_ERRORS_NONE = Errors: none
470MSG_BEGIN = -------- begin --------
471MSG_END = --------  end  --------
472MSG_SIZE_BEFORE = Size before:
473MSG_SIZE_AFTER = Size after:
474MSG_COFF = Converting to AVR COFF:
475MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
476MSG_FLASH = Creating load file for Flash:
477MSG_EEPROM = Creating load file for EEPROM:
478MSG_EXTENDED_LISTING = Creating Extended Listing:
479MSG_SYMBOL_TABLE = Creating Symbol Table:
480MSG_LINKING = Linking:
481MSG_COMPILING = Compiling C:
482MSG_COMPILING_CPP = Compiling C++:
483MSG_ASSEMBLING = Assembling:
484MSG_CLEANING = Cleaning project:
485MSG_CREATING_LIBRARY = Creating library:
486
487
488
489
490# Define all object files.
491OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
492
493# Define all listing files.
494LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
495
496
497# Compiler flags to generate dependency files.
498GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
499
500
501# Combine all necessary flags and optional flags.
502# Add target processor to flags.
503ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
504ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
505ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
506
507
508
509
510
511# Default target.
512#all: begin gccversion sizebefore build checkinvalidevents showliboptions showtarget sizeafter end
513all: begin gccversion sizebefore build showliboptions showtarget sizeafter end
514
515# Change the build target to build a HEX file or a library.
516build: elf hex eep lss sym asm
517#build: lib
518
519
520elf: $(TARGET).elf
521hex: $(TARGET).hex
522eep: $(TARGET).eep
523lss: $(TARGET).lss
524sym: $(TARGET).sym
525asm: $(TARGET).s
526LIBNAME=lib$(TARGET).a
527lib: $(LIBNAME)
528
529
530
531# Eye candy.
532# AVR Studio 3.x does not check make's exit code but relies on
533# the following magic strings to be generated by the compile job.
534begin:
535	@echo
536	@echo $(MSG_BEGIN)
537
538end:
539	@echo $(MSG_END)
540	@echo
541
542
543# Display size of file.
544HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
545ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
546MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
547FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
548
549sizebefore:
550	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
551	2>/dev/null; echo; fi
552
553sizeafter:
554	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
555	2>/dev/null; echo; fi
556
557#$(LUFA_PATH)/LUFA/LUFA_Events.lst:
558#	@make -C $(LUFA_PATH)/LUFA/ LUFA_Events.lst
559
560#checkinvalidevents: $(LUFA_PATH)/LUFA/LUFA_Events.lst
561#	@echo
562#	@echo Checking for invalid events...
563#	@$(shell) avr-nm $(OBJ) | sed -n -e 's/^.*EVENT_/EVENT_/p' | \
564#	                 grep -F -v --file=$(LUFA_PATH)/LUFA/LUFA_Events.lst > InvalidEvents.tmp || true
565#	@sed -n -e 's/^/  WARNING - INVALID EVENT NAME: /p' InvalidEvents.tmp
566#	@if test -s InvalidEvents.tmp; then exit 1; fi
567
568showliboptions:
569	@echo
570	@echo ---- Compile Time Library Options ----
571	@for i in $(LUFA_OPTS:-D%=%); do \
572		echo $$i; \
573	done
574	@echo --------------------------------------
575
576showtarget:
577	@echo
578	@echo --------- Target Information ---------
579	@echo AVR Model: $(MCU)
580	@echo Board:     $(BOARD)
581	@echo Clock:     $(F_CPU)Hz CPU, $(F_CLOCK)Hz Master
582	@echo --------------------------------------
583
584
585# Display compiler version information.
586gccversion :
587	@$(CC) --version
588
589
590# Program the device.
591program: $(TARGET).hex $(TARGET).eep
592	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
593
594flip: $(TARGET).hex
595	batchisp -hardware usb -device $(MCU_DFU) -operation erase f
596	batchisp -hardware usb -device $(MCU_DFU) -operation loadbuffer $(TARGET).hex program
597	batchisp -hardware usb -device $(MCU_DFU) -operation start reset 0
598
599dfu: $(TARGET).hex
600	dfu-programmer $(MCU_DFU) erase
601	dfu-programmer $(MCU_DFU) flash --debug 1 $(TARGET).hex
602	dfu-programmer $(MCU_DFU) reset
603
604
605flip-ee: $(TARGET).hex $(TARGET).eep
606	$(COPY) $(TARGET).eep $(TARGET)eep.hex
607	batchisp -hardware usb -device $(MCU_DFU) -operation memory EEPROM erase
608	batchisp -hardware usb -device $(MCU_DFU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
609	batchisp -hardware usb -device $(MCU_DFU) -operation start reset 0
610	$(REMOVE) $(TARGET)eep.hex
611
612dfu-ee: $(TARGET).hex $(TARGET).eep
613	dfu-programmer $(MCU_DFU) flash-eeprom --debug 1 --suppress-bootloader-mem $(TARGET).eep
614	dfu-programmer $(MCU_DFU) reset
615
616
617# Generate avr-gdb config/init file which does the following:
618#     define the reset signal, load the target file, connect to target, and set
619#     a breakpoint at main().
620gdb-config:
621	@$(REMOVE) $(GDBINIT_FILE)
622	@echo define reset >> $(GDBINIT_FILE)
623	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
624	@echo end >> $(GDBINIT_FILE)
625	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
626	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
627ifeq ($(DEBUG_BACKEND),simulavr)
628	@echo load  >> $(GDBINIT_FILE)
629endif
630	@echo break main >> $(GDBINIT_FILE)
631
632debug: gdb-config $(TARGET).elf
633ifeq ($(DEBUG_BACKEND), avarice)
634	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
635	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
636	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
637	@$(WINSHELL) /c pause
638
639else
640	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
641	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
642endif
643	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
644
645
646
647
648# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
649COFFCONVERT = $(OBJCOPY) --debugging
650COFFCONVERT += --change-section-address .data-0x800000
651COFFCONVERT += --change-section-address .bss-0x800000
652COFFCONVERT += --change-section-address .noinit-0x800000
653COFFCONVERT += --change-section-address .eeprom-0x810000
654
655
656
657coff: $(TARGET).elf
658	@echo
659	@echo $(MSG_COFF) $(TARGET).cof
660	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
661
662
663extcoff: $(TARGET).elf
664	@echo
665	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
666	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
667
668
669
670# Create final output files (.hex, .eep) from ELF output file.
671%.hex: %.elf
672	@echo
673	@echo $(MSG_FLASH) $@
674	$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@
675
676%.eep: %.elf
677	@echo
678	@echo $(MSG_EEPROM) $@
679	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
680	--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
681
682# Create extended listing file from ELF output file.
683%.lss: %.elf
684	@echo
685	@echo $(MSG_EXTENDED_LISTING) $@
686	$(OBJDUMP) -h -S -z $< > $@
687
688# Create a symbol table from ELF output file.
689%.sym: %.elf
690	@echo
691	@echo $(MSG_SYMBOL_TABLE) $@
692	$(NM) -n $< > $@
693
694
695
696# Create library from object files.
697.SECONDARY : $(TARGET).a
698.PRECIOUS : $(OBJ)
699%.a: $(OBJ)
700	@echo
701	@echo $(MSG_CREATING_LIBRARY) $@
702	$(AR) $@ $(OBJ)
703
704
705# Link: create ELF output file from object files.
706.SECONDARY : $(TARGET).elf
707.PRECIOUS : $(OBJ)
708%.elf: $(OBJ)
709	@echo
710	@echo $(MSG_LINKING) $@
711	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
712
713
714# Compile: create object files from C source files.
715$(OBJDIR)/%.o : %.c
716	@echo
717	@echo $(MSG_COMPILING) $<
718	$(CC) -c $(ALL_CFLAGS) $< -o $@
719
720
721# Compile: create object files from C++ source files.
722$(OBJDIR)/%.o : %.cpp
723	@echo
724	@echo $(MSG_COMPILING_CPP) $<
725	$(CC) -c $(ALL_CPPFLAGS) $< -o $@
726
727
728# Compile: create assembler files from C source files.
729%.s : %.c
730	$(CC) -S $(ALL_CFLAGS) $< -o $@
731
732
733# Compile: create assembler files from C++ source files.
734%.s : %.cpp
735	$(CC) -S $(ALL_CPPFLAGS) $< -o $@
736
737
738# Assemble: create object files from assembler source files.
739$(OBJDIR)/%.o : %.S
740	@echo
741	@echo $(MSG_ASSEMBLING) $<
742	$(CC) -c $(ALL_ASFLAGS) $< -o $@
743
744
745# Create preprocessed source for use in sending a bug report.
746%.i : %.c
747	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
748
749
750# Target: clean project.
751clean: begin clean_list clean_binary end
752
753clean_binary:
754	$(REMOVE) $(TARGET).hex
755
756clean_list:
757	@echo $(MSG_CLEANING)
758	$(REMOVE) $(TARGET).hex
759	$(REMOVE) $(TARGET).eep
760	$(REMOVE) $(TARGET).cof
761	$(REMOVE) $(TARGET).elf
762	$(REMOVE) $(TARGET).map
763	$(REMOVE) $(TARGET).sym
764	$(REMOVE) $(TARGET).lss
765	$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
766	$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
767	$(REMOVE) $(SRC:.c=.s)
768	$(REMOVE) $(SRC:.c=.d)
769	$(REMOVE) $(SRC:.c=.i)
770	$(REMOVEDIR) .dep
771
772doxygen:
773	@echo Generating Project Documentation...
774	@doxygen Doxygen.conf
775	@echo Documentation Generation Complete.
776
777clean_doxygen:
778	rm -rf Documentation
779
780# Create object files directory
781$(shell mkdir $(OBJDIR) 2>/dev/null)
782
783
784# Include the dependency files.
785-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
786
787
788# Listing of phony targets.
789.PHONY : all begin finish end sizebefore sizeafter gccversion \
790build elf hex eep lss sym coff extcoff doxygen clean          \
791clean_list clean_doxygen program dfu flip flip-ee dfu-ee      \
792debug gdb-config
793