Skip to content

Add support for WCH CH32L103 #89451

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

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

Conversation

paulwedeck
Copy link
Contributor

This pr adds support for the ch32l103 SoC and ch32l103evt board.
The code is mostly based on the ch32v208.

paulwedeck added 3 commits May 4, 2025 16:39
Fix clock selection for CH32L103 because it requires setting flash
wait states for higher frequencies.

Signed-off-by: Paul Wedeck <paulwedeck@gmail.com>
Introduces V4C-based CH32L103 SoC similar to CH32V208.
This board features a 32bit CH32L103C8T6 microcontroller similar to other CH32 systems.

Signed-off-by: Paul Wedeck <paulwedeck@gmail.com>
@VynDragon
Copy link
Collaborator

VynDragon commented May 4, 2025

Thanks!
You will need to apply the reorganization in this commit: #87345
Ill go try to get it merged...

Copy link
Collaborator

@nzmichaelh nzmichaelh left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@@ -132,6 +132,16 @@ static int clock_control_wch_rcc_init(const struct device *dev)
}
}

#if defined(CONFIG_SOC_CH32L103)
if(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 72*1000*1000) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

optional: I have something similar in 51cc459

If you want, please pull the change in and make this match the same style.

I'm not worried if you don't as I can fix it when I send my PR out for review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to but the l103 is not yet supported by ch32fun.
I just use the headers for the v208 which does not include the necessary defines (probably because it doesn't apply to the v208).

};

&clk_hse {
clock-frequency = <DT_FREQ_M(25)>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The HSE frequency depends on the crystal on the board, so move this out to the board definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I set it here is because ch32v208.dtsi sets it to a value larger than is supported by the l103.
The board uses a 8MHz crystal and sets the correct frequency in the board dts, so this rather marks the max value instead of the actual value.
Is is this a valid reasoning (for zephyr) or should I remove this part?

};

&flash {
reg = <0x40022000 0x28>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very similar to the definition in ch32v208.dtsi. Is the included file wrong? If so, should this fix be there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this was already wrong for the v208. Should I include a commit here or add a separate pr?

@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Michael Hope <michaelh@juju.nz>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I"m fine if you want to rewrite the copyright here.

drive-push-pull;
slew-rate = "max-speed-10mhz";
};
group2 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

newline gap between child nodes

Copy link
Collaborator

Choose a reason for hiding this comment

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

put through https://tinypng.com/

Copy link

github-actions bot commented Jul 6, 2025

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants