Why receiving USB_ERR_CANCELLED error during initial Rx transfer

From: Farhan Khan <farhan_at_farhan.codes>
Date: Tue, 29 Mar 2022 18:10:07 UTC
Hi all,

I am trying to send the initial "wakeup" USB Rx interrupt packet via usbd_transfer_start(), but after running the callback with USB_ST_SETUP, I receive another callback with USB_ERR_CANCELLED as the value of usb_error_t. What might be causing the cancellation?

Detailed explanation:
I am opening the pipes, then immediately running usbd_transfer_start() on the Rx Interrupt with this:
usbd_transfer_start(usc->usc_xfer[ATHN_RX_INTR]);

The callback function runs this:

	case USB_ST_SETUP:
		usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
		usbd_transfer_submit(xfer);
		break;

The next time the callback is invoked, the USB_GET_STATE macro reports USB_ST_ERROR with the value being USB_ERR_CANCELLED. The manual page suggests that this is the result of a transfer currently happening, but I am not clear on the issue. I have both set and disabled pipe_bof on the Rx Interrupt with the same result.

I borrowed the above code from the otus(4) driver.

Please assist. Thanks!

--
Farhan Khan
PGP Fingerprint: 1312 89CE 663E 1EB2 179C 1C83 C41D 2281 F8DA C0DE