-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Add support for WCH CH32V303 #87125
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 support for WCH CH32V303 #87125
Conversation
The following west manifest projects have changed revision in this Pull Request:
✅ All manifest checks OK Note: This message is automatically posted and updated by the Manifest GitHub Action. |
@VynDragon if you want to take a look, as this is based on your code for the ch32v208. |
CONFIG_CONSOLE=y | ||
CONFIG_UART_CONSOLE=y | ||
|
||
CONFIG_FLASH_BASE_ADDRESS=0x08000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't put that, CONFIG_FLASH_BASE_ADDRESS
will be set to the address of the flash in the device tree (currently 0), and minichlink fail to flash at the address 0. But if I change the address in the device tree, I can flash but Zephyr then fails to boot, I don't really know why. @VynDragon you didn't have this issue on the 208 ?
What would be the way to solve this ? I saw that some boards did change CONFIG_FLASH_BASE_ADDRESS
in their defconfig, so that's why I put it there, but maybe it should be in another place ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh so that's why the west flash didnt work! Ill look into it, might be a matter of fixing the runner instead of this, otherwise figuring how to make it boot in non aliased space would make it easier to use the full flash so ill see for both issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it works for me when i set
flash0: flash@8000000 {
compatible = "soc-nv-flash";
reg = <0x08000000 DT_SIZE_K(128)>;
};
after udpating minichlink and using minichlink -w build/zephyr/zephyr.bin 0x0
But west flash still doenst work so no clue what's going on there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a it's the -b for the runner, need to disable reset for ch32v208
Edit:" which is easy to say but almost impossible to do, i'm on my second PR just to be able to pass --no-reset in the board args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a frequency issue, for some reason on CH32V208 it works at 144MHz, but they 'highly recommend' using 120M in the RM for the F/V20x/30x serie. You added the long jump code in the ASM right?
It's only for the linking mapping within that space, otherwise the space is accessible without booting into it. (eg if your address space in zephyr is 0x08000000 it will only run in non-aliased, but if it's 0x0 it will only run in aliased due to the long jump / short jump things)
For flashing
Me neither, it's supposed to flash to 0x08000000 so with dt-flash=y and the flash address set to that and the long jump code, or 0x0 with no long jump and 0x08000000 flash address still. I think it changed between old and new minichlink version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So before answering to you I wanted to test it one last time and now it works, I don't know what I did wrong during my tests before... because I'm quite sure I tested with the long jump, but maybe I had changed something else, I don't know. Anyway it works now, so I modified my PR to include it, it seems cleaner to me than passing the flash address directly to minichlink.
I still don't really understand the point of the long jump, even if it's clearly necessary : if the address space in zephyr is at 0x08000000, why do we need the long jump to get into non-aliased mode ? Because when testing it seems like we boot in non-aliased mode with the address space at 0x08000000, but maybe the debuggers are just confused by all this aliasing and are lying to me. (I would like to add a comment explaining this long jump things but as I don't totally understand it yet...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't really understand the point of the long jump
It's so the pc is in the right zone when the short jumps happen, eg that the pc is in the area expected when it tries to do a short jump, there is also the matter of the gp pointer, and a couple other thing i believe break when operated in not the expected area. In practice it crashes if you run it without that long jump.
Also make sure to set frequency to 120 if you use the full flash! It might be your spurious issue
Because when testing it seems like we boot in non-aliased mode
It always boot in the aliased zone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It always boot in the aliased zone?
I think that I was fooled by the debugger, I'm not sure about what is happening but with the debugger even without the longjump I'm in non aliased space (pc = 0x0800...). I think it's not really executing the first instructions, it seems like it's just jumping to __start directly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, I dont know what could be going on
soc/wch/ch32v/qingke_v4_vector.S
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this file should also be located in qinke_v4f-directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this file I'm waiting on #87345 to be merged to rebase my code, so this file will end up in a folder for all Qingke-V4
/** | ||
* @brief Type to hold a pin's pinctrl configuration. | ||
*/ | ||
struct ch32v303_pinctrl_soc_pin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this struct will also be used by ch32v307. This means the naming would be better qingke_v4f_pin....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this, it's in the folder for all qingke v4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you told, it is in folder for all qinke v4, so a name of a soc (ch32v303) is maybe wrong. better to use a struct qinke_v4_pinvtrl_soc_pin {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the PR deduplicating the files was changed to just focus on the changes for the v208, so I created another PR deduplicating all the files, with the idea that when one of these two PR is merged, I would just rebase the other.
About the specific point, for the pinctrl file, naming it qingke_v4_something is maybe not the best idea, see this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to not naming it after the microarchitecture, as the pinctrl is a feature of the SoC, not the processor.
Update hal_wch. As the hal upstream changed name, there is now a name conflict. Rename ch32fun.h to hal_ch32fun.h to fix this conflict. Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
Adds support for building an image for the ch32v303. Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
Adds support for the CH32V303EVT board, based on the CH32V303 soc. Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
|
The deduplication of the files is now in #90007; when one of these is merged I will rebase the other. |
Overview | ||
******** | ||
|
||
The `WCH`_ CH3V303VCT6_EVT hardware provides support for QingKe 32-bit RISC-V4F |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you happen to have a link to the schematic for the board? It's hard to check if the pin assignments etc are correct without it.
Overview | ||
******** | ||
|
||
The `WCH`_ CH3V303VCT6_EVT hardware provides support for QingKe 32-bit RISC-V4F |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the name seems to be "CH32V303VCT6-EVT": https://www.aliexpress.com/item/1005005257256239.html
Overview | ||
******** | ||
|
||
The `WCH`_ CH3V303VCT6_EVT hardware provides support for QingKe 32-bit RISC-V4F |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it's a QingKe-V4F 32-bit RISC-V, not a RISC-V4F.
Hardware | ||
******** | ||
|
||
The QingKe 32-bit RISC-V4F processor of the WCH CH32V303VCT6_EVT is clocked by an external |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto re: RISC-V4F.
clk_hse: clk-hse { | ||
#clock-cells = <0>; | ||
compatible = "wch,ch32v00x-hse-clock"; | ||
clock-frequency = <DT_FREQ_M(32)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the HSE clock frequency is board specific, so probably shouldn't be set here.
}; | ||
|
||
&cpu0 { | ||
clock-frequency = <DT_FREQ_M(144)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this was reduced to 120 MHz on the ch32v203 to allow using the extra, higher wait state flash. Either reduce this or shrink the flash to the 256 KiB of low-wait state flash.
/** | ||
* @brief Type to hold a pin's pinctrl configuration. | ||
*/ | ||
struct ch32v303_pinctrl_soc_pin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to not naming it after the microarchitecture, as the pinctrl is a feature of the SoC, not the processor.
zephyrproject-rtos#87125 renamed the `ch32vfun.h` header but missed some of the drivers. Fix. Signed-off-by: Michael Hope <michaelh@juju.nz>
I've sent #90438 to fix the other drivers after the ch32fun -> hal_ch32fun update. |
zephyrproject-rtos#87125 renamed the `ch32vfun.h` header but missed some of the drivers. Fix. Signed-off-by: Michael Hope <michaelh@juju.nz>
This PR add support for the SoC CH32V303 from WCH, and for the board CH32V303EVT.
Depends on #85395 for the support of
west flash
.