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