cherryusb_wch icon indicating copy to clipboard operation
cherryusb_wch copied to clipboard

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

Open llinjupt opened this issue 1 year ago • 4 comments

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 avatar Oct 22 '24 04:10 llinjupt

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

llinjupt avatar Oct 22 '24 06:10 llinjupt

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.

sakumisu avatar Oct 22 '24 06:10 sakumisu

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.

llinjupt avatar Oct 22 '24 08:10 llinjupt

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.

sakumisu avatar Oct 22 '24 09:10 sakumisu