3
\$\begingroup\$

I am trying to build a USB device from scratch on a STM32F7 microcontroller.

When I plug the device to the computer the hosts does not accept the device descriptor sent by my device:

  1. The host resets the device
  2. The host send a GET_DEVICE_DESCRIPTOR
  3. My device replies with the device descriptor, sending the expected data
  4. When the host receives the endpoint 0 max packet size, it resets the device
  5. the host sends now a SET_ADDRESS request, my device accepts it and set its address
  6. the host send another GET_DEVICE_DESCRIPTOR request
  7. my device replies with the full device descriptor, sending the expected data
  8. The host resets the device again and the process restarts back from step 1 ... I don't know why

Here is my device descriptor:

const USB_DeviceDescriptor device_descriptor = {
    .bLength                = sizeof(USB_DeviceDescriptor),
    .bDescriptorType        = USB_DESCRIPTOR_TYPE_DEVICE,
    .bcdUSB                 = 0x0200,       // USB 2.0.0
    .bDeviceClass           = USB_CLASS_PER_INTERFACE,
    .bDeviceSubClass        = USB_SUBCLASS_NONE,
    .bDeviceProtocol        = USB_PROTOCOL_NONE,
    .bMaxPacketSize0        = 8,                // ENDPOINT0_SIZE_8
    .idVendor               = 0x1234,
    .idProduct              = 0x5678,
    .bcdDevice              = 0x0100,       // 1.0.0 version
    .iManufacturer          = 0,
    .iProduct               = 0,
    .iSerialNumber          = 0,
    .bNumConfigurations     = 1,
  };

Here is the log of the communication between the host and my device:

[INFO] Program entry point.
[INFO] USB Reset detected
[INFO] Speed enumeration done
[INFO] setup
[DEBUG] SETUP data: [8]: {0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00}
[INFO] USB GET DESCRIPTOR DEVICE Request
[DEBUG] REPLY data: [8]: {0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08}
[DEBUG] REPLY data: [8]: {0x34, 0x12, 0x78, 0x56, 0x00, 0x01, 0x00, 0x00}
[INFO] USB Reset detected
[INFO] Speed enumeration done
[INFO] setup
[DEBUG] SETUP data: [8]: {0x00, 0x05, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00}
[INFO] USB SET ADDRESS Request
[INFO] setup
[DEBUG] SETUP data: [8]: {0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x12, 0x00}
[INFO] USB GET DESCRIPTOR DEVICE Request
[DEBUG] REPLY data: [8]: {0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08}
[DEBUG] REPLY data: [8]: {0x34, 0x12, 0x78, 0x56, 0x00, 0x01, 0x00, 0x00}
[DEBUG] REPLY data: [2]: {0x00, 0x01}
[INFO] USB Reset detected\

As you can see; my device returns the correct values for the device descriptor, but the host does not accept or recognize it.

Also I noticed that it takes quite a long time for the host to send the GET_DEVICE_DESCRIPTOR request (several seconds right after the reset of the device). I don't know if such a delay is normal, but it seems quite long to me.

Here is a screenshot from the linux log:

enter image description here

Thank you for your help.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

The error code 110 is ETIMEDOUT.

Apparently, your code does not correctly handle some part of the USB protocol. I suspect that it does not send an ACK in response to the OUT transaction that is the status stage of the control transfer (see section 8.5.3.1 of the USB 2.0 Specification).

\$\endgroup\$
5
  • \$\begingroup\$ Hello, thank you. Do you know how I can check if ACK are correctly sent? My code is not supposed to handle these packets, the USB core in my microcontroller is supposed to handle them itself. Perhaps my board has an issue then. \$\endgroup\$
    – wbs2422
    Commented Oct 14, 2022 at 14:55
  • \$\begingroup\$ It's possible that you did not tell the library the data transfer size. Compare your code with ST's examples. \$\endgroup\$
    – CL.
    Commented Oct 14, 2022 at 15:08
  • \$\begingroup\$ Ok I've tried on another PC and it worked ... I've read that these ETIMEDOUT errors can be raised when the power supply is not sufficient... I'm not sure if it is the case however,it would be interesting to have a way to check it \$\endgroup\$
    – wbs2422
    Commented Oct 14, 2022 at 15:37
  • \$\begingroup\$ I'm following a course on USB programming, I have the same code than the teacher, minor the differences between my board and his, which are not the same. I double checked my configuration settings and have not spotted something that looked weird. But it may be the case also ... \$\endgroup\$
    – wbs2422
    Commented Oct 14, 2022 at 15:39
  • \$\begingroup\$ I switched to a windows computer, and these errors disappeared. I don't know why but I see them only on my Linux desktop. I'll also ask the Linux community \$\endgroup\$
    – wbs2422
    Commented Oct 15, 2022 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.