aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/avr.mk
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/avr.mk')
-rw-r--r--tmk_core/avr.mk179
1 files changed, 0 insertions, 179 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk
deleted file mode 100644
index c52262273..000000000
--- a/tmk_core/avr.mk
+++ /dev/null
@@ -1,179 +0,0 @@
1# Hey Emacs, this is a -*- makefile -*-
2##############################################################################
3# Compiler settings
4#
5CC = $(CC_PREFIX) avr-gcc
6OBJCOPY = avr-objcopy
7OBJDUMP = avr-objdump
8SIZE = avr-size
9AR = avr-ar
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)
13BIN =
14
15COMPILEFLAGS += -funsigned-char
16COMPILEFLAGS += -funsigned-bitfields
17COMPILEFLAGS += -ffunction-sections
18COMPILEFLAGS += -fdata-sections
19COMPILEFLAGS += -fpack-struct
20COMPILEFLAGS += -fshort-enums
21
22ASFLAGS += $(AVR_ASFLAGS)
23
24CFLAGS += $(COMPILEFLAGS) $(AVR_CFLAGS)
25CFLAGS += -fno-inline-small-functions
26CFLAGS += -fno-strict-aliasing
27
28CXXFLAGS += $(COMPILEFLAGS)
29CXXFLAGS += -fno-exceptions -std=c++11
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
91# Convert hex to bin.
92bin: $(BUILD_DIR)/$(TARGET).hex
93ifeq ($(BOOTLOADER),lufa-ms)
94 $(eval BIN_PADDING=$(shell n=`expr 32768 - $(BOOTLOADER_SIZE)` && echo $$(($$n)) || echo 0))
95 $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin --pad-to $(BIN_PADDING)
96else
97 $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
98endif
99 $(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
100
101# copy bin to FLASH.bin
102flashbin: bin
103 $(COPY) $(BUILD_DIR)/$(TARGET).bin FLASH.bin;
104
105# Generate avr-gdb config/init file which does the following:
106# define the reset signal, load the target file, connect to target, and set
107# a breakpoint at main().
108gdb-config:
109 @$(REMOVE) $(GDBINIT_FILE)
110 @echo define reset >> $(GDBINIT_FILE)
111 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
112 @echo end >> $(GDBINIT_FILE)
113 @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
114 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
115ifeq ($(DEBUG_BACKEND),simulavr)
116 @echo load >> $(GDBINIT_FILE)
117endif
118 @echo break main >> $(GDBINIT_FILE)
119
120debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
121ifeq ($(DEBUG_BACKEND), avarice)
122 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
123 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
124 $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
125 @$(WINSHELL) /c pause
126
127else
128 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
129 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
130endif
131 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
132
133
134
135
136# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
137COFFCONVERT = $(OBJCOPY) --debugging
138COFFCONVERT += --change-section-address .data-0x800000
139COFFCONVERT += --change-section-address .bss-0x800000
140COFFCONVERT += --change-section-address .noinit-0x800000
141COFFCONVERT += --change-section-address .eeprom-0x810000
142
143
144
145coff: $(BUILD_DIR)/$(TARGET).elf
146 @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
147 $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
148
149
150extcoff: $(BUILD_DIR)/$(TARGET).elf
151 @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
152 $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
153
154ifeq ($(strip $(BOOTLOADER)), qmk-dfu)
155QMK_BOOTLOADER_TYPE = DFU
156else ifeq ($(strip $(BOOTLOADER)), qmk-hid)
157QMK_BOOTLOADER_TYPE = HID
158endif
159
160bootloader:
161ifeq ($(strip $(QMK_BOOTLOADER_TYPE)),)
162 $(error Please set BOOTLOADER to "qmk-dfu" or "qmk-hid" first!)
163else
164 make -C lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/ clean
165 $(QMK_BIN) generate-dfu-header --quiet --keyboard $(KEYBOARD) --output lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/Keyboard.h
166 $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0))
167 $(eval PROGRAM_SIZE_KB=$(shell n=`expr $(MAX_SIZE) / 1024` && echo $$(($$n)) || echo 0))
168 $(eval BOOT_SECTION_SIZE_KB=$(shell n=`expr $(BOOTLOADER_SIZE) / 1024` && echo $$(($$n)) || echo 0))
169 $(eval FLASH_SIZE_KB=$(shell n=`expr $(PROGRAM_SIZE_KB) + $(BOOT_SECTION_SIZE_KB)` && echo $$(($$n)) || echo 0))
170 make -C lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/ MCU=$(MCU) ARCH=$(ARCH) F_CPU=$(F_CPU) FLASH_SIZE_KB=$(FLASH_SIZE_KB) BOOT_SECTION_SIZE_KB=$(BOOT_SECTION_SIZE_KB)
171 printf "Bootloader$(QMK_BOOTLOADER_TYPE).hex copied to $(TARGET)_bootloader.hex\n"
172 cp lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/Bootloader$(QMK_BOOTLOADER_TYPE).hex $(TARGET)_bootloader.hex
173endif
174
175production: $(BUILD_DIR)/$(TARGET).hex bootloader cpfirmware
176 @cat $(BUILD_DIR)/$(TARGET).hex | awk '/^:00000001FF/ == 0' > $(TARGET)_production.hex
177 @cat $(TARGET)_bootloader.hex >> $(TARGET)_production.hex
178 echo "File sizes:"
179 $(SIZE) $(TARGET).hex $(TARGET)_bootloader.hex $(TARGET)_production.hex