2021-11-23 01:13 AM
Hello,
I am using the STM32L4R5ZI-P dev board.
I have configured USB as a device only with the CDC class, where APP_TX_DATA_SIZE is 2048, USBD_MAX_STR_DESC_SIZ is 65536.
When I am transmitting a data buffer of 512 bytes continuously for 1 millisecond then I am getting 1536 bytes, but when transmitting a data buffer of 64 bytes then I am getting for the first 1 ms 320 bytes then onwards 384 bytes rest of the ms.
Question:
Why I am getting 1536 bytes for 512 bytes data buffer transmission and only 384 bytes for 64 bytes data buffer transmission?
Solved! Go to Solution.
2021-11-23 05:25 AM
Due to the overhead within the protocol, you can never hit 12 Mbps. Expect to max out around 8-10 Mbps, and only if you do everything right on the STM32 side and the PC side.
To maximize throughput, you need to ensure time between transfers is minimized. One way of doing this is sending more data at a time, which allows the USB peripheral to do its thing without CPU intervention, at least until the transfer is complete and a new one needs queued up.
The other piece of the puzzle is the PC side. If you fill up the hardware buffer, transmission will block until you read it out and the buffer has space again. Some programs do not read this buffer frequently enough to achieve the ~8 Mbps that the hardware is capable of.
As Uwe says, USB FS sends max 64 bytes per packet. This is a hardware/protocol limitation.
Note that 1536 bytes / 1 ms is 12.288 Mbps, which is not possible. It would be better to measure throughput over a longer period of time to reduce errors in timing.
2021-11-23 01:58 AM
USB is not only the device, it is device + cabling + hubs + PC host + protocol. There are 1 ms Frames and 1/8 ms Microframes in the protocol. So in the 64 byte case, you fill up 5 to 6 frames with 64 bytes each and in the 512 bytes things get split up in another way.
2021-11-23 04:26 AM
Does that mean we can achieve maximum throughput only when we will send large buffered data like 512 bytes?
STM32L4R5 can only work at full speed, so 1/8 frame size is possible?
2021-11-23 05:25 AM
Due to the overhead within the protocol, you can never hit 12 Mbps. Expect to max out around 8-10 Mbps, and only if you do everything right on the STM32 side and the PC side.
To maximize throughput, you need to ensure time between transfers is minimized. One way of doing this is sending more data at a time, which allows the USB peripheral to do its thing without CPU intervention, at least until the transfer is complete and a new one needs queued up.
The other piece of the puzzle is the PC side. If you fill up the hardware buffer, transmission will block until you read it out and the buffer has space again. Some programs do not read this buffer frequently enough to achieve the ~8 Mbps that the hardware is capable of.
As Uwe says, USB FS sends max 64 bytes per packet. This is a hardware/protocol limitation.
Note that 1536 bytes / 1 ms is 12.288 Mbps, which is not possible. It would be better to measure throughput over a longer period of time to reduce errors in timing.