Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

USB HID crash when ESB is used

I want to develop a 2.4G mouse Dongle and  have used NRF52840 and SDK 17.0.2. When I have used USB or ESB one by one - all is Ok. But when they are used together - usb driver goes into an infinite loop here:

 nrfx_usbd.c Line 1447

static void usbd_dmareq_process(void)
{
   ...

   /* There is a lot of USBD registers that cannot be accessed during EasyDMA transfer.
             * This is quick fix to maintain stability of the stack.
             * It cost some performance but makes stack stable. */
             
    while (!nrf_usbd_event_check(nrfx_usbd_ep_to_endevent(ep)) &&
           !nrf_usbd_event_check(NRF_USBD_EVENT_USBRESET))
    {
        /* Empty */        // ***** stay in here *****
    }
   ...          
}

I enqueue the received mouse data in the ESB receiving event, and then dequeue the data in the main loop and transfer it to the PC via USB,USB crashes after running for a while 。

 It seems that the USB has been waiting for the End point 1 transmission completion event :

NRF_USBD_EVENT_ENDEPIN1 /**< The whole EPIN[1] buffer has been consumed. The RAM buffer can be accessed safely by software. */

The call stack when the program crashes is as follows :

Please tell me how to solve this problem 。
 

Related