cherry-embedded / CherryUSB

CherryUSB is a tiny and portable USB Stack (device & host) for embedded system with USB IP
https://cherryusb.readthedocs.io/
Apache License 2.0
1.17k stars 249 forks source link

[dwc2 dc] EP0 is bi-direction? #131

Closed wosayttn closed 11 months ago

wosayttn commented 11 months ago

Hi,

These if conditional sentences are unnecessary in these function, right? Or, we should ignore the EP0 checking?

int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
{
...
    if (USB_OTG_INEP(ep_idx)->DIEPCTL & USB_OTG_DIEPCTL_EPENA)
    {
        return -2;
    }
...
}

int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
{
...
    if (USB_OTG_OUTEP(ep_idx)->DOEPCTL & USB_OTG_DOEPCTL_EPENA)
   {
        return -2;
    }
...
}
sakumisu commented 11 months ago

This checks if ep transfers done, it is necessary.

wosayttn commented 11 months ago

This checks if ep transfers done, it is necessary.

After appending "ignore ep_idx=0", the CONFIG_USB_DWC2_DMA_ENABLE mode is workable.

int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
{
    ....
    if (ep_idx && (USB_OTG_INEP(ep_idx)->DIEPCTL & USB_OTG_DIEPCTL_EPENA))
    {
        return -2;
    }
    ....
}
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
{
    ...
    if (ep_idx && (USB_OTG_OUTEP(ep_idx)->DOEPCTL & USB_OTG_DOEPCTL_EPENA)) //Endpoint enable?
    {
        return -2;
    }
    ...
}
sakumisu commented 11 months ago

Not adding works in mine.

sakumisu commented 11 months ago

You can see my stm32 demo, using stm32f4 and stm32h7 with dma mode. It works.

sakumisu commented 11 months ago

USB_OTG_DIEPCTL_EPENA will be set when start reading or writing and be cleared when transfers done.

sakumisu commented 11 months ago

Certainly, this check is not necessary.

wosayttn commented 11 months ago

Thanks comment, I will check other in our porting. CherryUSB is good implementation. Good job.

sakumisu commented 11 months ago

Thanks, maybe this check can disable?