Skip to content

Conversation

@kholia
Copy link
Contributor

@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 ch32v003evt samples/basic/blinky

west flash -r minichlink

Run CI checks locally

./scripts/ci/check_compliance.py -c origin/main..

Tested On

  • Bare CH32V003J4M6 SOP-8 chip

  • WCH CH32V003EVT board (CH32V003 Evaluation Kit)

Blinky Build

$ west build -p always -b ch32v003evt samples/basic/blinky
...
-- Zephyr version: 4.0.0-rc2 (zephyr), build: v3.7.0-5702-g9ba0ccf52d86
[99/99] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
             ROM:       10448 B        16 KB     63.77%
             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: ch32v003evt

Build Hello World

$ west build -p always -b ch32v003evt samples/hello_world
-- Zephyr version: 4.0.0-rc3 (zephyrproject/zephyr), build: v3.7.0-5962-g62996ce8717a
[106/106] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
             ROM:       10710 B        16 KB     65.37%
             RAM:        1526 B         2 KB     74.51%
        IDT_LIST:          0 GB         2 KB      0.00%

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

Board Doc Preview (edit by cfriedt)

@kholia kholia requested review from dcpleung and nashif as code owners June 5, 2024 05:31
@github-actions
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

zephyrbot commented Jun 5, 2024

The following west manifest projects have changed revision in this Pull Request:

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

DNM label due to: 1 added project

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

@kholia kholia force-pushed the ch32v003-for-upstream branch from 26f6f3e to ca12333 Compare November 26, 2024 10:55
@zephyrbot zephyrbot added the DNM This PR should not be merged (Do Not Merge) label Nov 26, 2024
@kholia
Copy link
Contributor Author

kholia commented Nov 26, 2024

@kartben @fabiobaltieri Does the following patch look okay to you?

diff --git a/boards/wch/ch32v003evt/ch32v003evt.dts b/boards/wch/ch32v003evt/ch32v003evt.dts
index 3f442754712..e369d82565e 100644
--- a/boards/wch/ch32v003evt/ch32v003evt.dts
+++ b/boards/wch/ch32v003evt/ch32v003evt.dts
@@ -32,6 +32,12 @@
        };
 };
 
+&red_led {
+       status = "disabled"; // Please connect the unconnected LED on the WCH
+                            // CH32V003EVT board to a suitable GPIO pin (like PD4)
+                            // and then change this status to "okay".
+};
+
 &clk_hse {
        clock-frequency = <DT_FREQ_M(24)>;
        status = "okay";

@fabiobaltieri
Copy link
Member

fabiobaltieri commented Nov 26, 2024

@kartben @fabiobaltieri Does the following patch look okay to you?

No that does nothing, disable the whole gpio-leds node instead, also these normally use /* style comments, better inline with the code than indented up, they turn from a comment to a haiku pretty quickly otherwise

leds {
		compatible = "gpio-leds";
                /* Please connect the unconnected LED on the WCH etc etc
                */
                status = "disabled";

		red_led: led0 {
...

@fabiobaltieri fabiobaltieri removed the DNM This PR should not be merged (Do Not Merge) label Nov 26, 2024
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 kholia force-pushed the ch32v003-for-upstream branch from ca12333 to 771c85c Compare November 26, 2024 11:47
@zephyrbot zephyrbot added the DNM This PR should not be merged (Do Not Merge) label Nov 26, 2024
@fabiobaltieri fabiobaltieri removed the DNM This PR should not be merged (Do Not Merge) label Nov 26, 2024
@fabiobaltieri fabiobaltieri assigned kholia and unassigned nordic-krch Nov 26, 2024
Copy link
Contributor

@kartben kartben left a comment

Choose a reason for hiding this comment

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

🚀

@fabiobaltieri fabiobaltieri merged commit de19a13 into zephyrproject-rtos:main Nov 26, 2024
40 of 41 checks passed
@github-actions
Copy link

Hi @kholia!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

@fabiobaltieri
Copy link
Member

@kholia and everyone, thanks for your patience and persistence with this.

@kholia
Copy link
Contributor Author

kholia commented Nov 26, 2024

@nzmichaelh Hey - You can queue up rest of the drivers now - thank you! <3

@nzmichaelh
Copy link
Contributor

Thanks everyone! I'll get going on the console, ADC, I2C, SPI, and WDT drivers...

@cnlohr
Copy link

cnlohr commented Nov 26, 2024

Also, if anyone is interested/curious, newer versions of 003fun support the ch32x033, x035, v203, v305 and v307. (With no-quite-complete support for the v103 and v208). But amazing work everyone. Thank you @kholia for driving this to ground. That was quite the 205 days!

@kartben
Copy link
Contributor

kartben commented Jan 24, 2025

btw @nzmichaelh @kholia feel free to claim your Zephyr Maintainer badge here: forms.gle/oCw9iAPLhUsHTapc8 :)

@miggazElquez
Copy link
Contributor

Thanks everyone! I'll get going on the console, ADC, I2C, SPI, and WDT drivers...

Hi @nzmichaelh
I'm planning to work on some drivers for my ch32v303 SoC (SPI, USB, ...). As a lot of these devices are the same in the v003 than in the v303, I wanted to check if you’ve done any work on them already. Just hoping to avoid overlapping efforts !

@cnlohr
Copy link

cnlohr commented Feb 14, 2025

If you're interested ch32v003fun is now ch32fun (main repo will soon be renamed) we have full support for the ch32v303 now.

@nzmichaelh
Copy link
Contributor

Thanks everyone! I'll get going on the console, ADC, I2C, SPI, and WDT drivers...

Hi @nzmichaelh I'm planning to work on some drivers for my ch32v303 SoC (SPI, USB, ...). As a lot of these devices are the same in the v003 than in the v303, I wanted to check if you’ve done any work on them already. Just hoping to avoid overlapping efforts !

@miggazElquez sorry for the delay. Yip, I have drivers for the ADC, IWDT, console, and PWM at https://github.com/nzmichaelh/zephyr/commits/ch32v003/

Have a look in the ch32v-* branches as well.

@Colt-Ma
Copy link

Colt-Ma commented Jul 10, 2025

@nzmichaelh It is necessary to adapt the DMA operation of UART, because the CPU is too late to deal with the receive interruption at a high receive baud rate, and it is easy to lose data

@cfriedt
Copy link
Member

cfriedt commented Jul 10, 2025

@Colt-Ma - this change was merged some time ago. At this point, it's best to file an issue / bug report

https://github.com/zephyrproject-rtos/zephyr/issues/new/choose

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: Done

Development

Successfully merging this pull request may close these issues.