Skip to content
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 CH32V20x USB OTG/FS Driver #2362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dragonlock2
Copy link

@dragonlock2 dragonlock2 commented Dec 6, 2023

Describe the PR
Added support for the USB OTG/FS driver found in the CH32V20x microcontrollers, heavily inspired by the CH32V307 driver. While not tested, this driver should also work for the matching IP in the CH32V307.

Note there is an older incomplete PR #1995 that was trying to accomplish something similar.

Additional context
Driver does appear to be working well, I'm currently using it to implement a basic RPC using bulk transfers and 8-channel 16-bit 48kHz audio streaming in dragonlock2/miscboards/wch/rvice_adc.

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

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

sorry still haven't got time to test this out. I am off for TET holidays for a couple of weeks. Will try to review afterwards, thank you for your patient.

@mean00
Copy link

mean00 commented Feb 19, 2024

I did a quick test with CH32V30X chips, it seems to work also there (very minor changes needed because i'm not using wch SDK)
Good job!

@greenscreenflicker
Copy link

I'm just trying to compile the Pull request. I'm documenting here my process.

  1. I'm getting an error in dcd_int_handler(uint8_t rhport) . That a semicolon is missing after a declaration.
    switch (token) {
    case PID_OUT:;
    uint16_t rx_len = USBOTG_FS->RX_LEN;
    update_out(rhport, ep, rx_len);
    break;

@dragonlock2
Copy link
Author

dragonlock2 commented Mar 23, 2024

I'm just trying to compile the Pull request. I'm documenting here my process.

  1. I'm getting an error in dcd_int_handler(uint8_t rhport) . That a semicolon is missing after a declaration.
    switch (token) {
    case PID_OUT:;
    uint16_t rx_len = USBOTG_FS->RX_LEN;
    update_out(rhport, ep, rx_len);
    break;

Some compilers don't like declaring a variable inside a switch/case. Added brackets to fix.

@dragonlock2 dragonlock2 reopened this Mar 23, 2024
@greenscreenflicker
Copy link

I'm just trying to compile the Pull request. I'm documenting here my process.

  1. I'm getting an error in dcd_int_handler(uint8_t rhport) . That a semicolon is missing after a declaration.
    switch (token) {
    case PID_OUT:;
    uint16_t rx_len = USBOTG_FS->RX_LEN;
    update_out(rhport, ep, rx_len);
    break;

Some compilers don't like declaring a variable inside a switch/case. Added brackets to fix.

Fixed by additional semicolon... see PID_OUT... Thanks for the support so far!

@greenscreenflicker
Copy link

greenscreenflicker commented Mar 23, 2024

@dragonlock2 does it support CDC also?

I have the problem that I don't get CDC enumeration. But that's probabbly me beeing a noob on tinyusb.

@dragonlock2
Copy link
Author

I prefer brackets for readability, didn't know a semicolon also works. The driver supports all of the transfer types needed in USB, so this should work for CDC too.

@greenscreenflicker
Copy link

greenscreenflicker commented Mar 23, 2024

Can you please give me some hints why I don't get enumeration. What could I do wrong?
I run it in Freertos, in a seperate task. It looks like this:

void task1_task(void *pvParameters)
{

    board_init();

    // init device stack on configured roothub port
    tud_init(BOARD_TUD_RHPORT);

    if (board_init_after_tusb) {
      board_init_after_tusb();
    }

    while (1) {
      tud_task(); // tinyusb device task
      tud_cdc_n_write_str(0,"Hello, World!\r\n");
      vTaskDelay(10);
    }
}

EDIT: I copied the rest of the code from https://github.com/hathach/tinyusb/tree/master/examples/device/cdc_dual_ports/src

EDIT2: I can assure that it's not the hardware, as it works with a non-tinyusb code.

@dragonlock2
Copy link
Author

@greenscreenflicker let's continue this part of the discussion on #2525 and keep comments here focused on the PR

@greenscreenflicker
Copy link

Please mention in the files, that it only works with some of the devices, having the right module. (H/D in the grafics below)

grafik

@dragonlock2
Copy link
Author

Not sure what @hathach would prefer, but I think the driver names are enough documentation. dcd_ch32_usbfs.c is for the USBFS/OTG_FS IP and dcd_ch32_usbhs.c is for the USBHD IP.

Notably some CH32V20x only have the USBD IP which I believe may be compatible with the STM32 driver.

@ddB0515
Copy link

ddB0515 commented Mar 26, 2024

I would be very interested into this as have 2 boards with v203(CH32V203G6U6 and CH32V203C8U6)
If you need any test let me know but love to have normal USB access with tinyUSB

@greenscreenflicker
Copy link

@ddB0515 Note that CH32V203G6U6 is not supported, while CH32V203C8U6 probbably is.
The naming by wch (@openwch) of the devices in unfortunate.

@ddB0515
Copy link

ddB0515 commented Mar 26, 2024

@greenscreenflicker will CH32V203G6U6 work at least as HID/CDC? as that is supported as USB Device or I'm wrong?

@greenscreenflicker
Copy link

greenscreenflicker commented Mar 26, 2024

@ddB0515 CH32V203G6U6 doesn't work with CDC/HID with the proposed module (see image from me above). I use that MCU also, and have the problem. See here:
#2525 (reply in thread)

@dragonlock2
Copy link
Author

@ddB0515 @greenscreenflicker as I expected the existing dcd_stm32_fsdev.c works for the USBD of CH32V20x. See dragonlock2/miscboards/wch/mouse_jiggler. Let's continue discussion on #2525 and keep this PR focused on the USB OTG/FS driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants