DeqingSun / ch55xduino

An Arduino-like programming API for the CH55X
GNU Lesser General Public License v2.1
439 stars 86 forks source link

Low Speed USB - Device Descriptor Fails #140

Closed Saatvik-Aggarwal closed 7 months ago

Saatvik-Aggarwal commented 1 year ago

When editing the USBDeviceCfg function in USBhandler.c to use Low Speed USB, the communication does not work. I've been trying to add support for lower clock frequencies down to 1.5MHz so others can save power, but any frequencies under 6MHz require low speed USB, which does not work. I've tested on the CH552G.

Here is my version

void USBDeviceCfg()
{
    USB_CTRL = 0x00;                                                           //Clear USB control register
    USB_CTRL &= ~bUC_HOST_MODE;                                                //This bit is the device selection mode
    USB_CTRL |=  bUC_DEV_PU_EN | bUC_INT_BUSY | bUC_DMA_EN;                    //USB device and internal pull-up enable, automatically return to NAK before interrupt flag is cleared during interrupt
    USB_DEV_AD = 0x00;                                                         //Device address initialization
         USB_CTRL |= bUC_LOW_SPEED;
         UDEV_CTRL |= bUD_LOW_SPEED;                                                //Run for 1.5M
    //USB_CTRL &= ~bUC_LOW_SPEED;
    //UDEV_CTRL &= ~bUD_LOW_SPEED;                                             //Select full speed 12M mode, default mode

#if defined(CH551) || defined(CH552) || defined(CH549)
    UDEV_CTRL |= bUD_PD_DIS;                                                     // Disable DP/DM pull-down resistor
#endif
#if defined(CH559)
    UDEV_CTRL = bUD_DP_PD_DIS;                                                     // Disable DP/DM pull-down resistor
#endif
    UDEV_CTRL |= bUD_PORT_EN;                                                  //Enable physical port
}

I get this error: "String Descriptor for index 2 not available while device is in low power state." If I remove the string descriptors, I get device descriptor request failed.

DeqingSun commented 1 year ago

I haven't used low speed for a long time. I don't remember clearly but you may need to change descriptor from USB 2.0 to 1.1 or 1.0.

Another thing is, the CDC need bulk transfer which is not officially supported in the low speed mode. The problem also happens in the VUSB applications on AVR chips. Some USB hub chip will not be that strict and you can put one in between your microcontroller and computer to make it work.

An easy way to confirm this issue is to run a HID example to see if your computer can recognize the device. As the HID ones are based on interrupt transfer.

usbman01 commented 1 year ago

try to change DEFAULT_ENDP0_SIZE. If i remember correctly only 0x08 is allowed for low speed.

DeqingSun commented 7 months ago

Close for inactivity.