cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC communication

josebuela
Associate

Hi all,

I am trying to USB CDC communication with my STM32 nucleo board. I want to send consecutive numbers and verify that they are consecutive and calculate the data rate.

I obtain errors, non consecutive numbers (irregularly), when I increase the amount of bytes I send. What can I do to solve this problem?

 

This is the code that I am using to send consecutive numbers:

uint32_t data[32];

USBD_StatusTypeDef status = 0 ;
while (1)
{

for (uint16_t i=0; i<32; i++)
{
data[i]=cnt++;
}
//HAL_Delay(1);
status = USBD_FAIL;
while (status != USBD_OK){
status = CDC_Transmit_FS(data, sizeof(data));

}
}

 

1 REPLY 1
Pavel A.
Evangelist III

Do you understand how USB works that  CDC_Transmit_FS needs time to complete? You cannot send a new data until the previous one is sent out. Also, mind the packet size specified for the USB endpoint, are you sending too short packets?