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
)
15 COMMON_VPATH
+= $(DRIVER_PATH
)/avr
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
-std
=c
++11
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 # Autodetect teensy loader
91 ifndef TEENSY_LOADER_CLI
92 ifneq (, $(shell which teensy-loader-cli
2>/dev
/null
))
93 TEENSY_LOADER_CLI ?
= teensy-loader-cli
95 TEENSY_LOADER_CLI ?
= teensy_loader_cli
99 # Generate a .qmk for the QMK-FF
100 qmk
: $(BUILD_DIR
)/$(TARGET
).hex
101 zip
$(TARGET
).qmk
-FSrj
$(KEYMAP_PATH
)/*
102 zip
$(TARGET
).qmk
-u
$<
103 printf
"@ $<\n@=firmware.hex\n" | zipnote
-w
$(TARGET
).qmk
104 printf
"{\n \"generated\": \"%s\"\n}" "$$(date)" > $(BUILD_DIR
)/$(TARGET
).json
105 if
[ -f
$(KEYBOARD_PATH_5
)/info.json
]; then \
106 jq
-s
'.[0] * .[1]' $(BUILD_DIR
)/$(TARGET
).json
$(KEYBOARD_PATH_5
)/info.json | ex
-sc
'wq!$(BUILD_DIR)/$(TARGET).json' /dev
/stdin
; \
108 if
[ -f
$(KEYBOARD_PATH_4
)/info.json
]; then \
109 jq
-s
'.[0] * .[1]' $(BUILD_DIR
)/$(TARGET
).json
$(KEYBOARD_PATH_4
)/info.json | ex
-sc
'wq!$(BUILD_DIR)/$(TARGET).json' /dev
/stdin
; \
111 if
[ -f
$(KEYBOARD_PATH_3
)/info.json
]; then \
112 jq
-s
'.[0] * .[1]' $(BUILD_DIR
)/$(TARGET
).json
$(KEYBOARD_PATH_3
)/info.json | ex
-sc
'wq!$(BUILD_DIR)/$(TARGET).json' /dev
/stdin
; \
114 if
[ -f
$(KEYBOARD_PATH_2
)/info.json
]; then \
115 jq
-s
'.[0] * .[1]' $(BUILD_DIR
)/$(TARGET
).json
$(KEYBOARD_PATH_2
)/info.json | ex
-sc
'wq!$(BUILD_DIR)/$(TARGET).json' /dev
/stdin
; \
117 if
[ -f
$(KEYBOARD_PATH_1
)/info.json
]; then \
118 jq
-s
'.[0] * .[1]' $(BUILD_DIR
)/$(TARGET
).json
$(KEYBOARD_PATH_1
)/info.json | ex
-sc
'wq!$(BUILD_DIR)/$(TARGET).json' /dev
/stdin
; \
120 zip
$(TARGET
).qmk
-urj
$(BUILD_DIR
)/$(TARGET
).json
121 printf
"@ $(TARGET).json\n@=info.json\n" | zipnote
-w
$(TARGET
).qmk
123 # Program the device.
124 program
: $(BUILD_DIR
)/$(TARGET
).hex
$(BUILD_DIR
)/$(TARGET
).eep check-size
127 teensy
: $(BUILD_DIR
)/$(TARGET
).hex check-size cpfirmware
128 $(TEENSY_LOADER_CLI
) -mmcu
=$(MCU
) -w
-v
$(BUILD_DIR
)/$(TARGET
).hex
132 flip
: $(BUILD_DIR
)/$(TARGET
).hex check-size
133 $(BATCHISP
) -hardware usb
-device
$(MCU
) -operation erase f
134 $(BATCHISP
) -hardware usb
-device
$(MCU
) -operation loadbuffer
$(BUILD_DIR
)/$(TARGET
).hex program
135 $(BATCHISP
) -hardware usb
-device
$(MCU
) -operation start reset
0
137 DFU_PROGRAMMER ?
= dfu-programmer
140 dfu
: $(BUILD_DIR
)/$(TARGET
).hex cpfirmware check-size
141 until
$(DFU_PROGRAMMER
) $(MCU
) get bootloader-version
; do\
142 echo
"Error: Bootloader not found. Trying again in 5s." ;\
145 if
$(DFU_PROGRAMMER
) --version
2>&1 |
$(GREP
) -q
0.7 ; then\
146 $(DFU_PROGRAMMER
) $(MCU
) erase
--force;\
148 $(DFU_PROGRAMMER
) $(MCU
) erase
;\
150 $(DFU_PROGRAMMER
) $(MCU
) flash
$(BUILD_DIR
)/$(TARGET
).hex
151 $(DFU_PROGRAMMER
) $(MCU
) reset
154 $(DFU_PROGRAMMER
) $(MCU
) reset
155 $(DFU_PROGRAMMER
) $(MCU
) start
157 flip-ee
: $(BUILD_DIR
)/$(TARGET
).hex
$(BUILD_DIR
)/$(TARGET
).eep
158 $(COPY
) $(BUILD_DIR
)/$(TARGET
).eep
$(BUILD_DIR
)/$(TARGET
)eep.hex
159 $(BATCHISP
) -hardware usb
-device
$(MCU
) -operation memory EEPROM erase
160 $(BATCHISP
) -hardware usb
-device
$(MCU
) -operation memory EEPROM loadbuffer
$(BUILD_DIR
)/$(TARGET
)eep.hex program
161 $(BATCHISP
) -hardware usb
-device
$(MCU
) -operation start reset
0
162 $(REMOVE
) $(BUILD_DIR
)/$(TARGET
)eep.hex
164 dfu-ee
: $(BUILD_DIR
)/$(TARGET
).hex
$(BUILD_DIR
)/$(TARGET
).eep
165 if
$(DFU_PROGRAMMER
) --version
2>&1 |
$(GREP
) -q
0.7 ; then\
166 $(DFU_PROGRAMMER
) $(MCU
) flash
--eeprom
$(BUILD_DIR
)/$(TARGET
).eep
;\
168 $(DFU_PROGRAMMER
) $(MCU
) flash-eeprom
$(BUILD_DIR
)/$(TARGET
).eep
;\
170 $(DFU_PROGRAMMER
) $(MCU
) reset
172 avrdude
: $(BUILD_DIR
)/$(TARGET
).hex check-size cpfirmware
173 if
$(GREP
) -q
-s Microsoft
/proc
/version
; then \
174 echo
'ERROR: AVR flashing cannot be automated within the Windows Subsystem for Linux (WSL) currently. Instead, take the .hex file generated and flash it using AVRDUDE, AVRDUDESS, or XLoader.'; \
176 printf
"Detecting USB port, reset your controller now."; \
177 ls
/dev
/tty
* > /tmp
/1; \
178 while
[ -z
$$USB ]; do \
181 ls
/dev
/tty
* > /tmp
/2; \
182 USB
=`comm -13 /tmp/1 /tmp/2 | $(GREP) -o '/dev/tty.*'`; \
186 echo
"Detected controller on USB port at $$USB"; \
187 if
$(GREP
) -q
-s
'MINGW\|MSYS' /proc
/version
; then \
188 USB
=`echo "$$USB" | perl -pne 's/\/dev\/ttyS(\d+)/COM.($$1+1)/e'`; \
189 echo
"Remapped MSYS2 USB port to $$USB"; \
192 avrdude
-p
$(MCU
) -c avr109
-P
$$USB -U flash
:w
:$(BUILD_DIR
)/$(TARGET
).hex
; \
195 # Convert hex to bin.
196 bin
: $(BUILD_DIR
)/$(TARGET
).hex
197 $(OBJCOPY
) -Iihex
-Obinary
$(BUILD_DIR
)/$(TARGET
).hex
$(BUILD_DIR
)/$(TARGET
).bin
198 $(COPY
) $(BUILD_DIR
)/$(TARGET
).bin
$(TARGET
).bin
;
200 # copy bin to FLASH.bin
202 $(COPY
) $(BUILD_DIR
)/$(TARGET
).bin FLASH.bin
;
204 # Generate avr-gdb config/init file which does the following:
205 # define the reset signal, load the target file, connect to target, and set
206 # a breakpoint at main().
208 @
$(REMOVE
) $(GDBINIT_FILE
)
209 @echo
define reset
>> $(GDBINIT_FILE
)
210 @echo SIGNAL SIGHUP
>> $(GDBINIT_FILE
)
211 @echo end
>> $(GDBINIT_FILE
)
212 @echo file
$(BUILD_DIR
)/$(TARGET
).elf
>> $(GDBINIT_FILE
)
213 @echo target remote
$(DEBUG_HOST
):$(DEBUG_PORT
) >> $(GDBINIT_FILE
)
214 ifeq ($(DEBUG_BACKEND
),simulavr
)
215 @echo load
>> $(GDBINIT_FILE
)
217 @echo break main
>> $(GDBINIT_FILE
)
219 debug
: gdb-config
$(BUILD_DIR
)/$(TARGET
).elf
220 ifeq ($(DEBUG_BACKEND
), avarice
)
221 @echo Starting AVaRICE
- Press enter when
"waiting to connect" message displays.
222 @
$(WINSHELL
) /c start avarice
--jtag
$(JTAG_DEV
) --erase
--program
--file \
223 $(BUILD_DIR
)/$(TARGET
).elf
$(DEBUG_HOST
):$(DEBUG_PORT
)
224 @
$(WINSHELL
) /c pause
227 @
$(WINSHELL
) /c start simulavr
--gdbserver
--device
$(MCU
) --clock-freq \
228 $(DEBUG_MFREQ
) --port
$(DEBUG_PORT
)
230 @
$(WINSHELL
) /c start avr-
$(DEBUG_UI
) --command
=$(GDBINIT_FILE
)
235 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
236 COFFCONVERT
= $(OBJCOPY
) --debugging
237 COFFCONVERT
+= --change-section-address .data-0x800000
238 COFFCONVERT
+= --change-section-address .bss-0x800000
239 COFFCONVERT
+= --change-section-address .noinit-0x800000
240 COFFCONVERT
+= --change-section-address .eeprom-0x810000
244 coff
: $(BUILD_DIR
)/$(TARGET
).elf
245 @
$(SECHO
) $(MSG_COFF
) $(BUILD_DIR
)/$(TARGET
).cof
246 $(COFFCONVERT
) -O coff-avr
$< $(BUILD_DIR
)/$(TARGET
).cof
249 extcoff
: $(BUILD_DIR
)/$(TARGET
).elf
250 @
$(SECHO
) $(MSG_EXTENDED_COFF
) $(BUILD_DIR
)/$(TARGET
).cof
251 $(COFFCONVERT
) -O coff-ext-avr
$< $(BUILD_DIR
)/$(TARGET
).cof
254 make
-C lib
/lufa
/Bootloaders
/DFU
/ clean
255 echo
-e
"#ifndef QMK_KEYBOARD\n#define QMK_KEYBOARD\n" > lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
256 echo
-e
`$(GREP) "MANUFACTURER" $(ALL_CONFIGS) -h | tail -1` >> lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
257 echo
-e
`$(GREP) "PRODUCT" $(ALL_CONFIGS) -h | tail -1` Bootloader
>> lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
258 echo
-e
`$(GREP) "QMK_ESC_OUTPUT" $(ALL_CONFIGS) -h | tail -1` >> lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
259 echo
-e
`$(GREP) "QMK_ESC_INPUT" $(ALL_CONFIGS) -h | tail -1` >> lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
260 echo
-e
`$(GREP) "QMK_LED" $(ALL_CONFIGS) -h | tail -1` >> lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
261 echo
-e
`$(GREP) "QMK_SPEAKER" $(ALL_CONFIGS) -h | tail -1` >> lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
262 echo
-e
"\n#endif" >> lib
/lufa
/Bootloaders
/DFU
/Keyboard.h
263 make
-C lib
/lufa
/Bootloaders
/DFU
/
264 echo
-e
"BootloaderDFU.hex copied to $(TARGET)_bootloader.hex"
265 cp lib
/lufa
/Bootloaders
/DFU
/BootloaderDFU.hex
$(TARGET
)_bootloader.hex
267 production
: $(BUILD_DIR
)/$(TARGET
).hex bootloader cpfirmware
268 @cat
$(BUILD_DIR
)/$(TARGET
).hex | awk
'/^:00000001FF/ == 0' > $(TARGET
)_production.hex
269 @cat
$(TARGET
)_bootloader.hex
>> $(TARGET
)_production.hex
271 $(SIZE
) $(TARGET
).hex
$(TARGET
)_bootloader.hex
$(TARGET
)_production.hex