nRF5340 - usb incomplete RX transfer until new TX transfer

Hi,
here is a nRF5340 generic usb device driver application developed with NCS 2.2.0 (Zephyr 3.2.99).
The interface has two bulk endpoint, 0x01 for RX and 0x81 for TX.
I can successfully exchange USB data between PC and the target.

I'm experiencing a problem in the PC to target direction of transfer (RX).
The RX transfer does not complete until a TX transfer gets done.
RX data is accumulated in the buffer (either in the PC or in the target), and only a TX event will unlock it.

This is the RX callback function, where I put the received data in a k_fifo before invoking a new transfer with the same cb function,
as done by ncs/zephyr/samples/subsys/usb/webusb sample code

static void usb_on_receive(uint8_t ep, int size, void *priv)
{
  static uint8_t data[COSMED_BULK_EP_MPS];
  struct usb_cfg_data *cfg = priv;

  if (size > 0) {
    struct comdrv_data_t *buf;
    buf = k_malloc(sizeof(*buf));
    if (buf) {
      buf->len = 0;
    } else {
      LOG_WRN("not able to allocate buffer");
      return;
    }

    buf->len = size;
    memcpy(buf->data, &data, buf->len);
    k_fifo_put(&rx_queue, buf);
  }

  /* start a new read transfer */
  usb_transfer(hostgw.cfg->endpoint[COSMED_OUT_EP_IDX].ep_addr, data,
     COSMED_BULK_EP_MPS, USB_TRANS_READ, usb_on_receive, cfg);
}

Related