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

RTT logging interferes with USB

I am using RTT logging and it is interfering with USB HID data transfer.  The host sends consecutive OUT packets and I print some logs after each one.  I will miss a APP_USBD_HID_USER_EVT_OUT_REPORT_READY event sometimes.  I am doing this in the main loop:

while (1) {

while (app_usbd_event_queue_process())
{
;
}

//process data and print to log

if (NRF_LOG_PROCESS() == false)
{
nrf_pwr_mgmt_run();
}

}

Is this the correct way to handle USB?  I copied it from the USB HID examples.  If I turn off logging or set APP_USBD_CONFIG_EVENT_QUEUE_ENABLE to 0 then I don't see this problem.

  • That seems plausible. 

    If the USB is set up as interrupts should solve the issue, because interrupts will always have a higher priority than the main loop. So even if an interrupt occurs between NRF_LOG_PROCESS() and nrf_pwr_mgmt_run(), or even during nrf_pwr_mgmt_run, but before the call to sd_app_evt_wait(), the interrupt will be handled. If it occurs after the call to sd_app_evt_wait(), it will obviously be handled as well. However, I believe there are some bugs in the interrupt driven USBD drivers, so I am not sure that works flawless either. 

    I see that the USB composite example has this in the main-loop:

            UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
            /* Sleep CPU only if there was no interrupt since last loop processing */
            __WFE();

    You should keep your check of the return for NRF_LOG_PROCESS(), in my opinion. But perhaps you can try to call nrf_app_usbd_event_queue_process() once more right before app_usbd_event_queue_process().

    Do you use the softdevice, by the way? If not, you can just use the WFE, like in the usbd_hid_composite example. 

  • I am using softdevice.  What kind of bugs are in USBD interrupt?  I am using interrupt and I don't see any problems yet.

  • It may not be a problem. If I remember correctly, it was easyDMA related, so if you are not using that in your USB, it may not be a problem.

    BR,
    Edvin

Related