1 # Hey Emacs, this is a -*- makefile -*-
2 ##############################################################################
11 HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature
12 EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT)
17 COMPILEFLAGS += -funsigned-char
18 COMPILEFLAGS += -funsigned-bitfields
19 COMPILEFLAGS += -ffunction-sections
20 COMPILEFLAGS += -fdata-sections
21 COMPILEFLAGS += -fpack-struct
22 COMPILEFLAGS += -fshort-enums
24 CFLAGS += $(COMPILEFLAGS)
25 CFLAGS += -fno-inline-small-functions
26 CFLAGS += -fno-strict-aliasing
28 CPPFLAGS += $(COMPILEFLAGS)
29 CPPFLAGS += -fno-exceptions
31 LDFLAGS +=-Wl,--gc-sections
33 OPT_DEFS += -DF_CPU=$(F_CPU)UL
35 MCUFLAGS = -mmcu=$(MCU)
37 # List any extra directories to look for libraries here.
38 # Each directory must be seperated by a space.
39 # Use forward slashes for directory separators.
40 # For a directory that has spaces, enclose it in quotes.
44 #---------------- External Memory Options ----------------
46 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
47 # used for variables (.data/.bss) and heap (malloc()).
48 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
50 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
51 # only used for heap (malloc()).
52 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
56 #---------------- Debugging Options ----------------
59 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
60 # AVR Studio 4.10 requires dwarf-2.
61 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
64 # For simulavr only - target MCU frequency.
65 DEBUG_MFREQ = $(F_CPU)
67 # Set the DEBUG_UI to either gdb or insight.
71 # Set the debugging back-end to either avarice, simulavr.
72 DEBUG_BACKEND = avarice
73 #DEBUG_BACKEND = simulavr
76 GDBINIT_FILE = __avr_gdbinit
78 # When using avarice settings for the JTAG
81 # Debugging port used to communicate between GDB / avarice / simulavr.
84 # Debugging host used to communicate between GDB / avarice / simulavr, normally
85 # just set to localhost unless doing some sort of crazy debugging when
86 # avarice is running on a different computer.
87 DEBUG_HOST = localhost
89 #============================================================================
90 # Autodecct teensy loader
91 ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
92 TEENSY_LOADER_CLI = teensy-loader-cli
94 TEENSY_LOADER_CLI = teensy_loader_cli
98 program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
101 teensy: $(BUILD_DIR)/$(TARGET).hex
102 $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
104 flip: $(BUILD_DIR)/$(TARGET).hex
105 batchisp -hardware usb -device $(MCU) -operation erase f
106 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
107 batchisp -hardware usb -device $(MCU) -operation start reset 0
109 dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
110 ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
111 dfu-programmer $(MCU) erase --force
113 dfu-programmer $(MCU) erase
115 dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
116 dfu-programmer $(MCU) reset
119 dfu-programmer $(MCU) reset
120 dfu-programmer $(MCU) start
122 flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
123 $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
124 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
125 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
126 batchisp -hardware usb -device $(MCU) -operation start reset 0
127 $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
129 dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
130 ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
131 dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
133 dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
135 dfu-programmer $(MCU) reset
138 # Generate avr-gdb config/init file which does the following:
139 # define the reset signal, load the target file, connect to target, and set
140 # a breakpoint at main().
142 @$(REMOVE) $(GDBINIT_FILE)
143 @echo define reset >> $(GDBINIT_FILE)
144 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
145 @echo end >> $(GDBINIT_FILE)
146 @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
147 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
148 ifeq ($(DEBUG_BACKEND),simulavr)
149 @echo load >> $(GDBINIT_FILE)
151 @echo break main >> $(GDBINIT_FILE)
153 debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
154 ifeq ($(DEBUG_BACKEND), avarice)
155 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
156 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
157 $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
158 @$(WINSHELL) /c pause
161 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
162 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
164 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
169 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
170 COFFCONVERT = $(OBJCOPY) --debugging
171 COFFCONVERT += --change-section-address .data-0x800000
172 COFFCONVERT += --change-section-address .bss-0x800000
173 COFFCONVERT += --change-section-address .noinit-0x800000
174 COFFCONVERT += --change-section-address .eeprom-0x810000
178 coff: $(BUILD_DIR)/$(TARGET).elf
179 @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
180 $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
183 extcoff: $(BUILD_DIR)/$(TARGET).elf
184 @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
185 $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof