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:
- The host resets the device
- The host send a GET_DEVICE_DESCRIPTOR
- My device replies with the device descriptor, sending the expected data
- When the host receives the endpoint 0 max packet size, it resets the device
- the host sends now a SET_ADDRESS request, my device accepts it and set its address
- the host send another GET_DEVICE_DESCRIPTOR request
- my device replies with the full device descriptor, sending the expected data
- 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:
Thank you for your help.