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

Faile to get the usb string desc when the len is 64. #13

Open
llinjupt opened this issue Oct 22, 2024 · 4 comments
Open

Faile to get the usb string desc when the len is 64. #13

llinjupt opened this issue Oct 22, 2024 · 4 comments

Comments

@llinjupt
Copy link

Hi Cherry,

First of all thanks for your hard effort to build this helpful software USB stack.

I tried the cherryusb_wch\examples\usb_device\cdc_acm demo on CH32V307 and it worked.
But after changing the usb string desc to make it exactly 64 (EP0_MAX_PACKET), PC failed to retrive these strings.

static const uint8_t cdc_descriptor[] = {
    USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
    USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
    CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, 0x02),
    ///////////////////////////////////////
    /// string0 descriptor
    ///////////////////////////////////////
    USB_LANGID_INIT(USBD_LANGID_STRING),
    ///////////////////////////////////////
    /// string1 descriptor
    ///////////////////////////////////////
    0x14,                       /* bLength */
    USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
    'C', 0x00,                  /* wcChar0 */
    'h', 0x00,                  /* wcChar1 */
    'e', 0x00,                  /* wcChar2 */
    'r', 0x00,                  /* wcChar3 */
    'r', 0x00,                  /* wcChar4 */
    'y', 0x00,                  /* wcChar5 */
    'U', 0x00,                  /* wcChar6 */
    'S', 0x00,                  /* wcChar7 */
    'B', 0x00,                  /* wcChar8 */
    ///////////////////////////////////////
    /// string2 descriptor
    ///////////////////////////////////////
    0x40,                       /* bLength */ // Enlarge it to 64-byte len
    USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
    '0', 0x00,                  /* wcChar0 */
    '1', 0x00,                  /* wcChar1 */
    '2', 0x00,                  /* wcChar2 */
    '3', 0x00,                  /* wcChar3 */
    '4', 0x00,                  /* wcChar4 */
    '5', 0x00,                  /* wcChar5 */
    '6', 0x00,                  /* wcChar6 */
    '7', 0x00,                  /* wcChar7 */
    '8', 0x00,                  /* wcChar8 */
    '9', 0x00,                  /* wcChar9 */
    '0', 0x00,                  /* wcChar0 */
    '1', 0x00,                  /* wcChar1 */
    '2', 0x00,                  /* wcChar2 */
    '3', 0x00,                  /* wcChar3 */
    '4', 0x00,                  /* wcChar4 */
    '5', 0x00,                  /* wcChar5 */
    '6', 0x00,                  /* wcChar6 */
    '7', 0x00,                  /* wcChar7 */
    '8', 0x00,                  /* wcChar8 */
    '9', 0x00,                  /* wcChar9 */
    '0', 0x00,                  /* wcChar6 */
    ///////////////////////////////////////
    /// string3 descriptor
    ///////////////////////////////////////
    0x40,                       /* bLength */ // Enlarge it to 64-byte len
    USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ 
    '0', 0x00,                  /* wcChar0 */
    '1', 0x00,                  /* wcChar1 */
    '2', 0x00,                  /* wcChar2 */
    '3', 0x00,                  /* wcChar3 */
    '4', 0x00,                  /* wcChar4 */
    '5', 0x00,                  /* wcChar5 */
    '6', 0x00,                  /* wcChar6 */
    '7', 0x00,                  /* wcChar7 */
    '8', 0x00,                  /* wcChar8 */
    '9', 0x00,                  /* wcChar9 */
    '0', 0x00,                  /* wcChar0 */
    '1', 0x00,                  /* wcChar1 */
    '2', 0x00,                  /* wcChar2 */
    '3', 0x00,                  /* wcChar3 */
    '4', 0x00,                  /* wcChar4 */
    '5', 0x00,                  /* wcChar5 */
    '6', 0x00,                  /* wcChar6 */
    '7', 0x00,                  /* wcChar7 */
    '8', 0x00,                  /* wcChar8 */
    '9', 0x00,                  /* wcChar9 */
    '0', 0x00,                  /* wcChar6 */

#ifdef CONFIG_USB_HS
    ///////////////////////////////////////
    /// device qualifier descriptor
    ///////////////////////////////////////
    0x0a,
    USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
    0x00,
    0x02,
    0x02,
    0x02,
    0x01,
    0x40,
    0x01,
    0x00,
#endif
    0x00
};

Obviously, it is a ZLP issue which is very common to encounter. After checking the code of CherryUSB (usbd_core.c), seems that it has already handled ZLP case. Any idea? Look forward to your feedback. Thanks in advance.

@llinjupt
Copy link
Author

llinjupt commented Oct 22, 2024

More info: cherryusb_stm32 doesn't have this issue. It seems that this issue's related to the platform.

@sakumisu
Copy link
Contributor

More info: cherryusb_stm32 doesn't have this issue. It seems that this issue's related to the platform.

Yes, maybe ep0 toggle flag issue, but we do not support wch chip now, you can attach breakpoint in usbd_ep_start_write when data_len=0 to check.

@llinjupt
Copy link
Author

More info: cherryusb_stm32 doesn't have this issue. It seems that this issue's related to the platform.

Yes, maybe ep0 toggle flag issue, but we do not support wch chip now, you can attach breakpoint in usbd_ep_start_write when data_len=0 to check.

Yes, your hint is valuable. When there needs a ZLP, it should do ep0_tx_data_toggle ^= 1 instead of ep0_tx_data_toggle = true. I hope this could help others.

@sakumisu
Copy link
Contributor

More info: cherryusb_stm32 doesn't have this issue. It seems that this issue's related to the platform.

Yes, maybe ep0 toggle flag issue, but we do not support wch chip now, you can attach breakpoint in usbd_ep_start_write when data_len=0 to check.

Yes, your hint is valuable. When there needs a ZLP, it should do ep0_tx_data_toggle ^= 1 instead of ep0_tx_data_toggle = true. I hope this could help others.

Thank you for your valuable information, for wch support, to be continue in the future, maybe.

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

No branches or pull requests

2 participants