Skip to content

wch: Add initial support for CH32H417 - #1027

Open
So1aric wants to merge 14 commits into
ZigEmbeddedGroup:mainfrom
So1aric:ch32h417
Open

So1aric wants to merge 14 commits into
ZigEmbeddedGroup:mainfrom
So1aric:ch32h417

Conversation

@So1aric

@So1aric So1aric commented Sep 6, 2026

Copy link
Copy Markdown

This draft adds initial support for the CH32H417. Currently, I can generate a flashable binary in which the V3F core wakes up the V5F and toggles PC2, while the V5F toggles PC3.
However, I'm not quite satisfied with the build system yet. Since the firmware for the two cores must be compiled separately, the add_firmware call should somehow accept two source paths. For now, I've added addDualCoreFirmware in the port's build.zig as a workaround — I'm not sure whether this is the right approach, so feedback is welcome.
The HAL is still unfinished, and system_init remains to be implemented.
That said, I'd like to settle on the build system design first before moving on to the remaining implementation.

@So1aric

So1aric commented Sep 6, 2026

Copy link
Copy Markdown
Author

#1023

@So1aric
So1aric marked this pull request as ready for review September 15, 2026 14:44
@So1aric
So1aric marked this pull request as draft September 15, 2026 14:44
@So1aric
So1aric marked this pull request as ready for review September 15, 2026 14:45
@mattnite

Copy link
Copy Markdown
Contributor

Hey! This is looking really great, thank you for putting time into a contribution. To what extent did you test this on your hardware, and are able to fetch the SVD through a dependency?

@Grazfather

Copy link
Copy Markdown
Collaborator

Looks good. Is this ready to review? There are some remaining TODOs and some commented out code. TODOs are OK if they are not needed to run the examples, but ideally you'd file an issue for them and reference them in the comment.

You'll also have to rebase.

@So1aric

So1aric commented Sep 16, 2026

Copy link
Copy Markdown
Author

Hi!

To what extent did you test this on your hardware, and are you able to fetch the SVD through a dependency?

I’ve only run the blinky example on a nanoCH32H417. Since UART isn’t implemented yet, validation is currently limited to GPIO/LED behavior. I found the SVD in MRS2, but it contained a few bugs; I’m using the ch32-rs patches as a base and added local fixes for STK, GPIO speed, and ISR-related fields.

Is this ready to review?

Yes, I suppose.

There are some remaining TODOs and some commented out code.

The TODOs are intentional for now: a few are possible code-duplication cleanups, and the rest depend on hardware details/features I haven’t verified yet. I've clean-up some of the commented-out code.

Comment thread examples/wch/ch32h/build.zig Outdated
Comment thread port/wch/ch32h/src/cpus/qingkev3f.zig Outdated
Comment thread port/wch/ch32h/src/hals/gpio.zig Outdated
Comment thread port/wch/ch32h/build.zig Outdated
Comment thread examples/wch/ch32h/src/blinky/v5f.zig
Comment thread port/wch/ch32h/src/hals/gpio.zig Outdated
Comment thread port/wch/ch32h/src/cpus/main.zig Outdated
LED toggling works, but dual-core untested.
Switch to b.addRunArtifact and add_firmware.
Add PLL and basic interrupt support and refine
gpio relevant code.

Now implement a blinky example which showcases
interrupt, clock and gpio usage.

Note that gpio speed and pull configuration is
left unimplemented.
Add priority and allocation (to specific core).
Previously the instructions are placed in flash,
causing ~27cycles delay. Now the instructions are
copied from flash to ram at startup, which solves
the issue.
Now gpio use read, put and toggle. Refine some
comments. Move interrupt relevant code from
blinky to its own example.
This allows comptime generate pin configuration.
@So1aric So1aric mentioned this pull request Sep 18, 2026
@So1aric

So1aric commented Sep 18, 2026

Copy link
Copy Markdown
Author

I believe it's ready for review.

@Grazfather Grazfather changed the title Draft: Add initial support for CH32H417 (#1023) wch: Add initial support for CH32H417 Sep 18, 2026
Comment thread examples/wch/ch32h/src/blinky_v5f.zig Outdated
@So1aric
So1aric requested a review from Grazfather September 19, 2026 08:15

@Grazfather Grazfather left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why did you rename clocks to clock?

@So1aric

So1aric commented Sep 19, 2026

Copy link
Copy Markdown
Author

My thinking was just that the other modules here are all singular (gpio, time, pin), so clock felt more consistent. But on second thought plural probably makes more sense (it includes a lot of clocks 🤔). should I change it back to clocks?

@Grazfather

Copy link
Copy Markdown
Collaborator

Yeah, we'd prefer if it matches the other HALs.

Other than that, this looks good. You tested both examples?

@So1aric

So1aric commented Sep 20, 2026

Copy link
Copy Markdown
Author

Yeah, we'd prefer if it matches the other HALs.

I've reverted it.

You tested both examples?

Yes, here's how they behave:
example

@So1aric

So1aric commented Sep 22, 2026

Copy link
Copy Markdown
Author

These ports are not running unit tests in CI:
wch/ch32h
These ports are not building examples in CI:
wch/ch32h

    - name: wch/ch32v
      run: zig build test
      working-directory: port/wch/ch32v

Should I add ch32h after this in .github/workflows/ports.yml?

@Grazfather

Copy link
Copy Markdown
Collaborator

Yes please!

@mattnite

Copy link
Copy Markdown
Contributor

So just a couple things here:

  • We need a corresponding examples dir for the port, just blinky is fine for now.
  • Add a "test" step to the port. It'd fine if it's just a:
_ = b.step("test", "");

I just want that wired up so that if/when tests are added, no one has to deal with CI scripting.

@Grazfather

Copy link
Copy Markdown
Collaborator

Ah yeah sorry @So1aric, I agree with Matt. Can you move those two blinky files into something like a ch32h417_only/ subdirectory?

@So1aric

So1aric commented Sep 28, 2026 •

Copy link
Copy Markdown
Author

I'm not very familiar with Zig's test setup. Should I just add _ = b.step("test", ""); directly in build()? I couldn't find a reference for this in the other ports.

Edit: done.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants