USBD EP Transfer

Hi,

I'm working on an USB device that should be emulating an Xbox controller on nRF52840 (currently working with a devkit - 3.0.0 2022.34). SDK: 17.1.0.

I have developed the firmware for the Xinput protocol, and it works OK so far. The device gets recognized on Windows, and I'm able to perform EP IN USB transfers, which are sending joystick and button data to the PC. This works OK.

I'm trying to receive some data from the PC, and I'm experiencing some strange behavior:
If I set optimization level to Level 3, and add one NRF_LOG_INFO() statement inside (at the top of) the USBD event handler, which is registered here:

const app_usbd_class_methods_t app_usbd_xinput_class_methods = {
        .event_handler = xinput_event_handler,
        .feed_descriptors = xinput_feed_descriptors,
};

I'm able to receive the data by reading it like so:

ret_code_t app_usbd_xinput_read(app_usbd_xinput_t const * p_xinput, void *p_buf, size_t length)
{
    app_usbd_class_inst_t const * p_inst = app_usbd_xinput_class_inst_get(p_xinput);

    nrf_drv_usbd_ep_t ep = data_ep_out_addr_get(p_inst);

    NRF_DRV_USBD_TRANSFER_OUT(transfer, p_buf, length);
    return app_usbd_ep_transfer(ep, &transfer);
}

If I either remove the NRF_LOG_INFO() statement or change the optimization level, I can't receive the data anymore.

If I try to debug, in the case when I can't receive the data, and I set a breakpoint inside app_usbd_event_queue_process(), I can see that nrf_atfifo_item_get(m_event_queue, &cx) always returns NULL.

Does anyone have an idea about what could be going on here?
Thanks

Best regards
Emir

Related