Re: Trouble loading firmware to USB device

From: Farhan Khan <>
Date: Thu, 21 Apr 2022 04:18:50 UTC
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


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

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

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?)

Between steps 4 and 5, I am expecting athn_usb_intr to be called with
the USB_ST_TRANSFERRED condition which will eventually execute
wakeup(9). However, this is never called and I have not been able to
determine why.

Do I need to run a callback manually? If how do I msleep() and make the
call at the same time?

Still stuck :/
- Farhan