Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Add support for RISC-V builds and GD32VF103 MCU #12508

Merged
merged 6 commits into from
Oct 18, 2021

Conversation

KarlK90
Copy link
Member

@KarlK90 KarlK90 commented Apr 7, 2021

Description

My port of the GD32VF103 has finally been merged into ChibiOS-Contrib so this PR adds support for this MCU and RISC-V in general. 🥳

  • Added toolchain selection in chibios.mk based on the mcu selected in mcu_selection.mk (This could be useful for other ports in the future).
  • Reordered and added comments to chibios.mk to have a streamlined makefile. (So far I was able to build ARM and RISC-V Boards without any problem, but there is a chance that I broke something when reordering the statements)
  • Added GD32VF103 MCU to possible targets for QMK.
  • Added GD DFU bootloader to known bootloaders.
  • Added STM32 compatibility for GD32VF103 MCU, this is hacky but more efficient then rewriting every driver.
  • Added Longan Nano to supported platfrom files.
  • Enabled STM32F103 EEPROM Flash emulation for GD32VF103
  • Soft resetting the board is possible ATM but jumping to the bootloader from user code is not. I don't know if this is possible at all my attempts have been fruitless so far, even jumping right to the bootloader address after resetting the mcu.

The targeted toolchain is riscv64-unknown-elf or riscv32-unknown-elf. embecosm provides pre-built GCC toolchains for every OS. Also Debian 11 and Ubuntu 21.04 have support for building via picolibc-riscv64-unknown-elf gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf.

Example rules.mk config:

MCU        = GD32VF103
BOARD      = SIPEED_LONGAN_NANO
BOOTLOADER = gd32-dfu

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@github-actions github-actions bot added cli qmk cli command core python labels Apr 7, 2021
@KarlK90 KarlK90 marked this pull request as ready for review April 7, 2021 09:43
@tzarc tzarc requested review from tzarc and a team April 7, 2021 10:54
@KarlK90 KarlK90 changed the title Add support for RISC-V builds and GD32VF103 MCU [Core] [DRAFT] Add support for RISC-V builds and GD32VF103 MCU May 12, 2021
@stale
Copy link

stale bot commented Jun 26, 2021

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@stale stale bot removed the awaiting changes label Jul 3, 2021
@KarlK90 KarlK90 changed the title [Core] [DRAFT] Add support for RISC-V builds and GD32VF103 MCU [Core] Add support for RISC-V builds and GD32VF103 MCU Jul 4, 2021
@KarlK90 KarlK90 force-pushed the risc-v-support branch 2 times, most recently from b071d07 to 44e7d22 Compare July 4, 2021 22:58
@KarlK90
Copy link
Member Author

KarlK90 commented Jul 4, 2021

@tzarc this is ready for review now 🥳

@KarlK90
Copy link
Member Author

KarlK90 commented Jul 4, 2021

Oh yes there is one thing:

For ChibiOS ARM builds GCC is currently set to align functions to 16 Byte boundaries with -falign-functions=16. I tried to find the reasoning behind that and the only reference I could find is this one from https://www.keil.com/support/man/docs/armasm/armasm_dom1361290002364.htm

Use ALIGN to take advantage of caches on some ARM processors. For example, the ARM940T has a cache with 16-byte lines. Use ALIGN 16 to align function entries on 16-byte boundaries and maximize the efficiency of the cache.

But none of the supported ARM MCUs has 16-bytes lines, M7 afaik have 32-byte boundaries if they have cache at all. Do I miss anything?

In conclusion I just dropped that flag.

lib/python/qmk/cli/console.py Outdated Show resolved Hide resolved
@KarlK90
Copy link
Member Author

KarlK90 commented Jul 5, 2021

I have opened a issue at Nuclei-Software/nuclei-sdk#29 to see if it is possible at all to jump to the embedded bootloader.

@KarlK90
Copy link
Member Author

KarlK90 commented Jul 6, 2021

After some further investigation I'm pretty confident that it is not possible to jump to the bootloader from user code, because the bootloader wasn't written in a position independent way. See Nuclei-Software/nuclei-sdk#29 (comment) for further details.

That leaves us with two possibilities:

  1. External reset and bootloader hardware like for the STM32 dual bank flash chips (e.g. G4s) (see below)
  2. Userland bootloader like gd32vf103inator or the stm32duino ones.

I tried the dual bank reset hardware circuit on a YAEMK prototyp that has the same that is also found on the djinn. And it doesn't work for this chip. It resets but doesn't enter the bootloader and it generally just stuck until you reset it. BOOT0 is pulled high for at least 300ms with a 1uF capacitor. Doesn't matter if it is done by pushing the dfu button or with the charge pin mechanism. So the 2nd option is what we have left, because the bootloader is a buggy mess.

@KarlK90
Copy link
Member Author

KarlK90 commented Jul 19, 2021

friendly ping 🙂

@drashna drashna requested a review from a team July 20, 2021 17:13
@drashna
Copy link
Member

drashna commented Jul 30, 2021

Got some merge conflict.

@KarlK90 KarlK90 force-pushed the risc-v-support branch 2 times, most recently from ca91cfd to 3f81d02 Compare July 30, 2021 15:40
@KarlK90
Copy link
Member Author

KarlK90 commented Jul 30, 2021

Got some merge conflict.

Resolved.

@KarlK90
Copy link
Member Author

KarlK90 commented Aug 16, 2021

All pending chibios-contrib prs have been merged, I will resolve the conflicts.

@github-actions github-actions bot removed the via Adds via keymap and/or updates keyboard for via support label Sep 14, 2021
Comment on lines 35 to 53
// GD32 compatibility
#if defined(MCU_GD)
# define CPU_CLOCK GD32_SYSCLK
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zvecr I have aligned the clock selection with GH-14430.

docs/driver_installation_zadig.md Outdated Show resolved Hide resolved
keyboards/handwired/onekey/readme.md Outdated Show resolved Hide resolved
keyboards/handwired/onekey/readme.md Outdated Show resolved Hide resolved
@KarlK90 KarlK90 force-pushed the risc-v-support branch 3 times, most recently from 927452e to fd69f31 Compare September 15, 2021 15:31
@@ -161,7 +161,7 @@ else
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
OPT_DEFS += -DEEPROM_EMU_STM32F303xC
OPT_DEFS += -DSTM32_EEPROM_ENABLE
else ifeq ($(MCU_SERIES), STM32F1xx)
else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),STM32F1xx GD32VF103))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),STM32F1xx GD32VF103))
else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),STM32F1xx GD32VF103)) # Despite being RISC-V, GD32VF103 effectively clones the peripherals of an equivalent STM32F103

@@ -93,6 +93,7 @@ The device name here is the name that appears in Zadig, and may not be what the
|`usbasploader`|USBasp |`16C0:05DC` |libusbK|
|`apm32-dfu` |APM32 DFU ISP Mode |`314B:0106` |WinUSB |
|`stm32-dfu` |STM32 BOOTLOADER |`0483:DF11` |WinUSB |
|`gd32-dfu` |GD32 BOOTLOADER |`28E9:0189` |WinUSB |
Copy link
Member

@tzarc tzarc Sep 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|`gd32-dfu` |GD32 BOOTLOADER |`28E9:0189` |WinUSB |
|`gd32v-dfu` |GD32V BOOTLOADER |`28E9:0189` |WinUSB |

platforms/chibios/boards/common/configs/chconf.h Outdated Show resolved Hide resolved
docs/compatible_microcontrollers.md Outdated Show resolved Hide resolved
platforms/chibios/flash.mk Outdated Show resolved Hide resolved
quantum/mcu_selection.mk Outdated Show resolved Hide resolved
tmk_core/chibios.mk Outdated Show resolved Hide resolved
tmk_core/chibios.mk Outdated Show resolved Hide resolved
tmk_core/common/chibios/chibios_config.h Outdated Show resolved Hide resolved
tmk_core/common/chibios/flash_stm32.c Outdated Show resolved Hide resolved
@KarlK90
Copy link
Member Author

KarlK90 commented Sep 30, 2021

@tzarc Thanks for the review! Applied suggested changes.

@drashna drashna requested a review from a team October 11, 2021 00:21
* 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
@KarlK90
Copy link
Member Author

KarlK90 commented Oct 16, 2021

Rebased on develop, so friendly ping. 🙂

@tzarc tzarc requested review from a team and fauxpark October 18, 2021 04:59
Copy link
Member

@drashna drashna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__attribute__((weak))

@tzarc tzarc merged commit e50867d into qmk:develop Oct 18, 2021
@KarlK90 KarlK90 deleted the risc-v-support branch October 18, 2021 07:11
@KarlK90
Copy link
Member Author

KarlK90 commented Oct 18, 2021

Cheers everyone! 🎉

cadusk pushed a commit to cadusk/qmk_firmware that referenced this pull request Oct 19, 2021
* qmk/develop: (26 commits)
  [DOCS] Fix the STENO_COMBINEDMAP table (qmk#14883)
  Fix builds for ChibiOS + Cortex-M0[+] (qmk#14879)
  Split out HAPTIC_ENABLE to have separate DRIVER option (qmk#14854)
  [Core] Add support for RISC-V builds and GD32VF103 MCU (qmk#12508)
  Add HT32 support to core (qmk#14388)
  preonic/rev3_drop: Fix old custom matrix code (qmk#14857)
  Remove legacy Makefile functionality (qmk#14858)
  Infer more when building features (qmk#13890)
  [Keymap] added media controls, copy and paste; moved print screen (qmk#14850)
  [Keyboard] Add SpiderIsland 25 key keyboard (qmk#14793)
  [Keyboard] Update Support for The Uni (qmk#14569)
  Try to clarify "number of elements in info.json does not match" error (qmk#14844)
  [Keyboard] Fix minor typo in Ploopy Trackball Nano Docs (qmk#14717)
  add docs/ja/ja_doc_status.sh (qmk#14402)
  [Keyboard] Amended Some Pins - KiwiKeebs Macro V2 (qmk#14824)
  [Keyboard] Adding CK60 and CK65 (qmk#14737)
  [Keymap] Update Miryoku (qmk#14827)
  [Keymap] Drashna Keymap Updates (qmk#14842)
  [Keyboard] Tractyl Manuform Updates (qmk#14841)
  [Keymap] Added GMMK Pro keymap with RGB  (qmk#14648)
  ...
ptrxyz pushed a commit to ptrxyz/qmk_firmware that referenced this pull request Apr 9, 2022
* 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
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants