Merge pull request #1029 from SjB/qmk_infinity60
[jackhill/qmk/firmware.git] / tmk_core / avr.mk
CommitLineData
4d4f7684 1# Hey Emacs, this is a -*- makefile -*-
2##############################################################################
3# Compiler settings
4#
5CC = avr-gcc
6OBJCOPY = avr-objcopy
7OBJDUMP = avr-objdump
8SIZE = avr-size
9AR = avr-ar rcs
10NM = avr-nm
11HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature
12EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT)
f9a6e34c 13BIN =
4d4f7684 14
15
16
17COMPILEFLAGS += -funsigned-char
18COMPILEFLAGS += -funsigned-bitfields
19COMPILEFLAGS += -ffunction-sections
20COMPILEFLAGS += -fdata-sections
21COMPILEFLAGS += -fpack-struct
22COMPILEFLAGS += -fshort-enums
23
24CFLAGS += $(COMPILEFLAGS)
25CFLAGS += -fno-inline-small-functions
26CFLAGS += -fno-strict-aliasing
27
28CPPFLAGS += $(COMPILEFLAGS)
901f29e3 29CPPFLAGS += -fno-exceptions -std=c++11
4d4f7684 30
31LDFLAGS +=-Wl,--gc-sections
32
33OPT_DEFS += -DF_CPU=$(F_CPU)UL
34
35MCUFLAGS = -mmcu=$(MCU)
36
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.
41EXTRALIBDIRS =
42
43
44#---------------- External Memory Options ----------------
45
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
49
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
53
54EXTMEMOPTS =
55
56#---------------- Debugging Options ----------------
57
58# Debugging format.
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.
62DEBUG = dwarf-2
63
64# For simulavr only - target MCU frequency.
65DEBUG_MFREQ = $(F_CPU)
66
67# Set the DEBUG_UI to either gdb or insight.
68# DEBUG_UI = gdb
69DEBUG_UI = insight
70
71# Set the debugging back-end to either avarice, simulavr.
72DEBUG_BACKEND = avarice
73#DEBUG_BACKEND = simulavr
74
75# GDB Init Filename.
76GDBINIT_FILE = __avr_gdbinit
77
78# When using avarice settings for the JTAG
79JTAG_DEV = /dev/com1
80
81# Debugging port used to communicate between GDB / avarice / simulavr.
82DEBUG_PORT = 4242
83
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.
87DEBUG_HOST = localhost
88
89#============================================================================
90# Autodecct teensy loader
91ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
92 TEENSY_LOADER_CLI = teensy-loader-cli
93else
94 TEENSY_LOADER_CLI = teensy_loader_cli
95endif
96
97# Program the device.
98program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
99 $(PROGRAM_CMD)
100
101teensy: $(BUILD_DIR)/$(TARGET).hex
102 $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
103
104flip: $(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
108
109dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
0b8c448b
TLM
110 until dfu-programmer $(MCU) get bootloader-version; do\
111 echo "Error: Bootloader not found. Trying again in 5s." ;\
112 sleep 5 ;\
113 done
4d4f7684 114ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
115 dfu-programmer $(MCU) erase --force
116else
117 dfu-programmer $(MCU) erase
118endif
119 dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
120 dfu-programmer $(MCU) reset
121
122dfu-start:
123 dfu-programmer $(MCU) reset
124 dfu-programmer $(MCU) start
125
126flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
127 $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
128 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
129 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
130 batchisp -hardware usb -device $(MCU) -operation start reset 0
131 $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
132
133dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
134ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
135 dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
136else
137 dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
138endif
139 dfu-programmer $(MCU) reset
140
8fab141a 141# Convert hex to bin.
142flashbin: $(BUILD_DIR)/$(TARGET).hex
143 $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
144 $(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
145 $(COPY) $(BUILD_DIR)/$(TARGET).bin FLASH.bin;
4d4f7684 146
147# Generate avr-gdb config/init file which does the following:
148# define the reset signal, load the target file, connect to target, and set
149# a breakpoint at main().
150gdb-config:
151 @$(REMOVE) $(GDBINIT_FILE)
152 @echo define reset >> $(GDBINIT_FILE)
153 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
154 @echo end >> $(GDBINIT_FILE)
155 @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
156 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
157ifeq ($(DEBUG_BACKEND),simulavr)
158 @echo load >> $(GDBINIT_FILE)
159endif
160 @echo break main >> $(GDBINIT_FILE)
161
162debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
163ifeq ($(DEBUG_BACKEND), avarice)
164 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
165 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
166 $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
167 @$(WINSHELL) /c pause
168
169else
170 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
171 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
172endif
173 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
174
175
176
177
178# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
179COFFCONVERT = $(OBJCOPY) --debugging
180COFFCONVERT += --change-section-address .data-0x800000
181COFFCONVERT += --change-section-address .bss-0x800000
182COFFCONVERT += --change-section-address .noinit-0x800000
183COFFCONVERT += --change-section-address .eeprom-0x810000
184
185
186
187coff: $(BUILD_DIR)/$(TARGET).elf
188 @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
189 $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
190
191
192extcoff: $(BUILD_DIR)/$(TARGET).elf
193 @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
194 $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
195