2025-03-06 7:00 AM - edited 2025-03-06 7:12 AM
Hi,
I am testing the USB HS Device CDC implemented from the CDC example (so using ST middlewares) and I notice a strange behavior while reading transfers of 512B.
Internally, the function CDC_Receive_HS file Appli/Src/usb_cdc_if.c has been adapted for a simple loopback as follows:
static int8_t CDC_Receive_HS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 11 */
USBD_CDC_SetRxBuffer(&hUsbDeviceHS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceHS);
SCB_CleanDCache_by_Addr((uint32_t *)Buf, *Len);
CDC_Transmit_HS(Buf, *Len);
return (USBD_OK);
/* USER CODE END 11 */
}
So basically, my testing program, based on libusb v1.0.27.11936, consists of consecutive bulk transfers to EP #0x01 (bulk writing to STM32 CDC device) and from EP #0x81 (bulk reading from STM32 CDC device) during a time interval of 1 second.
It works fine except for bulk transfers of 512B: in this case, the test results in approx. 50% of zero length bulk reads (0 B of data) so resulting in 75% of the achievable throughput (a maximum of 12 MB/s for 511B transfers with this tests), since for any bulk transfer of size < 512B, there are no zero length reads: data written to STM32 CDC is correctly read back from it, both in therms of equal data transferred size (both W/R) and data matching.
I checked the MPSIZ and XFERSIZ fields values. The RM doesn't specify anything special regarding the programming value. I could check during debugging that 512 is being written into these fields.
So what could be the problem with exactly 512 B?
Sounds like a possible off-by-one error.
Thanks,
S.