-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Add Zephyr RTOS support for WCH CH32V003 #73761
base: main
Are you sure you want to change the base?
Conversation
Hello @kholia, and thank you very much for your first pull request to the Zephyr project! |
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
39630a6
to
2ca52da
Compare
@kholia do you have a summary for what you changed? Or who's if any's quests have been changed? |
@cnlohr I just added The current build failure does NOT seem related to this work. I will rebase and re-push the commits. |
f87099a
to
aa19307
Compare
I have rebased and re-pushed the same commits in the hope of passing the CI checks! |
The current situation about CH32V307 header files licensing got a bit confusing, and this is an attempt to sort things out. Originally the WCH BSP files coming from the initial CH32V307 port commit came with an Apache 2.0 licence, which then it disappeared from newer BSP file versions. However, this prevented other projects such as Zephyr to actually support this MCU (and others from the same family). This prompted a request to WCH to relicense the BSP files under a more permissive licence such as MIT. A specific set of headers is currently available under the MIT licence after explicit relicensing from WCH, which is what this commit adds as a submodule. For reference, see openwch/ch32v003#45 and zephyrproject-rtos/zephyr#73761 (comment) Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The current situation about CH32V307 header files licensing got a bit confusing, and this is an attempt to sort things out. Originally the WCH BSP files coming from the initial CH32V307 port commit came with an Apache 2.0 licence, which then it disappeared from newer BSP file versions. However, this prevented other projects such as Zephyr to actually support this MCU (and others from the same family). This prompted a request to WCH to relicense the BSP files under a more permissive licence such as MIT. A specific set of headers is currently available under the MIT licence after explicit relicensing from WCH, which is what this commit adds as a submodule. For reference, see openwch/ch32v003#45 and zephyrproject-rtos/zephyr#73761 (comment) Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
There are still 4 changes requested - are they just waiting to be checked off by those reviewers? I wonder if someone should/could ping them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't manage to finish my last review. Just a small suggestion - not sure if it's still relevant
RCC_TypeDef *regs = config->regs; | ||
uint8_t id = (uintptr_t)sys; | ||
|
||
*(®s->AHBPCENR + WCH_RCC_CLOCK_ID_OFFSET(id)) |= 1 << WCH_RCC_CLOCK_ID_BIT(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*(®s->AHBPCENR + WCH_RCC_CLOCK_ID_OFFSET(id)) |= 1 << WCH_RCC_CLOCK_ID_BIT(id); | |
sys_write32(BIT(WCH_RCC_CLOCK_ID_BIT(id), ®s->AHBPCENR + WCH_RCC_CLOCK_ID_OFFSET(id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This results in:
clock_control_wch_rcc.c:31:68: warning: passing argument 2 of 'sys_write32' makes integer from pointer without a cast [-Wint-conversion]
31 | sys_write32(BIT(WCH_RCC_CLOCK_ID_BIT(id)), ®s->AHBPCENR + WCH_RCC_CLOCK_ID_OFFSET(id));
| ^
| |
| volatile uint32_t * {aka volatile unsigned int *}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the following change make sense?
+#define ENABLE_RCC_CLOCK(regs, id) \
+ (*(&(regs)->AHBPCENR + WCH_RCC_CLOCK_ID_OFFSET(id)) |= BIT(WCH_RCC_CLOCK_ID_BIT(id)))
+
#define WCH_RCC_CLOCK_ID_OFFSET(id) (((id) >> 5) & 0xFF)
#define WCH_RCC_CLOCK_ID_BIT(id) ((id) & 0x1F)
@@ -28,7 +31,8 @@ static int clock_control_wch_rcc_on(const struct device *dev, clock_control_subs
RCC_TypeDef *regs = config->regs;
uint8_t id = (uintptr_t)sys;
- *(®s->AHBPCENR + WCH_RCC_CLOCK_ID_OFFSET(id)) |= 1 << WCH_RCC_CLOCK_ID_BIT(id);
+ ENABLE_RCC_CLOCK(regs, id);
Looking forward to this landing! Here's a short video of 5 CH32V003 based boards running Zephyr and at least blinking a LED: https://juju.nz/michaelh/post/2024/all_so_far/ Once this PR lands, I'll send through PRs for I2C, SPI, and other drivers. |
Awesome! 🪁 |
config PINCTRL | ||
default y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not allowed, drivers must select this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger.
A bunch of existing code is doing the same thing though.
$ cat soc/atmel/sam/Kconfig.defconfig
# Atmel SAM MCU family default configuration options
# Copyright (c) 2016 Piotr Mienkowski
# Copyright (c) 2024 Gerson Fernando Budke <nandojve@gmail.com>
# SPDX-License-Identifier: Apache-2.0
if SOC_FAMILY_ATMEL_SAM
rsource "*/Kconfig.defconfig"
config CLOCK_CONTROL
default y
config GPIO
default y
config PINCTRL
default y
config SYS_CLOCK_HW_CYCLES_PER_SEC
default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency)
config WATCHDOG
default y
endif # SOC_FAMILY_ATMEL_SAM
Also there are other examples:
$ rg "config PINCTRL" | grep soc
soc/infineon/cat3/Kconfig.defconfig:config PINCTRL
soc/nxp/imxrt/Kconfig.defconfig:config PINCTRL_IMX
soc/microchip/mec/mec175x/Kconfig.defconfig.mec1753qlj:config PINCTRL
soc/microchip/mec/mec175x/Kconfig.defconfig.mec1753qsz:config PINCTRL
soc/microchip/mec/mec174x/Kconfig.defconfig.mec1743qsz:config PINCTRL
soc/microchip/mec/mec174x/Kconfig.defconfig.mec1743qlj:config PINCTRL
soc/microchip/mec/mech172x/Kconfig.defconfig.mech1723nlj:config PINCTRL
soc/microchip/mec/mech172x/Kconfig.defconfig.mech1723nsz:config PINCTRL
soc/gd/gd32/Kconfig.defconfig:config PINCTRL
soc/nxp/imx/imx8m/Kconfig.defconfig.mimx8ml8_a53:config PINCTRL_IMX
soc/nxp/imx/imx8m/Kconfig.defconfig.mimx8ml8_m7:config PINCTRL_IMX
soc/nxp/imx/imx8m/Kconfig.defconfig.mimx8mq6_m4:config PINCTRL_IMX
soc/nxp/imx/imx8m/Kconfig.defconfig.mimx8mn6_a53:config PINCTRL_IMX
soc/nxp/imx/imx8m/Kconfig.defconfig.mimx8mm6_m4:config PINCTRL_IMX
soc/nxp/imx/imx8m/Kconfig.defconfig.mimx8mm6_a53:config PINCTRL_IMX
soc/nxp/imx/imx7d/Kconfig.defconfig:config PINCTRL_IMX
soc/nxp/imx/imx6sx/Kconfig.defconfig:config PINCTRL_IMX
soc/nxp/imx/imx9/imx93/Kconfig.defconfig.mimx93.a55:config PINCTRL_IMX
soc/ti/k3/am6x/Kconfig.defconfig:config PINCTRL
soc/ite/ec/it8xxx2/Kconfig.defconfig.series:config PINCTRL
soc/atmel/sam/Kconfig.defconfig:config PINCTRL
soc/atmel/sam0/Kconfig.defconfig:config PINCTRL
soc/wch/ch32v00x/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra6m5/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra6e2/Kconfig.defconfig:config PINCTRL
soc/raspberrypi/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra4m3/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra8m1/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra6e1/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra2a1/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra8d1/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra6m3/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra6m2/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra8t1/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra6m1/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra4w1/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra4e2/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra6m4/Kconfig.defconfig:config PINCTRL
soc/renesas/ra/ra4m2/Kconfig.defconfig:config PINCTRL
soc/telink/tlsr/tlsr951x/Kconfig.defconfig:config PINCTRL
soc/renesas/rcar/rcar_gen4/Kconfig.defconfig.r8a779f0:config PINCTRL
soc/renesas/rcar/rcar_gen3/Kconfig.defconfig:config PINCTRL
@kholia I noticed a bug in the GPIO input mode configuration code. See nzmichaelh@e32d9ac for a fix that also adds pullup / pulldown support. |
This is used for WCH chips including the CH32V003. Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the dtsi and bindings for the WCH CH32V003 which is a 32-bit general-purpose RISC-V MCU. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the soc support for WCH CH32V003. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the pinctrl driver for WCH CH32V003. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the clock driver for WCH CH32V003. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the systick driver for WCH CH32V003. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the usart driver for WCH CH32V003. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the pfic interrupt controller driver for WCH CH32V003. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds the gpio driver for WCH CH32V003. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds support for the CH32V003EVT board which features a 32-bit general-purpose RISC-V MCU. Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit adds a runner wrapper for the 'minichlink' program which offers a free, open mechanism to use the CH-LinkE programming dongle for the CH32V003. https://github.com/cnlohr/ch32v003fun/tree/master/minichlink Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
aa19307
to
88e6d57
Compare
Applied and pushed - thanks! |
I have purchased the WCH board and can't wait to run Zephyr on it. What is I can do? Help to accelerate the merger. |
Details
This PR adds Zephyr RTOS support for WCH CH32V003 RISC-V MCU.
https://www.wch-ic.com/products/CH32V003.html
Usage
Tested On
Bare CH32V003J4M6 SOP-8 chip
WCH CH32V003EVT board (CH32V003 Evaluation Kit)
Blinky Build
It is fun to see Zephyr RTOS running on a "10 cent" MCU.