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

Add Zephyr RTOS support for WCH CH32V003 #73761

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

kholia
Copy link

@kholia kholia commented Jun 5, 2024

Details

This PR adds Zephyr RTOS support for WCH CH32V003 RISC-V MCU.

https://www.wch-ic.com/products/CH32V003.html

Usage

west update

west build -p always -b wch_ch32v003evt samples/basic/blinky

west flash -r minichlink

Tested On

  • Bare CH32V003J4M6 SOP-8 chip

  • WCH CH32V003EVT board (CH32V003 Evaluation Kit)

Blinky Build

$ west build -p always -b wch_ch32v003evt samples/basic/blinky
...
-- Zephyr version: 3.6.99 (zephyr), build: v3.6.0-5403-g90b43c51ff3f
[101/101] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
             ROM:       10056 B        16 KB     61.38%
             RAM:        1524 B         2 KB     74.41%
        IDT_LIST:          0 GB         2 KB      0.00%
Generating files from zephyr/build/zephyr/zephyr.elf for board: wch_ch32v003evt

It is fun to see Zephyr RTOS running on a "10 cent" MCU.

Copy link

github-actions bot commented Jun 5, 2024

Hello @kholia, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@zephyrbot
Copy link
Collaborator

zephyrbot commented Jun 5, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_wch N/A zephyrproject-rtos/hal_wch@1de9d3e (main) N/A

Note: This message is automatically posted and updated by the Manifest GitHub Action.

soc/wch/ch32v00x/Kconfig Show resolved Hide resolved
soc/wch/ch32v00x/soc.yml Outdated Show resolved Hide resolved
soc/wch/ch32v00x/Kconfig.soc Show resolved Hide resolved
boards/wch/ch32v003evt/Kconfig Outdated Show resolved Hide resolved
boards/wch/ch32v003evt/Kconfig.board Outdated Show resolved Hide resolved
boards/wch/ch32v003evt/Kconfig.defconfig Outdated Show resolved Hide resolved
dts/bindings/pinctrl/wch,afio.yaml Outdated Show resolved Hide resolved
drivers/gpio/Kconfig.ch32v00x Outdated Show resolved Hide resolved
@kholia
Copy link
Author

kholia commented Oct 2, 2024

All references to ch32v003fun.h filename are now confined to modules/hal_wch interface layer folder.

[dhiru@zippy zephyr]$ rg ch32v003fun                                                                        
modules/hal_wch/ch32_rcc.h
11:#include <ch32v003fun.h>

modules/hal_wch/ch32_gpio.h
11:#include <ch32v003fun.h>

modules/hal_wch/CMakeLists.txt
2:  zephyr_include_directories(${ZEPHYR_HAL_WCH_MODULE_DIR}/ch32v003fun .)

modules/hal_wch/ch32_uart.h
11:#include <ch32v003fun.h>

modules/hal_wch/ch32_soc.h
11:#include <ch32v003fun.h>

modules/hal_wch/ch32_pinctrl.h
11:#include <ch32v003fun.h>

modules/hal_wch/ch32_systick.h
11:#include <ch32v003fun.h>

modules/hal_wch/ch32_pfic.h
11:#include <ch32v003fun.h>

@fabiobaltieri fabiobaltieri removed the DNM This PR should not be merged (Do Not Merge) label Oct 3, 2024
fabiobaltieri
fabiobaltieri previously approved these changes Oct 3, 2024
Copy link
Member

@fabiobaltieri fabiobaltieri left a comment

Choose a reason for hiding this comment

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

Seems like a good starting point, would be cool to redo the clock configuration in devicetree rather than kconfig options but that can be a followup. To the other folks in the review list, can you do another pass?

cfriedt
cfriedt previously approved these changes Oct 3, 2024
@cnlohr
Copy link

cnlohr commented Oct 5, 2024

The clock tree on the 003 really only has 4 reasonable configurations, XTAL/internal and PLL/no PLL. There are extra main clock divisors you can use, but their practicality is very low. Is it expected to have richer configurations in things like this?

@nzmichaelh
Copy link
Collaborator

The clock tree on the 003 really only has 4 reasonable configurations, XTAL/internal and PLL/no PLL. There are extra main clock divisors you can use, but their practicality is very low. Is it expected to have richer configurations in things like this?

My vote is no, but if someone wants to add it in a follow up and it (ideally) doesn't increase the flash usage, then that's all good.

I think it's reasonable for Zephyr to support the common configurations. For example, it shouldn't cover just the CH32V003JM46 but all part numbers; and it shouldn't be HSE only but both HSI and HSE.

@cnlohr
Copy link

cnlohr commented Oct 5, 2024

The clock tree on the 003 really only has 4 reasonable configurations, XTAL/internal and PLL/no PLL. There are extra main clock divisors you can use, but their practicality is very low. Is it expected to have richer configurations in things like this?

My vote is no, but if someone wants to add it in a follow up and it (ideally) doesn't increase the flash usage, then that's all good.

I think it's reasonable for Zephyr to support the common configurations. For example, it shouldn't cover just the CH32V003JM46 but all part numbers; and it shouldn't be HSE only but both HSI and HSE.

All the 003 part numbers have identical cores, flash RAM and clock trees, thankfully.

@cnlohr
Copy link

cnlohr commented Oct 7, 2024

It's getting very close, @fabiobaltieri !
image

@kholia kholia dismissed stale reviews from cfriedt and fabiobaltieri via 39630a6 October 7, 2024 03:23
@kholia kholia force-pushed the ch32v003-for-upstream branch 2 times, most recently from 39630a6 to 2ca52da Compare October 7, 2024 03:24
@zephyrbot zephyrbot added the DNM This PR should not be merged (Do Not Merge) label Oct 7, 2024
@cnlohr
Copy link

cnlohr commented Oct 7, 2024

@kholia do you have a summary for what you changed? Or who's if any's quests have been changed?

@kholia
Copy link
Author

kholia commented Oct 8, 2024

@cnlohr I just added select ATOMIC_OPERATIONS_C line and rebased the PR on top of latest upstream main.

The current build failure does NOT seem related to this work.

Screenshot_2024-10-08_07-51-07

I will rebase and re-push the commits.

kholia and others added 11 commits October 9, 2024 13:07
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>
@kholia
Copy link
Author

kholia commented Oct 9, 2024

I have rebased and re-pushed the same commits in the hope of passing the CI checks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Clock Control area: Devicetree Binding PR modifies or adds a Device Tree binding area: GPIO area: Interrupt Controller area: Pinctrl area: Process area: RISCV RISCV Architecture (32-bit & 64-bit) area: Timer Timer area: UART Universal Asynchronous Receiver-Transmitter area: West West utility DNM This PR should not be merged (Do Not Merge) manifest manifest-hal_wch
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.