This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52840 USB MSD without optimizations

Hello,

I am currently trying to make an MSD RAM disk with nrf52840 nRF5_SDK_14.0.0 with O0 optimization level. And had no success. For some reason in Keil example O3 is used. If I set O0 then it stops working. It looks like EP1 gets stalled and no bulk data is process while trying to format the disk. Also the msc example with no changes fails some USBCV MSD tests. I tried to apply a strange fix in app_usbd.c ln:1261:

for (uint8_t j = 0; j < ep_count; ++j)
{
    /*Clear stall for every endpoint*/
    app_usbd_class_ep_conf_t const * p_ep = app_usbd_class_iface_ep_get(p_iface, j);

    if (nrf_usbd_dtoggle_get(p_ep->address) != NRF_USBD_DTOGGLE_DATA0)
    {
        nrf_usbd_dtoggle_set(p_ep->address, NRF_USBD_DTOGGLE_DATA0);
    }

    //if (NRF_USBD_EPISO_CHECK(p_ep->address) == 0)
    //{
        nrf_drv_usbd_ep_stall_clear(p_ep->address);
    //}

}

It looked like set interface request should clear all ep status. And it looks like it helped to pass USBCV MSD tests, but still Windows is unable to format the disk and copy files with the same ep1 stall problem.

So there are two main questions why does it stop working without optimizations? Could it be fixed in USB driver code or it is an HW limitation/bug?

I tried GCC and ARMCC and both gives similar results - no optimization settings leads to some errors with bulk transfer on ep1. Also with different settings like USBD queue size and usb interrupt priority it sometimes work on windows 7 but does not on windows 10 or Linux (Ubuntu).

Thanks for any help or advice.

Related