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

Merged
merged 11 commits into from
Nov 26, 2024

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
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 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.

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
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>
@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 <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 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
Collaborator

@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
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
Collaborator

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!

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.