Skip to main content
Explorer
December 28, 2025
Solved

slow data rate with usb cdc on nucleo-h533

  • December 28, 2025
  • 4 replies
  • 221 views

Hi All,

I'm building an instrument that needs to stream data to a PC at ~4Mbps. People were claiming nearly twice this with USB CDC so I chose the nucleo-h533 board and started with the Ux_Device_CDC_ACM example. I disconnected the USART code and added a loop that calls ux_device_class_cdc_acm_write and then I measure the rate at which I receive data on the PC. I can't get past ~1.8Mbps.

I have tried the following:

  • varying the size of the buffer passed in from 64 to 2048
  • enabling ZERO copy in the driver UX_DEVICE_ENDPOINT_BUFFER_OWNER=1 and defining UX_DEVICE_CLASS_CDC_ACM_ZERO_COPY
  • setting USBD_CDCACM_EPINCMD_FS_BINTERVAL to 1 instead of 5

In all cases, the baud rate remains about the same at 1.8Mbps. Is there anything I can do to improve this?

Best,

Marc

 

    This topic has been closed for replies.
    Best answer by TDK

    Hmm

    If you add a USB hub, does it go down? If you remove one, does it go up?

    Maybe it is a computer hardware limitation. Do you have another PC to test? You're on native Windows as opposed to some virtual machine, right?

    4 replies

    Super User
    December 28, 2025

    The PC side needs to poll quickly enough. Most programs do not do this. What are you using on the PC side? Eliminate hubs from the chain. Ensure you send a new buffer immediately after the previous buffer is sent.

    MScha.8Author
    Explorer
    December 29, 2025

    I wrote my own C# application on the PC side and digging into that did indeed uncover a problem. It appears the default behavior for Windows serial ports is a 4096 byte buffer with polling at 16 msec intervals which works out to 2Mbps--exactly what I am seeing.

    Some drivers support changing these values in device manager, but the default windows driver that gets used for the STM32 USB CDC device does not as noted in the link below.

    Serial Port Latency Option Missing - Windows 11 - Microsoft Q&A

     

    -Marc

     

    Super User
    December 29, 2025

    I wouldn't put too much stock in that answer. You're probably running into a C# implementation issue rather than an underlying hardware limitation. If you can, try reading 16 kB at a time rather than 4 kB.

    I'm able to achieve 9.2 Mbps.

    USB CDC packet loss at high data rates - STMicroelectronics Community

    Super User
    December 29, 2025

    Check the descriptors. For full-speed device the endpoint size should be 64 bytes. For high speed 512 bytes (on STM32H7 requires external PHY. Without that the "HS" USB instance is full speed).

     

    Technical Moderator
    December 30, 2025

    Hi @MScha.8 

    You can optimize better the provided implementation to achieve higher data rate using USBX stack. I'm suspecting the buffering and logic process.

     /* Check if there is a new data to send */
     if (UserTxBufPtrOut != UserTxBufPtrIn)
     {
     /* Check buffer overflow and Rollback */
     if (UserTxBufPtrOut > UserTxBufPtrIn)
     {
     buffsize = APP_RX_DATA_SIZE - UserTxBufPtrOut;
     }
     else
     {
     /* Calculate data size */
     buffsize = UserTxBufPtrIn - UserTxBufPtrOut;
     }
    
     /* Copy UserTxBufPtrOut in buffptr */
     buffptr = UserTxBufPtrOut;
    
     /* Send data over the class cdc_acm_write */
     if (ux_device_class_cdc_acm_write(cdc_acm, (UCHAR *)(&UserTxBufferFS[buffptr]),
     buffsize, &actual_length) == UX_SUCCESS)
     {
     /* Increment the UserTxBufPtrOut pointer */
     UserTxBufPtrOut += buffsize;
    
     /* Rollback UserTxBufPtrOut if it equal to APP_TX_DATA_SIZE */
     if (UserTxBufPtrOut == APP_TX_DATA_SIZE)
     {
     UserTxBufPtrOut = 0;
     }
     }
    }

     

    TDKAnswer
    Super User
    December 30, 2025

    Hmm

    If you add a USB hub, does it go down? If you remove one, does it go up?

    Maybe it is a computer hardware limitation. Do you have another PC to test? You're on native Windows as opposed to some virtual machine, right?

    MScha.8Author
    Explorer
    December 31, 2025

    I get 16kB max reads and 7Mbps on my laptop.

    It turns out I can get up to 8Mbps from my desktop depending on which USB plugs I use so it is a PC h/w issue.

    Thanks so much for your help.

    -Marc

     

    Super User
    December 31, 2025

    Thanks for reporting back with results.

    That's interesting that one device seems to limit the max readout or buffer size to 4 kB.

    Makes me wonder if the bug reported in that other thread could be due to the hardware and not something within Windows. Now I want to create an STM32 project with a USB CDC ACM host and see (a) the max throughput and (b) if packets are ever dropped.