Skip to content

Adding SOC WCH ch32v307 and board scdz ch32v307evt #91702

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

Conversation

SoftwareArchitekt
Copy link

Adding SOC WCH ch32v307 and board scdz ch32v307evt
all remarks from old request are included

dts: add riscv/wch/ch32v307 and packages
wch has provide a ch32v307 soc series
Signed-off-by: SoftwareArchitekt <[email protected]>
adding from scdz the ch32v307evt-board, it is build on a ch32v307vc-soc
which have a risc-v qingKeV4F-Core
Signed-off-by: SoftwareArchitekt <[email protected]>
@@ -18,9 +18,11 @@ GTEXT(__initialize)

SECTION_FUNC(vectors, ivt)
.option norvc
#ifndef SOC_CH32V307
Copy link
Contributor

Choose a reason for hiding this comment

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

If you remove these two lines, you have to change the value written into mtvec (to 0x7 in this case).


flash0: flash@8000000 {
compatible = "soc-nv-flash";
reg = <0x08000000 DT_SIZE_K(480)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Two question about this, related to the change in vector.S:

In my tests, for the ch32v303, without the jump in vector.S to the non-aliased space (0x0800 ....) the code will only work if I put the address of the flash at 0, not 0x08000000. And if I put the jump in vector.S, then I have to put the address at 0x08000000 (which make sense). It seems strange to me that this is different for the ch32v307 ?

Also, without this jump, do you really have access to the full 480 KB ? For me, it should probably be something between 128 KB and 288KB depending on SRAM_CODE_MODE, and probably 288 KB (and 32 KB of RAM) as this is what minichlink do if I recall correctly.

Copy link
Author

Choose a reason for hiding this comment

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

my plan was, to ectract this discussion out of this PR to open a new issue for it. Because in doc CH32FV2x_V3xRM.PDF you can read in chapter 1.3:

Copy link
Author

Choose a reason for hiding this comment

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

The user selects the startup mode after reset by setting the status value of BOOT pins. After the system is reset
or the power is reset, the value of the BOOT pin will be latched again.
The program flash memory, system memory and internal SRAM have different access methods in different
startup modes:
l When it is started up from the program flash memory, the program flash memory address will be mapped
to the 0x00000000 address area and can also be accessed in the start address area 0x08000000.
l When it is started up from the system memory, the system memory address will be mapped to the address
area 0x00000000 and can also be accessed in the original address area 0x1FFFF000.
l When it is started up from the internal SRAM, it can be only accessed from 0x20000000 address area.
When the CH32F2x is started up in this area, it is necessary to set the vector table offset register through
the NVIC controller to remap the vector table to SRAM. For CH32V2x and CH32V3x, such action is not
required.

Copy link
Author

Choose a reason for hiding this comment

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

this means, the memory mirrored address depences on the pins, and with a jump to 0x8000000 you can run in trouble.
What is your proposal?

Copy link
Contributor

Choose a reason for hiding this comment

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

In any case, I think it's important that the code is working, and I think that in the current state it isn't working ? Correct me if I'm wrong.

Maybe I'm understanding it wrong, but with Zephyr I think we are always in the program flash memory. It seems that the "system memory" is not really writable. For the part with the internal SRAM I don't really understand how it works ?
But as we know that we are in program flash memory (we compiled zephyr for it) it is possible to jump to 0x0800 0000.
The downside is that the access to flash should be slower. But anyway, if we are reading the code from the 0-wait area, at 0x0, is should be described as such in the device tree imo, for the address because it doesn't work with the wrong address, and for the size, because if we put 480 then Zephyr won't complain if we have too much code to fit in the 0-wait area.

Or maybe there is a way in Zephyr to describe this situation of 480 Kb of Flash, with a part of it aliased in another place ?

@VynDragon you understand all of this better than me, if you have any advice.

toolchain:
- cross-compile
- zephyr
ram: 64
Copy link
Contributor

Choose a reason for hiding this comment

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

And these two value are incompatible with what is declared in the device tree.

Copy link
Author

Choose a reason for hiding this comment

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

please check again

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
Author

Choose a reason for hiding this comment

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

please check again

bias-pull-up;
};
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Copy link
Author

Choose a reason for hiding this comment

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

please check again

compatible = "gpio-keys";

user_button0: sw0 {
label = "User SW0";
Copy link
Collaborator

Choose a reason for hiding this comment

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

indent is off

Copy link
Author

Choose a reason for hiding this comment

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

please check again

@nordicjm nordicjm requested a review from kartben June 17, 2025 09:15
fix ram size to be aligned with soc, fix some file layouts

Signed-off-by: SoftwareArchitekt <[email protected]>
fix document error for build-docs run

Signed-off-by: SoftwareArchitekt <[email protected]>
@miggazElquez
Copy link
Contributor

When pushing modification, you should rebase your changes to keep only the necessary commits and force push. See https://docs.zephyrproject.org/latest/contribute/guidelines.html#contribution-workflow, 14th bullet point.

Copy link

@miggazElquez
Copy link
Contributor

Which commit you mean?

At first your pull request had two commits, and it was correct. But you pushed two new commits, and these two new commits shouldn't appear, they should be squashed into the first two commit. The contribution guideline will explain this better than me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: RISCV RISCV Architecture (32-bit & 64-bit) platform: WinChipHead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants