diff --git a/builddefs/mcu_selection.mk b/builddefs/mcu_selection.mk index 17c80b9c49e2..253135ec2d56 100644 --- a/builddefs/mcu_selection.mk +++ b/builddefs/mcu_selection.mk @@ -1,5 +1,36 @@ MCU_ORIG := $(MCU) +ifneq ($(findstring CH582, $(MCU)),) + # RISC-V + MCU = risc-v + + # RISC-V extensions and abi configuration + MCU_ARCH = rv32imac + MCU_ABI = ilp32 + MCU_CMODEL = medlow + + ## chip/board settings + # - the next two should match the directories in + # /os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) + MCU_FAMILY = CH58x + MCU_SERIES = CH582 + + # Linker script to use + # - it should exist either in /os/common/startup/RISCV-ECLIC/compilers/GCC/ld/ + # or /ld/ + MCU_LDSCRIPT ?= CH582M + + # Startup code to use + # - it should exist in /os/common/startup/RISCV-ECLIC/compilers/GCC/mk/ + MCU_STARTUP ?= ch582m + + # Board: it should exist either in /os/hal/boards/, + # /boards/, or drivers/boards/ + BOARD ?= CH582_DEMO + + USE_FPU ?= no +endif + ifneq ($(findstring MKL26Z64, $(MCU)),) # Cortex version MCU = cortex-m0plus @@ -196,15 +227,9 @@ ifneq ($(findstring STM32F103, $(MCU)),) MCU_FAMILY = STM32 MCU_SERIES = STM32F1xx - ifeq ($(strip $(BOOTLOADER)), tinyuf2) - MCU_LDSCRIPT ?= STM32F103x8_uf2 - FIRMWARE_FORMAT ?= uf2 - BOARD ?= STM32_F103_STM32DUINO - else - MCU_LDSCRIPT ?= STM32F103x8 - BOARD ?= GENERIC_STM32_F103 - endif - + MCU_LDSCRIPT ?= STM32F103x8 + BOARD ?= GENERIC_STM32_F103 + # Startup code to use # - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ MCU_STARTUP ?= stm32f1xx @@ -700,7 +725,6 @@ ifneq ($(findstring GD32VF103, $(MCU)),) ifeq ($(strip $(BOOTLOADER)), tinyuf2) MCU_LDSCRIPT ?= GD32VF103xB_uf2 FIRMWARE_FORMAT ?= uf2 - OPT_DEFS += -DGD32VF103UF2 else MCU_LDSCRIPT ?= GD32VF103xB endif diff --git a/keyboards/zhaqian/gh60/rules.mk b/keyboards/zhaqian/gh60/rules.mk index 87f258ae55c7..fe2663ceb738 100644 --- a/keyboards/zhaqian/gh60/rules.mk +++ b/keyboards/zhaqian/gh60/rules.mk @@ -1,14 +1,11 @@ # MCU name MCU = STM32F103 +MCU_LDSCRIPT = STM32F103xB_uf2 +FIRMWARE_FORMAT = uf2 +BOARD = STM32_F103_STM32DUINO # Bootloader selection -BOOTLOADER = tinyuf2 - -ifeq ($(strip $(BOOTLOADER)), tinyuf2) - MCU_LDSCRIPT = STM32F103x8_uf2 - FIRMWARE_FORMAT = uf2 - BOARD = STM32_F103_STM32DUINO -endif +BOOTLOADER = custom # Build Options # comment out to disable the options. @@ -21,7 +18,7 @@ COMMAND_ENABLE = no SLEEP_LED_ENABLE = no NKRO_ENABLE = yes RGBLIGHT_ENABLE = no +LTO_ENABLE = yes OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE - - +SRC += uf2_boot.c diff --git a/keyboards/zhaqian/gh60/uf2_boot.c b/keyboards/zhaqian/gh60/uf2_boot.c new file mode 100644 index 000000000000..c09adb15d6f2 --- /dev/null +++ b/keyboards/zhaqian/gh60/uf2_boot.c @@ -0,0 +1,30 @@ +/* Copyright 2022 ZhaQian + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bootloader.h" + +#include + +#define MAGIC_BOOT 0x544F4F42UL +#define MAGIC_REG *(volatile uint32_t*)0x20004000 + +void bootloader_jump(void) { + MAGIC_REG = MAGIC_BOOT; + NVIC_SystemReset(); +} + +void enter_bootloader_mode_if_requested(void) {} + diff --git a/keyboards/zhaqian/readme.md b/keyboards/zhaqian/readme.md index b3ff318605ee..11c320e5c3ac 100644 --- a/keyboards/zhaqian/readme.md +++ b/keyboards/zhaqian/readme.md @@ -1,6 +1,21 @@ # Readme Version * [Enlish version](./readme.md) * [Chinese version](./readme_cn.md) + +# Table of Contents +- [Readme Version](#readme-version) +- [Table of Contents](#table-of-contents) +- [Keyboards Released by ZhaQian](#keyboards-released-by-zhaqian) +- [TODO LIST](#todo-list) +- [ZhaQian library](#zhaqian-library) + - [Alt Tab Marco](#alt-tab-marco) + - [Encoder Trigger](#encoder-trigger) + - [Joystick Trigger](#joystick-trigger) + - [Radial Controller](#radial-controller) + - [RGB Matrix Control](#rgb-matrix-control) + - [Underglow RGB Matrix](#underglow-rgb-matrix) + - [UF2 Bootloader](#uf2-bootloader) + # Keyboards Released by ZhaQian | NAME | VENDOR_ID | PRODUCT_ID | PCB | MCU | FEATURES | |:-------------:| :-------: | :--------: | :------: |:----------------: | :------------------------------------------: | @@ -28,6 +43,12 @@ | zq50 | 0x00AA | 0xAA16 | Hotswap | ST stm32f103/f103 | RGB, UGRGB, ENCODER | | Mpad12 | 0x00AA | 0xAAAA | Hotswap | Atmel atmega32u4 | RGB, UGRGB, JOYSTICK, ENCODER, OLED | | split69 | 0x00AA | 0xAAAB | Solder | Atmel atmega32u4 | SPLIT, UGRGB, OLED, ENCODER | +| GH60 | 0xFEED | 0x6060 | Hotswap | ST stm32f103/f103 | RGB | +# TODO LIST +- BLE + - [ ] CH58X protocol of qmk + - [x] new kb firmware(use cherry usb) +- Rgb matrix control software (usb hid) # ZhaQian library This is a simple library that integrates some common repetitive functions. @@ -163,7 +184,4 @@ You can also alternate these defines to control these feature: |STM32F411xE| |GD32VF103xB| -# TODO LIST -- Bluetooth (esp32s3,ch58x or nrf) -- Rgb matrix control software (usb hid) diff --git a/keyboards/zhaqian/readme_cn.md b/keyboards/zhaqian/readme_cn.md index 48b654d5ea1b..3ec4051e786c 100644 --- a/keyboards/zhaqian/readme_cn.md +++ b/keyboards/zhaqian/readme_cn.md @@ -1,6 +1,20 @@ # Readme Version * [Enlish version](./readme.md) * [Chinese version](./readme_cn.md) + +# Table of Contents +- [Readme Version](#readme-version) +- [Table of Contents](#table-of-contents) +- [Keyboards Released by ZhaQian](#keyboards-released-by-zhaqian) +- [ZhaQian library](#zhaqian-library) + - [Alt Tab Marco](#alt-tab-marco) + - [Encoder Trigger](#encoder-trigger) + - [Joystick Trigger](#joystick-trigger) + - [Radial Controller](#radial-controller) + - [RGB Matrix Control](#rgb-matrix-control) + - [Underglow RGB Matrix](#underglow-rgb-matrix) + - [UF2 Bootloader](#uf2-bootloader) +- [TODO LIST](#todo-list) # Keyboards Released by ZhaQian | NAME | VENDOR_ID | PRODUCT_ID | PCB | MCU | FEATURES | |:-------------:| :-------: | :--------: | :------: |:----------------: | :------------------------------------------: | @@ -28,7 +42,7 @@ | zq50 | 0x00AA | 0xAA16 | Hotswap | ST stm32f103/f103 | RGB, UGRGB, ENCODER | | Mpad12 | 0x00AA | 0xAAAA | Hotswap | Atmel atmega32u4 | RGB, UGRGB, JOYSTICK, ENCODER, OLED | | split69 | 0x00AA | 0xAAAB | Solder | Atmel atmega32u4 | SPLIT, UGRGB, OLED, ENCODER | - +| GH60 | 0xFEED | 0x6060 | Hotswap | ST stm32f103/f103 | RGB | # ZhaQian library 这是一个集合了许多简单的但可能在不同键盘上重复用到功能的库. - Alt Tab Marco diff --git a/keyboards/zhaqian/s80/board.h b/keyboards/zhaqian/s80/board.h index 466f23dfa148..08479e31ab83 100644 --- a/keyboards/zhaqian/s80/board.h +++ b/keyboards/zhaqian/s80/board.h @@ -21,3 +21,5 @@ #undef STM32_HSECLK #define STM32_HSECLK 8000000 +#undef STM32F103xB +#define STM32F103x8 \ No newline at end of file diff --git a/keyboards/zhaqian/s80/rules.mk b/keyboards/zhaqian/s80/rules.mk index 3fde4cef58af..51588ed016c7 100644 --- a/keyboards/zhaqian/s80/rules.mk +++ b/keyboards/zhaqian/s80/rules.mk @@ -1,9 +1,11 @@ # MCU name MCU = STM32F103 +MCU_LDSCRIPT = STM32F103x8_uf2 +FIRMWARE_FORMAT = uf2 +BOARD = STM32_F103_STM32DUINO # Bootloader selection -BOOTLOADER = tinyuf2 - +BOOTLOADER = custom # Build Options # comment out to disable the options. # @@ -16,5 +18,7 @@ SLEEP_LED_ENABLE = no NKRO_ENABLE = yes RGBLIGHT_ENABLE = no KEYBOARD_SHARED_EP = no +LTO_ENABLE = yes OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE +SRC += uf2_boot.c diff --git a/keyboards/zhaqian/s80/uf2_boot.c b/keyboards/zhaqian/s80/uf2_boot.c new file mode 100644 index 000000000000..c09adb15d6f2 --- /dev/null +++ b/keyboards/zhaqian/s80/uf2_boot.c @@ -0,0 +1,30 @@ +/* Copyright 2022 ZhaQian + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bootloader.h" + +#include + +#define MAGIC_BOOT 0x544F4F42UL +#define MAGIC_REG *(volatile uint32_t*)0x20004000 + +void bootloader_jump(void) { + MAGIC_REG = MAGIC_BOOT; + NVIC_SystemReset(); +} + +void enter_bootloader_mode_if_requested(void) {} + diff --git a/keyboards/zhaqian/sp67/board.h b/keyboards/zhaqian/sp67/board.h index 466f23dfa148..ecc888a03c7c 100644 --- a/keyboards/zhaqian/sp67/board.h +++ b/keyboards/zhaqian/sp67/board.h @@ -21,3 +21,5 @@ #undef STM32_HSECLK #define STM32_HSECLK 8000000 +#undef STM32F103xB +#define STM32F103x8 diff --git a/keyboards/zhaqian/sp67/rules.mk b/keyboards/zhaqian/sp67/rules.mk index 3fde4cef58af..6f2982909e44 100644 --- a/keyboards/zhaqian/sp67/rules.mk +++ b/keyboards/zhaqian/sp67/rules.mk @@ -1,8 +1,11 @@ # MCU name MCU = STM32F103 +MCU_LDSCRIPT = STM32F103x8_uf2 +FIRMWARE_FORMAT = uf2 +BOARD = STM32_F103_STM32DUINO # Bootloader selection -BOOTLOADER = tinyuf2 +BOOTLOADER = custom # Build Options # comment out to disable the options. @@ -16,5 +19,7 @@ SLEEP_LED_ENABLE = no NKRO_ENABLE = yes RGBLIGHT_ENABLE = no KEYBOARD_SHARED_EP = no +LTO_ENABLE = yes OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE +SRC += uf2_boot.c diff --git a/keyboards/zhaqian/sp67/uf2_boot.c b/keyboards/zhaqian/sp67/uf2_boot.c new file mode 100644 index 000000000000..c09adb15d6f2 --- /dev/null +++ b/keyboards/zhaqian/sp67/uf2_boot.c @@ -0,0 +1,30 @@ +/* Copyright 2022 ZhaQian + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bootloader.h" + +#include + +#define MAGIC_BOOT 0x544F4F42UL +#define MAGIC_REG *(volatile uint32_t*)0x20004000 + +void bootloader_jump(void) { + MAGIC_REG = MAGIC_BOOT; + NVIC_SystemReset(); +} + +void enter_bootloader_mode_if_requested(void) {} + diff --git a/keyboards/zhaqian/zq50/rules.mk b/keyboards/zhaqian/zq50/rules.mk index 56ad20929204..0f564a241ade 100644 --- a/keyboards/zhaqian/zq50/rules.mk +++ b/keyboards/zhaqian/zq50/rules.mk @@ -1,9 +1,11 @@ # MCU name MCU = STM32F103 MCU_LDSCRIPT = STM32F103xB_uf2 +FIRMWARE_FORMAT = uf2 +BOARD = STM32_F103_STM32DUINO # Bootloader selection -BOOTLOADER = tinyuf2 +BOOTLOADER = custom # Build Options # comment out to disable the options. @@ -16,7 +18,8 @@ COMMAND_ENABLE = no SLEEP_LED_ENABLE = no NKRO_ENABLE = yes RGBLIGHT_ENABLE = no +LTO_ENABLE = yes OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE - +SRC += uf2_boot.c diff --git a/keyboards/zhaqian/zq50/uf2_boot.c b/keyboards/zhaqian/zq50/uf2_boot.c new file mode 100644 index 000000000000..c09adb15d6f2 --- /dev/null +++ b/keyboards/zhaqian/zq50/uf2_boot.c @@ -0,0 +1,30 @@ +/* Copyright 2022 ZhaQian + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bootloader.h" + +#include + +#define MAGIC_BOOT 0x544F4F42UL +#define MAGIC_REG *(volatile uint32_t*)0x20004000 + +void bootloader_jump(void) { + MAGIC_REG = MAGIC_BOOT; + NVIC_SystemReset(); +} + +void enter_bootloader_mode_if_requested(void) {} + diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_uf2.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_uf2.ld index 5642c437ea63..ebf3b02033c7 100644 --- a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_uf2.ld +++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_uf2.ld @@ -83,6 +83,3 @@ REGION_ALIAS("HEAP_RAM", ram0); /* Generic rules inclusion.*/ INCLUDE rules.ld - -/* TinyUF2 bootloader reset support */ -_board_dfu_dbl_tap = ORIGIN(ram0) + 20k - 4; /* this is based off the linker file for tinyuf2 */ diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_uf2.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_uf2.ld index 2ca1b1bccb5a..f9b419551953 100644 --- a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_uf2.ld +++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_uf2.ld @@ -84,5 +84,4 @@ REGION_ALIAS("HEAP_RAM", ram0); /* Generic rules inclusion.*/ INCLUDE rules.ld -/* TinyUF2 bootloader reset support */ -_board_dfu_dbl_tap = ORIGIN(ram0) + 20k - 4; /* this is based off the linker file for tinyuf2 */ + diff --git a/platforms/chibios/bootloaders/tinyuf2.c b/platforms/chibios/bootloaders/tinyuf2.c index 19977e62978e..dd902346c7f3 100644 --- a/platforms/chibios/bootloaders/tinyuf2.c +++ b/platforms/chibios/bootloaders/tinyuf2.c @@ -25,7 +25,7 @@ extern uint32_t _board_dfu_dbl_tap[]; #define DBL_TAP_REG _board_dfu_dbl_tap[0] -#ifdef GD32VF103UF2 +#ifdef GD32VF103 #define DBGMCU_KEY_UNLOCK 0x4B5A6978 #define DBGMCU_CMD_RESET 0x1 __IO uint32_t *DBGMCU_KEY = (uint32_t *)0xE0042000U + 0x0CU; @@ -34,7 +34,7 @@ __IO uint32_t *DBGMCU_CMD = (uint32_t *)0xE0042000U + 0x08U; __attribute__((weak)) void bootloader_jump(void) { DBL_TAP_REG = DBL_TAP_MAGIC; -#ifndef GD32VF103UF2 +#ifndef GD32VF103 NVIC_SystemReset(); #else *DBGMCU_KEY = DBGMCU_KEY_UNLOCK; diff --git a/platforms/chibios/eeprom_stm32_defs.h b/platforms/chibios/eeprom_stm32_defs.h index 13a693136907..3ac3b082bd82 100644 --- a/platforms/chibios/eeprom_stm32_defs.h +++ b/platforms/chibios/eeprom_stm32_defs.h @@ -45,7 +45,7 @@ #if !defined(FEE_MCU_FLASH_SIZE) # if defined(STM32F042x6) # define FEE_MCU_FLASH_SIZE 32 // Size in Kb -# elif defined(GD32VF103C8) +# elif defined(GD32VF103C8) || defined(STM32F103x8) # define FEE_MCU_FLASH_SIZE 64 // Size in Kb # elif defined(STM32F103xB) || defined(STM32F072xB) || defined(STM32F070xB) || defined(GD32VF103CB) || defined(CM32M101A) # define FEE_MCU_FLASH_SIZE 128 // Size in Kb @@ -62,7 +62,11 @@ #if !defined(FEE_PAGE_BASE_ADDRESS) # if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F405xG) || defined(STM32F411xE) # ifndef FEE_PAGE_BASE_ADDRESS -# define FEE_PAGE_BASE_ADDRESS 0x08004000 // bodge to force 2nd 16k page +# ifdef BOOTLOADER_TINYUF2 +# define FEE_PAGE_BASE_ADDRESS 0x08008000 // bodge to force 3nd 16k page +# else +# define FEE_PAGE_BASE_ADDRESS 0x08004000 // bodge to force 2nd 16k page +# endif # endif # else # ifndef FEE_FLASH_BASE diff --git a/platforms/chibios/eeprom_stm32_l4.c b/platforms/chibios/eeprom_stm32_l4.c index edb6d0762d48..934ce82eaab7 100644 --- a/platforms/chibios/eeprom_stm32_l4.c +++ b/platforms/chibios/eeprom_stm32_l4.c @@ -535,7 +535,7 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) { write_len = 2; } else { /* Write the unaligned or single byte */ - EEPROM_WriteDataByte((uintptr_t)dest++, *src++); + EEPROM_WriteDataByte((uintptr_t)dest, *src); write_len = 1; }