Hello! I have recently decided to try a newer version of USB for RTL and detected a mistake in file "usbcore.c":
__inline BOOL USB_ReqGetDescriptor (void) { U8 *pD; U32 len, n; switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: switch (SetupPacket.wValue.WB.H) { ... case USB_STRING_DESCRIPTOR_TYPE: pD = (U8 *)USB_StringDescriptor; for (n = 0; n != SetupPacket.wValue.WB.L; n++) { if (((USB_STRING_DESCRIPTOR *)pD)->bLength != 0) { pD += ((USB_STRING_DESCRIPTOR *)pD)->bLength; } } if (((USB_STRING_DESCRIPTOR *)pD)->bLength == 0) { return (__FALSE); } EP0Data.pData = pD; len = ((USB_STRING_DESCRIPTOR *)pD)->bLength; break; ... } break; ... }
Selected code part which is responsible for sending the string descriptor to the host, doesn't work correctly. In previous versions of USB sources, al least in version V1.10 of USB Core Module it worked well and it looked like this:
case USB_STRING_DESCRIPTOR_TYPE: EP0Data.pData = (U8 *)USB_StringDescriptor + SetupPacket.wValue.WB.L; len = ((USB_STRING_DESCRIPTOR *)EP0Data.pData)->bLength; break;
Please correct the issue if I am right, or explain the situation if not. Thanks in advance.
Well.... I've just realized what the issue was. It was not actually a source code mistake, as the Device Descriptor has also been modified in the new version of sources. The Device Descriptor includes bytes which previously (in the old version) held string offsets, but now they hold string indices (0x01, 0x02, e.t.c). Taking this into account, I see that the string descriptor processing algorithm is correct.
Recompiling my projects I have copy-pasted my old USB descriptors into a new USB sources without changing and it wasn't right. So be careful with that.
Now the problem is solved, Thank you.
Hello Alexey Kozyrev,
The reason for using indices rather than offset was that the USB Compliance test threw an error/warning for the older version which used the offset to address the string.
Best Regards, Martin Guenther