cherry-embedded / CherryUSB

CherryUSB is a tiny, beautiful and portable USB host and device stack for embedded system with USB IP
https://cherryusb.readthedocs.io/
Apache License 2.0
1.21k stars 256 forks source link

usb_hc_dw2.c, dwc2_pipe_transfer, 第278到283行无意义 #111

Closed yangmafu closed 1 year ago

yangmafu commented 1 year ago

第278行开始的代码如下:

    /* make sure to set the correct ep direction */
    if (ep_addr & 0x80) {
        tmpreg |= USB_OTG_HCCHAR_EPDIR;
    } else {
        tmpreg &= ~USB_OTG_HCCHAR_EPDIR;
    }

    /* Set host channel enable */
    tmpreg = USB_OTG_HC(ch_num)->HCCHAR;
    tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
    tmpreg |= USB_OTG_HCCHAR_CHENA;
    USB_OTG_HC(ch_num)->HCCHAR = tmpreg;

此处需要配置HCCHAR寄存器中的EPDIR位。 代码逻辑中,先把EPDIR位的值写到变量tmpreg中,然后从HCCHAR寄存器中读取值到变量tmpreg。这导致前面写到变量tmpreg中的EPDIR配置被覆盖掉。也就是说278行到283行无意义。

改动如下:

    /* Set host channel enable */
    tmpreg = USB_OTG_HC(ch_num)->HCCHAR;
    tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
    tmpreg |= USB_OTG_HCCHAR_CHENA;

    /* make sure to set the correct ep direction */
    if (ep_addr & 0x80) {
        tmpreg |= USB_OTG_HCCHAR_EPDIR;
    } else {
        tmpreg &= ~USB_OTG_HCCHAR_EPDIR;
    }

    USB_OTG_HC(ch_num)->HCCHAR = tmpreg;
sakumisu commented 1 year ago

是的这边是有问题,应该是之前改错了

sakumisu commented 1 year ago

已修正,感谢