USB Device driver failed to send descriptor / USB enumeraion

162 Views Asked by At

I am writing a usb driver from scratch on STM32F4 to work as a msc deivce. However it always failed at enumeration process. Here is a sequence of events happened when I tested it:

  1. On start, it received rxqlvl interrupt then read the setup packet from host to get descriptor.
  2. It then set the xfersize(=18) and pktcnt(=1) and epena=1 and cnak=1 in the corresponding register of endpoint0(IN).
  3. In the "empty tx fifo" interrupt callback it wrote the descriptor content(18 bytes) to data fifo0.
  4. It got "xfercomplete" in-endpoint interrupt.
  5. It received the second setup packet from host to set address, then set the address in the device config register and sent a zero length packet back to host.

After all aboves steps, the driver got RESET and then received the setup packet again as in step 1 from host asking for device descritpor (wValue=0x100), and then ran through step 1-5 again and again... What I am expecting here is that after step5 host should instead ask for config descriptor (wValue=0x200) instead of resetting the device, right?

I used usbmon to capture the log of host as below:

ffff93b39f300fc0 3605221398 S Ci:1:000:0 s 80 06 0100 0000 0040 64 <
ffff93b39f300fc0 3610458920 C Ci:1:000:0 -2 64 = 12010002 00000040 c0168b08 00010102 03010000 00000000 00000000 00000000

It seems like host it getting error (-2). The host should have already received the descriptor but something else went wrong. What could I do to fix/debug this problem?

0

There are 0 best solutions below