cancel
Showing results for 
Search instead for 
Did you mean: 

Losing data sending over USB CDC

alejandro_a
Associate

Dear community,

I am working with the STM32 Nucleo F429ZI board to send data over USB - CDC. I have set a time interrupt every 1ms and my goal is to send a package of data after each time interrupt (the data sent are consecutive numbers).

As the code below shows, I am sending the variable "data" (array of values, e.g. 512). When I send a large package of "data" I do not receive the entire data on my computer.

Code:

alejandro_a_0-1689934743795.png

 

2 REPLIES 2
TDK
Guru

CDC_Transmit_FS takes time to complete, much more than 1ms in the worst case. Expect USB to have random unavoidable delays of 10s of ms.

Implement a buffer where you store data before sending, capable of storing up to maybe 200ms of data, and send that out after the previous transaction completes.

Use the return value of CDC_Transmit_FS or the state of the state machine to determine if the previous transaction is complete or not.

If you feel a post has answered your question, please click "Accept as Solution".

The USB delay I measured is as high as 2 seconds. Is this normal? And the longer the continuous transmission time of my device, the higher the USB delay. When the transmission is about two hours, the maximum delay is about 250 milliseconds. I use the USB CDC class interrupt transmission method.