Skip to content

soc: wch: Deduplicate common files across ch32v socs #90007

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 2 commits into
base: main
Choose a base branch
from

Conversation

miggazElquez
Copy link
Contributor

Moves shared files from multiple ch32v SoCs into a new common/ directory to eliminate duplication.

I only de-duplicated pinctrl_soc.h for the qingke_v4x socs, because the pin controller is not the same between the qingke_v2a (ch32v003) and the qingke_v2c (other ch32v00x).

@@ -10,7 +10,7 @@
/**
* @brief Type to hold a pin's pinctrl configuration.
*/
struct ch32v208_pinctrl_soc_pin {
struct qingke_v4_pinctrl_soc_pin {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should do this. The pinmux is a feature of the SOC, not the microarchitecture.

For example, both the CH32V003 and CH32V006 are QingKe V2, but they have different pinmux.

I'm concerned this PR will have the same issues as the previous one where there's lots of rebasing due to differing opinions. Should we work this out in a bug or chat first?

@@ -10,7 +10,7 @@
/**
* @brief Type to hold a pin's pinctrl configuration.
*/
struct ch32v208_pinctrl_soc_pin {
struct qingke_v4_pinctrl_soc_pin {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should do this. The pinmux is a feature of the SOC, not the microarchitecture.

For example, both the CH32V003 and CH32V006 are QingKe V2, but they have different pinmux.

I'm concerned this PR will have the same issues as the previous one where there's lots of rebasing due to differing opinions. Should we work this out in a bug or chat first?

Copy link
Contributor Author

@miggazElquez miggazElquez May 19, 2025

Choose a reason for hiding this comment

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

I'm concerned this PR will have the same issues as the previous one where there's lots of rebasing due to differing opinions. Should we work this out in a bug or chat first?

Maybe, I figured having a starting point could help us discuss it but if you prefer we can talk about it on another place, I have no preference.

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 don't think we should do this. The pinmux is a feature of the SOC, not the microarchitecture.
For example, both the CH32V003 and CH32V006 are QingKe V2, but they have different pinmux.

I understand this, that's why I didn't move them. For now all qingke_v4-based soc are part of the ch32v20x/30x series and they all have the same pinmux, but if there is another SoC with a qingke_v4 it would indeed be a problem.
But it would still be good to deduplicate this file no ?

Choose a reason for hiding this comment

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

CH32V006

the 003 is a V2A and the 006 is a V2C. So different Cores, they also have different instruction sets. (Infos you can find in datasheet on capital 1.4.1)
With this background it makes sence to move from SOC to core-naming.

@@ -3,8 +3,8 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_sources(
soc_irq.S
vector.S
../common/qingke_v2x/soc_irq.S
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think a directory should refer to a different directory. I can't find any examples of this in the other socs.

As soc_irq.S is fairly trivial, shall we just denormalise it across all SOCs?

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 don't think a directory should refer to a different directory. I can't find any examples of this in the other socs.

There is some exemples, like a some espressif SoCs, one nxp, ... I don't see how to deduplicate files without doing that.

As soc_irq.S is fairly trivial, shall we just denormalise it across all SOCs?

True, I will do it.

@miggazElquez
Copy link
Contributor Author

I rebased to include the ch32v303. For the pinctrl file, I moved it back to the folder for each SoC series, but renamed the one in the qingke_v4f folder to 30x from 303, that way it can be re-used by other 30x SoC.

Does it seems like a good solution ?

Copy link

@SoftwareArchitekt SoftwareArchitekt left a comment

Choose a reason for hiding this comment

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

I just see a problem with the vector.s - file for qinke4. Here i already told in last pr (adding ch32v303), that the 2 assembly lines not work on my ch32v307. Means, we need here a change.

@miggazElquez
Copy link
Contributor Author

I can't find your message about vector.S, what was the problem ?

@SoftwareArchitekt
Copy link

I can't find your message about vector.S, what was the problem ?

with the 2 lines
lui x5, 0x8000
jr 0x8(x5)
j __start
before j __start my system is not initialize right (printk is not working for example). When I remove both, everything is fine. When I understand the commands, you are doing double the jump, never reach the j __start, because jumping before to the __start. right?

@miggazElquez
Copy link
Contributor Author

The goal of these lines is to go from aliased space (adress at 0x00....) to non-aliased space (0x80...), to use the full flash. So jr 0x8(x5) should jump right to the next line ( j __start), but in non aliased space. It's strange that it doesn't work for you, I think the 307 and the 303 should work in the same way ?

@SoftwareArchitekt
Copy link

The goal of these lines is to go from aliased space (adress at 0x00....) to non-aliased space (0x80...), to use the full flash. So jr 0x8(x5) should jump right to the next line ( j __start), but in non aliased space. It's strange that it doesn't work for you, I think the 307 and the 303 should work in the same way ?

Why not in the same way like all the other implementation with just the j __start? For me it is also strange

@miggazElquez
Copy link
Contributor Author

Because the processor start in aliased space, with only limited amout of memory available. So we need to jump to non aliased space if we want the full memory space.

@kartben kartben closed this May 27, 2025
@tomi-font tomi-font reopened this May 28, 2025
Moves shared files from multiple ch32v SoCs into a new `common/`
directory to eliminate duplication.

Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
Rename the struct ch32v303_pinctrl_soc_pin to ch32v30x_pinctrl_soc_pin
to allow the same struct to be used for other SoC of the series.

Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
Copy link

Please retry analysis of this Pull-Request directly on SonarQube Cloud

@miggazElquez miggazElquez requested a review from nzmichaelh June 4, 2025 08:06
@miggazElquez
Copy link
Contributor Author

@nzmichaelh Could you revisit this ?

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.

5 participants