diff options
author | Stefan Kerkmann <karlk90@pm.me> | 2021-10-18 07:23:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-18 16:23:20 +1100 |
commit | e50867d52d9c255570630a23514842749b45e4c1 (patch) | |
tree | e448e47262668e21084fb7439a38b0322136bb89 /tmk_core | |
parent | 7e3ff206b8600265ea086040b397f1a600c4a7f3 (diff) | |
download | qmk_firmware-e50867d52d9c255570630a23514842749b45e4c1.tar.gz qmk_firmware-e50867d52d9c255570630a23514842749b45e4c1.zip |
[Core] Add support for RISC-V builds and GD32VF103 MCU (#12508)
* Add support for RISC-V builds and GD32VF103 MCU
* Add toolchain selection in chibios.mk based on the mcu selected in
mcu_selection.mk
* Reorder and added comments to chibios.mk to have a streamlined makefile
* Add GD32VF103 mcu to possible targets for QMK.
* Add STM32 compatibility for GD32VF103 MCU, this is hacky but more efficent
then rewriting every driver.
* Add GigaDevice DFU bootloader as flash target, please note that
dfu-util of at least version 0.10 is needed.
* Add analog driver compatibility
* Add apa102 bitbang driver compatibility
* Add ws2812 bitbang driver compatibility
* Add eeprom in flash emulation compatibility
* Allow faster re-builds with ccache
* Add SiPeed Longan Nano to platform files
* Add SiPeed Longan Nano Onekeys
* Make quine compatible with other bootloaders
* Support builds with picolibc
* Add risc-v toolchain to arch and debian/ubuntu scripts
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/chibios.mk | 310 | ||||
-rw-r--r-- | tmk_core/common/chibios/bootloader.c | 22 | ||||
-rw-r--r-- | tmk_core/common/chibios/chibios_config.h | 19 | ||||
-rw-r--r-- | tmk_core/common/chibios/eeprom_stm32_defs.h | 6 | ||||
-rw-r--r-- | tmk_core/common/chibios/flash_stm32.c | 5 | ||||
-rw-r--r-- | tmk_core/common/chibios/gd32v_compatibility.h | 120 | ||||
-rw-r--r-- | tmk_core/common/chibios/syscall-fallbacks.c | 6 |
7 files changed, 377 insertions, 111 deletions
diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk index 18839710b..cae840fa4 100644 --- a/tmk_core/chibios.mk +++ b/tmk_core/chibios.mk | |||
@@ -27,29 +27,62 @@ endif | |||
27 | OPT_OS = chibios | 27 | OPT_OS = chibios |
28 | CHIBIOS = $(TOP_DIR)/lib/chibios | 28 | CHIBIOS = $(TOP_DIR)/lib/chibios |
29 | CHIBIOS_CONTRIB = $(TOP_DIR)/lib/chibios-contrib | 29 | CHIBIOS_CONTRIB = $(TOP_DIR)/lib/chibios-contrib |
30 | # Startup files. Try a few different locations, for compability with old versions and | 30 | |
31 | # for things hardware in the contrib repository | 31 | # |
32 | STARTUP_MK = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk | 32 | # Startup, Port and Platform support selection |
33 | ifeq ("$(wildcard $(STARTUP_MK))","") | 33 | ############################################################################## |
34 | STARTUP_MK = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk | 34 | |
35 | ifeq ("$(wildcard $(STARTUP_MK))","") | 35 | ifeq ($(strip $(MCU)), risc-v) |
36 | STARTUP_MK = $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk | 36 | # RISC-V Support |
37 | endif | 37 | # As of 7.4.2021 there is only one supported RISC-V platform in Chibios-Contrib, |
38 | # therefore all required settings are hard-coded | ||
39 | STARTUP_MK = $(CHIBIOS_CONTRIB)/os/common/startup/RISCV-ECLIC/compilers/GCC/mk/startup_$(MCU_STARTUP).mk | ||
40 | PORT_V = $(CHIBIOS_CONTRIB)/os/common/ports/RISCV-ECLIC/compilers/GCC/mk/port.mk | ||
41 | RULESPATH = $(CHIBIOS_CONTRIB)/os/common/startup/RISCV-ECLIC/compilers/GCC | ||
42 | PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/GD/GD32VF103/platform.mk | ||
43 | else | ||
44 | # ARM Support | ||
45 | # Startup files. Try a few different locations, for compability with old versions and | ||
46 | # for things hardware in the contrib repository | ||
47 | STARTUP_MK = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk | ||
48 | ifeq ("$(wildcard $(STARTUP_MK))","") | ||
49 | STARTUP_MK = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk | ||
50 | ifeq ("$(wildcard $(STARTUP_MK))","") | ||
51 | STARTUP_MK = $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk | ||
52 | endif | ||
53 | endif | ||
54 | |||
55 | # Compability with old version | ||
56 | PORT_V = $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk | ||
57 | ifeq ("$(wildcard $(PORT_V))","") | ||
58 | PORT_V = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk | ||
59 | endif | ||
60 | |||
61 | RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC | ||
62 | ifeq ("$(wildcard $(RULESPATH)/rules.mk)","") | ||
63 | RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC | ||
64 | endif | ||
38 | endif | 65 | endif |
39 | include $(STARTUP_MK) | ||
40 | # HAL-OSAL files (optional). | ||
41 | include $(CHIBIOS)/os/hal/hal.mk | ||
42 | 66 | ||
43 | ifeq ("$(PLATFORM_NAME)","") | 67 | ifeq ("$(PLATFORM_NAME)","") |
44 | PLATFORM_NAME = platform | 68 | PLATFORM_NAME = platform |
45 | endif | 69 | endif |
46 | 70 | ||
47 | PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk | ||
48 | ifeq ("$(wildcard $(PLATFORM_MK))","") | 71 | ifeq ("$(wildcard $(PLATFORM_MK))","") |
49 | PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk | 72 | PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk |
73 | ifeq ("$(wildcard $(PLATFORM_MK))","") | ||
74 | PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk | ||
75 | endif | ||
50 | endif | 76 | endif |
77 | |||
78 | include $(STARTUP_MK) | ||
79 | include $(PORT_V) | ||
51 | include $(PLATFORM_MK) | 80 | include $(PLATFORM_MK) |
52 | 81 | ||
82 | # | ||
83 | # Board support selection. | ||
84 | ############################################################################## | ||
85 | |||
53 | BOARD_MK := | 86 | BOARD_MK := |
54 | 87 | ||
55 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk)","") | 88 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk)","") |
@@ -77,13 +110,19 @@ else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/boards/$(BOARD)/board/board | |||
77 | endif | 110 | endif |
78 | 111 | ||
79 | ifeq ("$(wildcard $(BOARD_MK))","") | 112 | ifeq ("$(wildcard $(BOARD_MK))","") |
80 | BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk | 113 | BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk |
81 | ifeq ("$(wildcard $(BOARD_MK))","") | 114 | ifeq ("$(wildcard $(BOARD_MK))","") |
82 | BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk | 115 | BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk |
83 | endif | 116 | endif |
84 | endif | 117 | endif |
85 | 118 | ||
86 | # Bootloader address | 119 | include $(BOARD_MK) |
120 | |||
121 | # | ||
122 | # Bootloader selection. | ||
123 | ############################################################################## | ||
124 | |||
125 | # Set bootloader address if supplied. | ||
87 | ifdef STM32_BOOTLOADER_ADDRESS | 126 | ifdef STM32_BOOTLOADER_ADDRESS |
88 | OPT_DEFS += -DSTM32_BOOTLOADER_ADDRESS=$(STM32_BOOTLOADER_ADDRESS) | 127 | OPT_DEFS += -DSTM32_BOOTLOADER_ADDRESS=$(STM32_BOOTLOADER_ADDRESS) |
89 | endif | 128 | endif |
@@ -113,6 +152,10 @@ else ifneq ("$(wildcard $(BOARD_PATH)/configs/bootloader_defs.h)","") | |||
113 | OPT_DEFS += -include $(BOARD_PATH)/configs/bootloader_defs.h | 152 | OPT_DEFS += -include $(BOARD_PATH)/configs/bootloader_defs.h |
114 | endif | 153 | endif |
115 | 154 | ||
155 | # | ||
156 | # ChibiOS config selection. | ||
157 | ############################################################################## | ||
158 | |||
116 | # Work out the config file directories | 159 | # Work out the config file directories |
117 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/chconf.h)","") | 160 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/chconf.h)","") |
118 | CHCONFDIR = $(KEYBOARD_PATH_5) | 161 | CHCONFDIR = $(KEYBOARD_PATH_5) |
@@ -130,6 +173,10 @@ else ifneq ("$(wildcard $(TOP_DIR)/platforms/boards/chibios/common/configs/chcon | |||
130 | CHCONFDIR = $(TOP_DIR)/platforms/chibios/boards/common/configs | 173 | CHCONFDIR = $(TOP_DIR)/platforms/chibios/boards/common/configs |
131 | endif | 174 | endif |
132 | 175 | ||
176 | # | ||
177 | # HAL config selection. | ||
178 | ############################################################################## | ||
179 | |||
133 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/halconf.h)","") | 180 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/halconf.h)","") |
134 | HALCONFDIR = $(KEYBOARD_PATH_5) | 181 | HALCONFDIR = $(KEYBOARD_PATH_5) |
135 | else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/halconf.h)","") | 182 | else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/halconf.h)","") |
@@ -146,40 +193,10 @@ else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/boards/common/configs/halco | |||
146 | HALCONFDIR = $(TOP_DIR)/platforms/chibios/boards/common/configs | 193 | HALCONFDIR = $(TOP_DIR)/platforms/chibios/boards/common/configs |
147 | endif | 194 | endif |
148 | 195 | ||
149 | # HAL-OSAL files (optional). | 196 | # |
150 | include $(CHIBIOS)/os/hal/hal.mk | 197 | # Linker script selection. |
151 | 198 | ############################################################################## | |
152 | ifeq ("$(PLATFORM_NAME)","") | ||
153 | PLATFORM_NAME = platform | ||
154 | endif | ||
155 | |||
156 | PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk | ||
157 | ifeq ("$(wildcard $(PLATFORM_MK))","") | ||
158 | PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk | ||
159 | endif | ||
160 | include $(PLATFORM_MK) | ||
161 | |||
162 | |||
163 | include $(BOARD_MK) | ||
164 | -include $(CHIBIOS)/os/hal/osal/rt/osal.mk # ChibiOS <= 19.x | ||
165 | -include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk # ChibiOS >= 20.x | ||
166 | # RTOS files (optional). | ||
167 | include $(CHIBIOS)/os/rt/rt.mk | ||
168 | # Compability with old version | ||
169 | PORT_V = $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk | ||
170 | ifeq ("$(wildcard $(PORT_V))","") | ||
171 | PORT_V = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk | ||
172 | endif | ||
173 | include $(PORT_V) | ||
174 | # Other files (optional). | ||
175 | include $(CHIBIOS)/os/hal/lib/streams/streams.mk | ||
176 | |||
177 | RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC | ||
178 | ifeq ("$(wildcard $(RULESPATH)/rules.mk)","") | ||
179 | RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC | ||
180 | endif | ||
181 | 199 | ||
182 | # Define linker script file here | ||
183 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/ld/$(MCU_LDSCRIPT).ld)","") | 200 | ifneq ("$(wildcard $(KEYBOARD_PATH_5)/ld/$(MCU_LDSCRIPT).ld)","") |
184 | LDSCRIPT = $(KEYBOARD_PATH_5)/ld/$(MCU_LDSCRIPT).ld | 201 | LDSCRIPT = $(KEYBOARD_PATH_5)/ld/$(MCU_LDSCRIPT).ld |
185 | else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/ld/$(MCU_LDSCRIPT).ld)","") | 202 | else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/ld/$(MCU_LDSCRIPT).ld)","") |
@@ -202,17 +219,30 @@ else | |||
202 | LDSCRIPT = $(STARTUPLD)/$(MCU_LDSCRIPT).ld | 219 | LDSCRIPT = $(STARTUPLD)/$(MCU_LDSCRIPT).ld |
203 | endif | 220 | endif |
204 | 221 | ||
222 | # | ||
223 | # Include ChibiOS makefiles. | ||
224 | ############################################################################## | ||
225 | |||
226 | # HAL-OSAL files (optional). | ||
227 | include $(CHIBIOS)/os/hal/hal.mk | ||
228 | -include $(CHIBIOS)/os/hal/osal/rt/osal.mk # ChibiOS <= 19.x | ||
229 | -include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk # ChibiOS >= 20.x | ||
230 | # RTOS files (optional). | ||
231 | include $(CHIBIOS)/os/rt/rt.mk | ||
232 | # Other files (optional). | ||
233 | include $(CHIBIOS)/os/hal/lib/streams/streams.mk | ||
234 | |||
205 | CHIBISRC = $(STARTUPSRC) \ | 235 | CHIBISRC = $(STARTUPSRC) \ |
206 | $(KERNSRC) \ | 236 | $(KERNSRC) \ |
207 | $(PORTSRC) \ | 237 | $(PORTSRC) \ |
208 | $(OSALSRC) \ | 238 | $(OSALSRC) \ |
209 | $(HALSRC) \ | 239 | $(HALSRC) \ |
210 | $(PLATFORMSRC) \ | 240 | $(PLATFORMSRC) \ |
211 | $(BOARDSRC) \ | 241 | $(BOARDSRC) \ |
212 | $(STREAMSSRC) \ | 242 | $(STREAMSSRC) \ |
213 | $(CHIBIOS)/os/various/syscalls.c \ | 243 | $(CHIBIOS)/os/various/syscalls.c \ |
214 | $(PLATFORM_COMMON_DIR)/syscall-fallbacks.c \ | 244 | $(PLATFORM_COMMON_DIR)/syscall-fallbacks.c \ |
215 | $(PLATFORM_COMMON_DIR)/wait.c | 245 | $(PLATFORM_COMMON_DIR)/wait.c |
216 | 246 | ||
217 | # Ensure the ASM files are not subjected to LTO -- it'll strip out interrupt handlers otherwise. | 247 | # Ensure the ASM files are not subjected to LTO -- it'll strip out interrupt handlers otherwise. |
218 | QUANTUM_LIB_SRC += $(STARTUPASM) $(PORTASM) $(OSALASM) $(PLATFORMASM) | 248 | QUANTUM_LIB_SRC += $(STARTUPASM) $(PORTASM) $(OSALASM) $(PLATFORMASM) |
@@ -247,9 +277,9 @@ else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/boards/$(BOARD)/configs/hal | |||
247 | endif | 277 | endif |
248 | 278 | ||
249 | ifeq ($(strip $(USE_CHIBIOS_CONTRIB)),yes) | 279 | ifeq ($(strip $(USE_CHIBIOS_CONTRIB)),yes) |
250 | include $(CHIBIOS_CONTRIB)/os/hal/hal.mk | 280 | include $(CHIBIOS_CONTRIB)/os/hal/hal.mk |
251 | CHIBISRC += $(PLATFORMSRC_CONTRIB) $(HALSRC_CONTRIB) | 281 | CHIBISRC += $(PLATFORMSRC_CONTRIB) $(HALSRC_CONTRIB) |
252 | EXTRAINCDIRS += $(PLATFORMINC_CONTRIB) $(HALINC_CONTRIB) $(CHIBIOS_CONTRIB)/os/various | 282 | EXTRAINCDIRS += $(PLATFORMINC_CONTRIB) $(HALINC_CONTRIB) $(CHIBIOS_CONTRIB)/os/various |
253 | endif | 283 | endif |
254 | 284 | ||
255 | # | 285 | # |
@@ -267,61 +297,123 @@ ifneq ("$(wildcard $(BOARD_PATH)/configs/post_config.h)","") | |||
267 | endif | 297 | endif |
268 | 298 | ||
269 | ############################################################################## | 299 | ############################################################################## |
270 | # Compiler settings | 300 | # Compiler and Linker configuration |
271 | # | 301 | # |
272 | CC = arm-none-eabi-gcc | 302 | |
273 | OBJCOPY = arm-none-eabi-objcopy | 303 | # Use defined stack sizes of the main thread in linker scripts |
274 | OBJDUMP = arm-none-eabi-objdump | 304 | LDSYMBOLS =--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE) |
275 | SIZE = arm-none-eabi-size | 305 | |
276 | AR = arm-none-eabi-ar | 306 | # Shared Compiler flags for all toolchains |
277 | NM = arm-none-eabi-nm | 307 | SHARED_CFLAGS = -fomit-frame-pointer \ |
278 | HEX = $(OBJCOPY) -O $(FORMAT) | 308 | -ffunction-sections \ |
279 | EEP = | 309 | -fdata-sections \ |
280 | BIN = $(OBJCOPY) -O binary | 310 | -fno-common \ |
281 | 311 | -fshort-wchar | |
282 | THUMBFLAGS = -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb -DTHUMB | 312 | |
283 | 313 | # Shared Linker flags for all toolchains | |
284 | COMPILEFLAGS += -fomit-frame-pointer | 314 | SHARED_LDFLAGS = -T $(LDSCRIPT) \ |
285 | COMPILEFLAGS += -falign-functions=16 | 315 | -Wl,$(LDSYMBOLS) \ |
286 | COMPILEFLAGS += -ffunction-sections | 316 | -Wl,--gc-sections \ |
287 | COMPILEFLAGS += -fdata-sections | 317 | -nostartfiles |
288 | COMPILEFLAGS += -fno-common | 318 | |
289 | COMPILEFLAGS += -fshort-wchar | 319 | ifeq ($(strip $(MCU)), risc-v) |
290 | COMPILEFLAGS += $(THUMBFLAGS) | 320 | # RISC-V toolchain specific configuration |
291 | 321 | # Find suitable GCC compiler | |
292 | # FPU options default (Cortex-M4 and Cortex-M7 single precision). | 322 | ifeq ($(strip $(TOOLCHAIN)),) |
293 | USE_FPU_OPT ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant | 323 | ifneq ($(shell which riscv32-unknown-elf-gcc 2>/dev/null),) |
294 | 324 | TOOLCHAIN = riscv32-unknown-elf- | |
295 | # FPU-related options | 325 | else |
296 | USE_FPU ?= no | 326 | ifneq ($(shell which riscv64-unknown-elf-gcc 2>/dev/null),) |
297 | ifneq ($(USE_FPU),no) | 327 | TOOLCHAIN = riscv64-unknown-elf- |
298 | COMPILEFLAGS += $(USE_FPU_OPT) | 328 | else |
299 | OPT_DEFS += -DCORTEX_USE_FPU=TRUE | 329 | $(error "No RISC-V toolchain found. Can't find riscv32-unknown-elf-gcc or riscv64-unknown-elf-gcc found in your systems PATH variable. Please install a valid toolchain and make it accessible!") |
330 | endif | ||
331 | endif | ||
332 | endif | ||
333 | |||
334 | # Default to compiling with picolibc for RISC-V targets if available, | ||
335 | # which is available by default on current (bullseye) debian based systems. | ||
336 | ifeq ($(shell $(TOOLCHAIN)gcc --specs=picolibc.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) | ||
337 | # Toolchain specific Compiler flags | ||
338 | # Note that we still link with our own linker script | ||
339 | # by providing it via the -T flag above. | ||
340 | TOOLCHAIN_CFLAGS = --specs=picolibc.specs | ||
341 | |||
342 | # Tell QMK that we are compiling with picolibc. | ||
343 | OPT_DEFS += -DUSE_PICOLIBC | ||
344 | endif | ||
345 | |||
346 | # MCU architecture flags | ||
347 | MCUFLAGS = -march=$(MCU_ARCH) \ | ||
348 | -mabi=$(MCU_ABI) \ | ||
349 | -mcmodel=$(MCU_CMODEL) \ | ||
350 | -mstrict-align | ||
300 | else | 351 | else |
301 | OPT_DEFS += -DCORTEX_USE_FPU=FALSE | 352 | # ARM toolchain specific configuration |
353 | TOOLCHAIN ?= arm-none-eabi- | ||
354 | |||
355 | # Toolchain specific Linker flags | ||
356 | TOOLCHAIN_LDFLAGS = -Wl,--no-wchar-size-warning \ | ||
357 | --specs=nano.specs | ||
358 | |||
359 | # MCU architecture flags | ||
360 | MCUFLAGS = -mcpu=$(MCU) \ | ||
361 | -mthumb -DTHUMB_PRESENT \ | ||
362 | -mno-thumb-interwork -DTHUMB_NO_INTERWORKING \ | ||
363 | -mno-unaligned-access | ||
364 | |||
365 | # Some ARM cores like the M4 and M7 have floating point units which can be enabled | ||
366 | USE_FPU ?= no | ||
367 | |||
368 | ifneq ($(USE_FPU),no) | ||
369 | OPT_DEFS += -DCORTEX_USE_FPU=TRUE | ||
370 | |||
371 | # Default is single precision floats | ||
372 | USE_FPU_OPT ?= -mfloat-abi=hard \ | ||
373 | -mfpu=fpv4-sp-d16 \ | ||
374 | -fsingle-precision-constant | ||
375 | |||
376 | MCUFLAGS += $(USE_FPU_OPT) | ||
377 | else | ||
378 | OPT_DEFS += -DCORTEX_USE_FPU=FALSE | ||
379 | endif | ||
302 | endif | 380 | endif |
303 | 381 | ||
304 | CFLAGS += $(COMPILEFLAGS) | 382 | # Assembler flags |
383 | ASFLAGS += $(SHARED_ASFLAGS) $(TOOLCHAIN_ASFLAGS) | ||
305 | 384 | ||
306 | ASFLAGS += $(THUMBFLAGS) | 385 | # C Compiler flags |
386 | CFLAGS += $(SHARED_CFLAGS) $(TOOLCHAIN_CFLAGS) | ||
307 | 387 | ||
308 | CXXFLAGS += $(COMPILEFLAGS) | 388 | # C++ Compiler flags |
309 | CXXFLAGS += -fno-rtti | 389 | CXXFLAGS += $(CFLAGS) $(SHARED_CXXFLAGS) $(TOOLCHAIN_CXXFLAGS) -fno-rtti |
310 | 390 | ||
311 | LDFLAGS +=-Wl,--gc-sections | 391 | # Linker flags |
312 | LDFLAGS +=-Wl,--no-wchar-size-warning | 392 | LDFLAGS += $(SHARED_LDFLAGS) $(TOOLCHAIN_LDFLAGS) $(MCUFLAGS) |
313 | LDFLAGS += -mno-thumb-interwork -mthumb | ||
314 | LDSYMBOLS =,--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE) | ||
315 | LDSYMBOLS :=$(LDSYMBOLS),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE) | ||
316 | LDFLAGS += -Wl,--script=$(LDSCRIPT)$(LDSYMBOLS) | ||
317 | LDFLAGS += --specs=nano.specs | ||
318 | 393 | ||
394 | # Tell QMK that we are hosting it on ChibiOS. | ||
319 | OPT_DEFS += -DPROTOCOL_CHIBIOS | 395 | OPT_DEFS += -DPROTOCOL_CHIBIOS |
320 | 396 | ||
321 | # Workaround to stop ChibiOS from complaining about new GCC -- it's been fixed for 7/8/9 already | 397 | # Speed up recompilations by opt-in usage of ccache |
322 | OPT_DEFS += -DPORT_IGNORE_GCC_VERSION_CHECK=1 | 398 | USE_CCACHE ?= no |
399 | ifneq ($(USE_CCACHE),no) | ||
400 | CC_PREFIX ?= ccache | ||
401 | endif | ||
402 | |||
403 | # Construct GCC toolchain | ||
404 | CC = $(CC_PREFIX) $(TOOLCHAIN)gcc | ||
405 | OBJCOPY = $(TOOLCHAIN)objcopy | ||
406 | OBJDUMP = $(TOOLCHAIN)objdump | ||
407 | SIZE = $(TOOLCHAIN)size | ||
408 | AR = $(TOOLCHAIN)ar | ||
409 | NM = $(TOOLCHAIN)nm | ||
410 | HEX = $(OBJCOPY) -O $(FORMAT) | ||
411 | EEP = | ||
412 | BIN = $(OBJCOPY) -O binary | ||
323 | 413 | ||
324 | MCUFLAGS = -mcpu=$(MCU) | 414 | ############################################################################## |
415 | # Make targets | ||
416 | # | ||
325 | 417 | ||
326 | DEBUG = gdb | 418 | DEBUG = gdb |
327 | 419 | ||
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c index f9514ee5f..5cadadeee 100644 --- a/tmk_core/common/chibios/bootloader.c +++ b/tmk_core/common/chibios/bootloader.c | |||
@@ -95,6 +95,28 @@ void enter_bootloader_mode_if_requested(void) { | |||
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | #elif defined(GD32VF103) | ||
99 | |||
100 | # define DBGMCU_KEY_UNLOCK 0x4B5A6978 | ||
101 | # define DBGMCU_CMD_RESET 0x1 | ||
102 | |||
103 | __IO uint32_t *DBGMCU_KEY = (uint32_t *)DBGMCU_BASE + 0x0CU; | ||
104 | __IO uint32_t *DBGMCU_CMD = (uint32_t *)DBGMCU_BASE + 0x08U; | ||
105 | |||
106 | __attribute__((weak)) void bootloader_jump(void) { | ||
107 | /* The MTIMER unit of the GD32VF103 doesn't have the MSFRST | ||
108 | * register to generate a software reset request. | ||
109 | * BUT instead two undocumented registers in the debug peripheral | ||
110 | * that allow issueing a software reset. WHO would need the MSFRST | ||
111 | * register anyway? Source: | ||
112 | * https://github.com/esmil/gd32vf103inator/blob/master/include/gd32vf103/dbg.h */ | ||
113 | *DBGMCU_KEY = DBGMCU_KEY_UNLOCK; | ||
114 | *DBGMCU_CMD = DBGMCU_CMD_RESET; | ||
115 | } | ||
116 | |||
117 | void enter_bootloader_mode_if_requested(void) { /* Jumping to bootloader is not possible from user code. */ | ||
118 | } | ||
119 | |||
98 | #elif defined(KL2x) || defined(K20x) || defined(MK66F18) || defined(MIMXRT1062) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS | 120 | #elif defined(KL2x) || defined(K20x) || defined(MK66F18) || defined(MIMXRT1062) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS |
99 | /* Kinetis */ | 121 | /* Kinetis */ |
100 | 122 | ||
diff --git a/tmk_core/common/chibios/chibios_config.h b/tmk_core/common/chibios/chibios_config.h index f06594802..ad2f808a9 100644 --- a/tmk_core/common/chibios/chibios_config.h +++ b/tmk_core/common/chibios/chibios_config.h | |||
@@ -39,6 +39,25 @@ | |||
39 | # endif | 39 | # endif |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | // GD32 compatibility | ||
43 | #if defined(MCU_GD32V) | ||
44 | # define CPU_CLOCK GD32_SYSCLK | ||
45 | |||
46 | # if defined(GD32VF103) | ||
47 | # define USE_GPIOV1 | ||
48 | # define USE_I2CV1 | ||
49 | # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_GD32_ALTERNATE_OPENDRAIN | ||
50 | # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_GD32_ALTERNATE_PUSHPULL | ||
51 | # endif | ||
52 | #endif | ||
53 | |||
54 | #if defined(GD32VF103) | ||
55 | /* This chip has the same API as STM32F103, but uses different names for literally the same thing. | ||
56 | * As of 4.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake | ||
57 | * we just redefine the GD32 names. */ | ||
58 | # include "gd32v_compatibility.h" | ||
59 | #endif | ||
60 | |||
42 | // teensy compatibility | 61 | // teensy compatibility |
43 | #if defined(MCU_KINETIS) | 62 | #if defined(MCU_KINETIS) |
44 | # define CPU_CLOCK KINETIS_SYSCLK_FREQUENCY | 63 | # define CPU_CLOCK KINETIS_SYSCLK_FREQUENCY |
diff --git a/tmk_core/common/chibios/eeprom_stm32_defs.h b/tmk_core/common/chibios/eeprom_stm32_defs.h index 349979626..66904f247 100644 --- a/tmk_core/common/chibios/eeprom_stm32_defs.h +++ b/tmk_core/common/chibios/eeprom_stm32_defs.h | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <hal.h> | 18 | #include <hal.h> |
19 | 19 | ||
20 | #if !defined(FEE_PAGE_SIZE) || !defined(FEE_PAGE_COUNT) | 20 | #if !defined(FEE_PAGE_SIZE) || !defined(FEE_PAGE_COUNT) |
21 | # if defined(STM32F103xB) || defined(STM32F042x6) | 21 | # if defined(STM32F103xB) || defined(STM32F042x6) || defined(GD32VF103C8) || defined(GD32VF103CB) |
22 | # ifndef FEE_PAGE_SIZE | 22 | # ifndef FEE_PAGE_SIZE |
23 | # define FEE_PAGE_SIZE 0x400 // Page size = 1KByte | 23 | # define FEE_PAGE_SIZE 0x400 // Page size = 1KByte |
24 | # endif | 24 | # endif |
@@ -45,7 +45,9 @@ | |||
45 | #if !defined(FEE_MCU_FLASH_SIZE) | 45 | #if !defined(FEE_MCU_FLASH_SIZE) |
46 | # if defined(STM32F042x6) | 46 | # if defined(STM32F042x6) |
47 | # define FEE_MCU_FLASH_SIZE 32 // Size in Kb | 47 | # define FEE_MCU_FLASH_SIZE 32 // Size in Kb |
48 | # elif defined(STM32F103xB) || defined(STM32F072xB) || defined(STM32F070xB) | 48 | # elif defined(GD32VF103C8) |
49 | # define FEE_MCU_FLASH_SIZE 64 // Size in Kb | ||
50 | # elif defined(STM32F103xB) || defined(STM32F072xB) || defined(STM32F070xB) || defined(GD32VF103CB) | ||
49 | # define FEE_MCU_FLASH_SIZE 128 // Size in Kb | 51 | # define FEE_MCU_FLASH_SIZE 128 // Size in Kb |
50 | # elif defined(STM32F303xC) || defined(STM32F401xC) | 52 | # elif defined(STM32F303xC) || defined(STM32F401xC) |
51 | # define FEE_MCU_FLASH_SIZE 256 // Size in Kb | 53 | # define FEE_MCU_FLASH_SIZE 256 // Size in Kb |
diff --git a/tmk_core/common/chibios/flash_stm32.c b/tmk_core/common/chibios/flash_stm32.c index 35fb0eebd..72c41b8b7 100644 --- a/tmk_core/common/chibios/flash_stm32.c +++ b/tmk_core/common/chibios/flash_stm32.c | |||
@@ -23,6 +23,11 @@ | |||
23 | # define FLASH_SR_WRPERR FLASH_SR_WRPRTERR | 23 | # define FLASH_SR_WRPERR FLASH_SR_WRPRTERR |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #if defined(MCU_GD32V) | ||
27 | /* GigaDevice GD32VF103 is a STM32F103 clone at heart. */ | ||
28 | # include "gd32v_compatibility.h" | ||
29 | #endif | ||
30 | |||
26 | #if defined(STM32F4XX) | 31 | #if defined(STM32F4XX) |
27 | # define FLASH_SR_PGERR (FLASH_SR_PGSERR | FLASH_SR_PGPERR | FLASH_SR_PGAERR) | 32 | # define FLASH_SR_PGERR (FLASH_SR_PGSERR | FLASH_SR_PGPERR | FLASH_SR_PGAERR) |
28 | 33 | ||
diff --git a/tmk_core/common/chibios/gd32v_compatibility.h b/tmk_core/common/chibios/gd32v_compatibility.h new file mode 100644 index 000000000..f4dcfd8c5 --- /dev/null +++ b/tmk_core/common/chibios/gd32v_compatibility.h | |||
@@ -0,0 +1,120 @@ | |||
1 | /* Copyright 2021 QMK | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | /* GD32VF103 has the same API as STM32F103, but uses different names for literally the same thing. | ||
20 | * As of 23.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake | ||
21 | * we just redefine the GD32 names. */ | ||
22 | |||
23 | /* Close your eyes kids. */ | ||
24 | #define MCU_STM32 | ||
25 | |||
26 | /* AFIO redefines */ | ||
27 | #define MAPR PCF0 | ||
28 | #define AFIO_MAPR_USART1_REMAP AFIO_PCF0_USART0_REMAP | ||
29 | #define AFIO_MAPR_USART2_REMAP AFIO_PCF0_USART1_REMAP | ||
30 | #define AFIO_MAPR_USART3_REMAP_PARTIALREMAP AFIO_PCF0_USART2_REMAP_PARTIALREMAP | ||
31 | #define AFIO_MAPR_USART3_REMAP_FULLREMAP AFIO_PCF0_USART2_REMAP_FULLREMAP | ||
32 | |||
33 | /* DMA redefines. */ | ||
34 | #define STM32_DMA_STREAM(stream) GD32_DMA_STREAM(stream) | ||
35 | #define STM32_DMA_STREAM_ID(peripheral, channel) GD32_DMA_STREAM_ID(peripheral - 1, channel - 1) | ||
36 | #define STM32_DMA_CR_DIR_M2P GD32_DMA_CTL_DIR_M2P | ||
37 | #define STM32_DMA_CR_PSIZE_WORD GD32_DMA_CTL_PWIDTH_WORD | ||
38 | #define STM32_DMA_CR_MSIZE_WORD GD32_DMA_CTL_MWIDTH_WORD | ||
39 | #define STM32_DMA_CR_MINC GD32_DMA_CTL_MNAGA | ||
40 | #define STM32_DMA_CR_CIRC GD32_DMA_CTL_CMEN | ||
41 | #define STM32_DMA_CR_PL GD32_DMA_CTL_PRIO | ||
42 | #define STM32_DMA_CR_CHSEL GD32_DMA_CTL_CHSEL | ||
43 | #define cr1 ctl0 | ||
44 | #define cr2 ctl1 | ||
45 | #define cr3 ctl2 | ||
46 | #define dier dmainten | ||
47 | |||
48 | /* ADC redefines */ | ||
49 | #if HAL_USE_ADC | ||
50 | # define STM32_ADC_USE_ADC1 GD32_ADC_USE_ADC0 | ||
51 | |||
52 | # define smpr1 sampt0 | ||
53 | # define smpr2 sampt1 | ||
54 | # define sqr1 rsq0 | ||
55 | # define sqr2 rsq1 | ||
56 | # define sqr3 rsq2 | ||
57 | |||
58 | # define ADC_SMPR2_SMP_AN0 ADC_SAMPT1_SMP_SPT0 | ||
59 | # define ADC_SMPR2_SMP_AN1 ADC_SAMPT1_SMP_SPT1 | ||
60 | # define ADC_SMPR2_SMP_AN2 ADC_SAMPT1_SMP_SPT2 | ||
61 | # define ADC_SMPR2_SMP_AN3 ADC_SAMPT1_SMP_SPT3 | ||
62 | # define ADC_SMPR2_SMP_AN4 ADC_SAMPT1_SMP_SPT4 | ||
63 | # define ADC_SMPR2_SMP_AN5 ADC_SAMPT1_SMP_SPT5 | ||
64 | # define ADC_SMPR2_SMP_AN6 ADC_SAMPT1_SMP_SPT6 | ||
65 | # define ADC_SMPR2_SMP_AN7 ADC_SAMPT1_SMP_SPT7 | ||
66 | # define ADC_SMPR2_SMP_AN8 ADC_SAMPT1_SMP_SPT8 | ||
67 | # define ADC_SMPR2_SMP_AN9 ADC_SAMPT1_SMP_SPT9 | ||
68 | |||
69 | # define ADC_SMPR1_SMP_AN10 ADC_SAMPT0_SMP_SPT10 | ||
70 | # define ADC_SMPR1_SMP_AN11 ADC_SAMPT0_SMP_SPT11 | ||
71 | # define ADC_SMPR1_SMP_AN12 ADC_SAMPT0_SMP_SPT12 | ||
72 | # define ADC_SMPR1_SMP_AN13 ADC_SAMPT0_SMP_SPT13 | ||
73 | # define ADC_SMPR1_SMP_AN14 ADC_SAMPT0_SMP_SPT14 | ||
74 | # define ADC_SMPR1_SMP_AN15 ADC_SAMPT0_SMP_SPT15 | ||
75 | |||
76 | # define ADC_SQR3_SQ1_N ADC_RSQ2_RSQ1_N | ||
77 | #endif | ||
78 | |||
79 | /* FLASH redefines */ | ||
80 | #if defined(EEPROM_ENABLE) | ||
81 | # define SR STAT | ||
82 | # define FLASH_SR_BSY FLASH_STAT_BUSY | ||
83 | # define FLASH_SR_PGERR FLASH_STAT_PGERR | ||
84 | # define FLASH_SR_EOP FLASH_STAT_ENDF | ||
85 | # define FLASH_SR_WRPRTERR FLASH_STAT_WPERR | ||
86 | # define FLASH_SR_WRPERR FLASH_SR_WRPRTERR | ||
87 | # define FLASH_OBR_OPTERR FLASH_OBSTAT_OBERR | ||
88 | # define AR ADDR | ||
89 | # define CR CTL | ||
90 | # define FLASH_CR_PER FLASH_CTL_PER | ||
91 | # define FLASH_CR_STRT FLASH_CTL_START | ||
92 | # define FLASH_CR_LOCK FLASH_CTL_LK | ||
93 | # define FLASH_CR_PG FLASH_CTL_PG | ||
94 | # define KEYR KEY | ||
95 | #endif | ||
96 | |||
97 | /* Serial USART redefines. */ | ||
98 | #if HAL_USE_SERIAL | ||
99 | # if !defined(SERIAL_USART_CR1) | ||
100 | # define SERIAL_USART_CR1 (USART_CTL0_PCEN | USART_CTL0_PM | USART_CTL0_WL) // parity enable, odd parity, 9 bit length | ||
101 | # endif | ||
102 | # if !defined(SERIAL_USART_CR2) | ||
103 | # define SERIAL_USART_CR2 (USART_CTL1_STB_1) // 2 stop bits | ||
104 | # endif | ||
105 | # if !defined(SERIAL_USART_CR3) | ||
106 | # define SERIAL_USART_CR3 0x0 | ||
107 | # endif | ||
108 | # define USART_CR3_HDSEL USART_CTL2_HDEN | ||
109 | # define CCR CHCV | ||
110 | #endif | ||
111 | |||
112 | /* SPI redefines. */ | ||
113 | #if HAL_USE_SPI | ||
114 | # define SPI_CR1_LSBFIRST SPI_CTL0_LF | ||
115 | # define SPI_CR1_CPHA SPI_CTL0_CKPH | ||
116 | # define SPI_CR1_CPOL SPI_CTL0_CKPL | ||
117 | # define SPI_CR1_BR_0 SPI_CTL0_PSC_0 | ||
118 | # define SPI_CR1_BR_1 SPI_CTL0_PSC_1 | ||
119 | # define SPI_CR1_BR_2 SPI_CTL0_PSC_2 | ||
120 | #endif | ||
diff --git a/tmk_core/common/chibios/syscall-fallbacks.c b/tmk_core/common/chibios/syscall-fallbacks.c index 739017ae1..4569879c7 100644 --- a/tmk_core/common/chibios/syscall-fallbacks.c +++ b/tmk_core/common/chibios/syscall-fallbacks.c | |||
@@ -18,6 +18,12 @@ | |||
18 | #include <sys/stat.h> | 18 | #include <sys/stat.h> |
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | 20 | ||
21 | /* To compile the ChibiOS syscall stubs with picolibc | ||
22 | * the _reent struct has to be defined. */ | ||
23 | #if defined(USE_PICOLIBC) | ||
24 | struct _reent; | ||
25 | #endif | ||
26 | |||
21 | #pragma GCC diagnostic ignored "-Wmissing-prototypes" | 27 | #pragma GCC diagnostic ignored "-Wmissing-prototypes" |
22 | 28 | ||
23 | __attribute__((weak, used)) int _open_r(struct _reent *r, const char *path, int flag, int m) { | 29 | __attribute__((weak, used)) int _open_r(struct _reent *r, const char *path, int flag, int m) { |