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 WCH CH32V307 port #1405
Add WCH CH32V307 port #1405
Conversation
Add WCH mcu submodule Add CH32V307V-R1-1v0 bsp
could you add a build workflow for this? |
Added. I think just adding to the family will be enough? But I think they won't run unless a maintainer approves them to run. |
Yes, i think so. I can approve. |
you need to add the family to the skip files on freertos examples if you don't have the freertos port configured |
USBHSD->HOST_CTRL = USBHS_PHY_SUSPENDM; | ||
|
||
USBHSD->CONTROL = 0; | ||
#if 1 |
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.
Shouldn't this be behing the BOARD_DEVICE_RHPORT_SPEED
variable?
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've just tested, and the device doesn't correctly enumerate when set to Full Speed mode.
Something to look into, as a placeholder I'll have it throw an error if BOARD_DEVICE_RHPORT_SPEED==OPT_MODE_FULL_SPEED
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.
looks good overall, only missing the docs, but that can be added after
Just for easier reference, you mention initial driver, what is missing currently? |
I've not tested with a Full Speed only host/hub.
I've also not done extensive testing yet, I've only had the dev board for <1week. |
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.
Looks good to me, let's wait for @hathach to look at this
I should also mention. The CH32V307 has 2 separate USB interfaces/peripherals, One is FS/OTG and then one is HS/FS/Device/Host. These use different pins on the device, and have completely different register sets. This port is only targeting the High Speed peripheral. |
The CH32V307 USB FS/OTG interface looks to be identical to, or else very
very similar to, the STM32 USB FS/OTG interface on e.g. the STM32F103, so
it would probably be fairly simple to add support. (I know, easy for me to
say.) There are also STM32 parts that have basically the same dual USB (FS
& HS) as the CH32V307.
…On Tue, Mar 22, 2022 at 6:09 PM Greg Davill ***@***.***> wrote:
I should also mention. The CH32V307 has 2 separate USB
interfaces/peripherals, One is FS/OTG and then one is HS/FS/Device/Host.
These use different pins on the device, and have completely different
register sets.
This port is only targeting the High Speed peripheral.
—
Reply to this email directly, view it on GitHub
<#1405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADLYXVRXJSE627I7IEUAXDVBJOKRANCNFSM5RH3PL2A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
sounds like it might have a synopsys usb core, very popular among MCUs, it might be compatible with the |
I've been digging into this a tad more, there is actually 4 different USB peripherals in the CH32FV32x_V3x Reference manual.
Config summary
*V305 should be compatible with this port, but hasn't been released yet. So sounds like it should be possible to support some of these using the Can you point me at the STM32 devices that have a similar HS/FS pair? The only ones I've seen/worked with were definitely a different register set, and needed an external ULPI PHY. |
The technical director at WCH is also very open, you can contact him through twitter maybe they could even send you one @hathach |
yeah, I saw that board as well, but I will wait for a cheaper option. I won't have time to do anything with it anything soon anyway.
hard to tell, I never look at usb 3.0 specs, may need to update my own knowledge first. Will do that later when I have both the board and time.
that is too much hassle for an dev board, and there is no guarantee that I would spend anytime on it to begin with. Let ch569 have its own PR. We should better focus on v307 on this PR instead. |
Oh i wasn't trying to bundle the ch569 on here at all, just a suggestion for a possible way of getting a dev board, since you were interested |
I'm planing to poke around with the ch565/ch569 at some point too. Have some of the ICs. Let me know when you get your CH32V307 devkit. Loading firmware currently requires the use of a "patched" openOCD, which can be downloaded as part of the MounRiver Toolchain (http://www.mounriver.com/download). I hope that eventually support for the WCH-Link and this IC are upstreamed into openOCD. |
thanks for your suggestion.
thanks for the hint, it probably got delivered in a week or so, will let you know by then. |
my ch32v307 dev board has arrived, however, I am currently busy catching up with paid work and won't probably look at this pr this week. I will try my best to review this as soon as I could. Please be patient. |
@hathach any idea if you'd have time to look into this PR in the near future? |
this PR is on my TODO, though I am currently busy with other paid work. Please be patient in the meanwhile. |
Apparently, the dev board for the CH569 is now available at a reasonable price on LCSC |
thanks @perigoso (late response again), I actually ordered this, but it is now kept in the custom. and it has been a PITA with custom to get this particular package. |
@hathach I'm sure you're busy but I'd love to see this PR progress when you have time! There's a PR that has begun to add support for the v307 to MicroPython and I'd like to add TinyUSB to the mix. I have a v307 dev board so if I can help test just let me know. |
yeah, sure thing. I was waiting for wch devkit to test this out (it takes 2 months to ship) and I totally forgot about this one. Will test this out as soon as I could. |
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.
special thanks to @gregdavill for this brilliant PR and others joining this discussio, and sorry for my huge delay in reviewing and testing this. I struggled a bit with openocd on linux, but finally got everything running. (also put some doc to the family.mk for building it). USB highspeed work well with cdc and msc (hid example has some hiccups but we will fix it later on).
CH32V307 is really an interesting mcu with dual usb controllers, one of which is highspeed, and bundle lots of other great peripherals as well. I am not too familiar with the chip and only make some minor tweak (mostly bsp and rename). Hopefully we could fully support this mcu in the future with more follow-up PRs.
Thanks @hathach! I think I might have found/fixed some of those issues.. I know I hit some issues trying to use multiple IN/OUT endpoints, after some adjustments to the endpoint handling code it was working nicely on a local project branch. It's been a bit of time since I did the initial work, but supporting the FS PHY I think should be easy, since it's similar/the same as the STM's one. |
That is great to hear, I wished I could have more time to looked into ch32v307 dcd code and do more testing with other class drivers as well.
Yeah, you are right. I just checked, it is similar to the stm fsdev driver. Ideally we should generalize the driver ( shared .c file like dwc2). Though I think we can start with duplicating driver first to make sure hardware is all working. I can actually help with this if I manage the time. Though I guess there is no rush to support FS since most people would prefer to use the HS port for device. PS: Thanks again for the great work on this. |
Hi, I am curious if there is any progress on working on both ports at the same time? I have really interesting case where I need host on fs, and device on hs |
Describe the PR
Add initial driver/port for the CH32V307 series from WCH. This is a RISCV (rv32imac) with integrated High Speed USB PHY.
The targets the WCH development board
CH32V307V-R1-1v0
, which is a lowish cost ~$10 board from LCSC.Additional context
The
xpack-riscv-gcc
compiler is used. The official wch packaged gcc appears to have some custom changes to support the interrupt controller in this part that handles hw stack save/restore. Fortunately that's reasonably easy to work around, so that a vanilla compiler works.Right now I've been testing this port with the
cdc_msc
example, so I thought I'd open up the PR.I'd like to help get this merged so that others can use tinyusb on this new IC too, it's a pretty nice combination pairing the high-speed PHY inside a lower cost microcontroller,