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 kholia force-pushed the ch32v003-for-upstream branch 5 times, most recently from a9f9ebe to 0c6ca7c Compare October 2, 2024 09:48
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.

hi, flagged few more pending comments and added few more, let's keep this moving :-)

soc/wch/ch32v00x/soc.c Outdated Show resolved Hide resolved
* SPDX-License-Identifier: Apache-2.0
*/

#include <offsets.h>
Copy link
Member

Choose a reason for hiding this comment

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

@nzmichaelh @kholia is this someting you are going to look into further?

RCC_TypeDef *regs = config->regs;
uint8_t id = (uintptr_t)sys;

*(&regs->AHBPCENR + WCH_RCC_CLOCK_ID_OFFSET(id)) |= 1 << WCH_RCC_CLOCK_ID_BIT(id);
Copy link
Member

Choose a reason for hiding this comment

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

still pending

drivers/timer/ch32v00x_systick.c Outdated Show resolved Hide resolved
#
# SPDX-License-Identifier: Apache-2.0

"""CH32V00x specific runner."""
Copy link
Member

Choose a reason for hiding this comment

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

found references of minichlink and other parts, I say just rename it to be generic

soc/wch/ch32v00x/soc.c Show resolved Hide resolved
@kholia kholia force-pushed the ch32v003-for-upstream branch 6 times, most recently from b89d78c to 70dc45a Compare October 2, 2024 14:59
kholia and others added 2 commits October 2, 2024 21:00
This is used for WCH chips including the CH32V003.

Signed-off-by: Dhiru Kholia <[email protected]>
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 <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds the soc support for WCH CH32V003.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds the pinctrl driver for WCH CH32V003.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds the clock driver for WCH CH32V003.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds the systick driver for WCH CH32V003.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds the usart driver for WCH CH32V003.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds the pfic interrupt controller driver for WCH CH32V003.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds the gpio driver for WCH CH32V003.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
This commit adds support for the CH32V003EVT board which features a
32-bit general-purpose RISC-V MCU.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
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 <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
@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
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?

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 manifest manifest-hal_wch
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.