Re: Trouble loading firmware to USB device

From: Hans Petter Selasky <hps_at_selasky.org>
Date: Thu, 21 Apr 2022 05:57:49 UTC
On 4/21/22 06:18, Farhan Khan wrote:
> On Wed, 2022-04-20 at 20:37 +0200, Hans Petter Selasky wrote:
>>
>> Hi,
>>
>> It appears you've programmed the interrupt endpoint to only receive
>> one
>> USB packet, because there is no /* FALLTHROUGH */, but a "break;"
>> statement instead!
>>
>>>                  break;
>>>          case USB_ST_SETUP:
>>
>> Maybe if you change that, it will work.
>>
>> --HPS
> 
> Hi!
> 
> I removed that break and the issue remains.
> 
> I would not expect this to make a difference because the USB_ST_SETUP
> condition is below the USB_ST_TRANSFERRED condition and the
> USB_ST_TRANSFERRED condition is never called. Since I am only getting
> USB_ST_SETUP calls, USB_ST_TRANSFERRED's fallthrough never happens
> anyways.
> 
> The timeline of events is this:
> ----
> 1. athn_data_rx_callback called via usbd_transfer_start() when pipes
> are opened, with USB_ST_SETUP condition - no USB_ST_TRANSFERRED occurs
> 
> 2. athn_usb_intr callback called via usbd_transfer_start(), also when
> pipes are opened. This creates a USB_ST_SETUP condition, but no
> USB_ST_TRANSFFERRED condition.
> 
> 3. Loading firmware content via usbd_do_request_flags()
> 
> 4. Sending final usbd_do_request() with length of 0.
> 
> 5. msleep() called, times out with EWOUDLBLOCK condition. This should
> be woke up by wakeup(9), which would happen if athn_usb_intr with the
> USB_ST_TRANSFERRED condition happened, but it does not.
> 
> 6. Firmware loading failure due to timeout.
> 
> 7. Driver unloaded
> 
> 8. athn_usb_intr called with USB_ST_ERROR/USB_ST_CANCELLED (Why?)

Hi,

8) usbdump will answer this question.

I see some more bugs:

	[ATHN_RX_INTR] = {
		.type = UE_INTERRUPT,
		.endpoint = 0x83, // AR_PIPE_RX_INTR,
		.direction = UE_DIR_ANY,
	                      ^^^^ try to use UE_DIR_RX here, else you might 
bind for TX!

And use UE_DIR_TX for TX. Ditto for the other transfers. Any change?

Second note, is that you should set some buffer size for the 
non-interrupt endpoints, else the buffer size will only be 
wMaxPacketSize bytes big!

--HPS