Skip to main content
Associate
April 5, 2024
Question

USB CDC Increase Reading Speed

Hello,
I'm currently working on a USB project and i encounter some issues.

I would like to send data to the STM32 and the STM32 must re-send it as fast as possible. I already test the sending speed and it work great for me but the reading speed is low.
The function CDC_Receive_FS work as a callback function and is call at the right speed (as fast as the sending speed) but between the sending and the writing, there's a delay... I've looked into the library but i don't understant where it comes from or how to fix it.
The STM32 seems to be able to receive et write data with a latency of 10ms but combining these two operation make the board have a latency of (avg)124ms.

 

I suspect the USBD_CDC_ReceivePacket function to be the cause of this issue.

Do you have any idea ?

```C

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)

{

/* USER CODE BEGIN 6 */

incrtest++;

 

TCountMsgReceive = StartingValueTCount;

 

USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);

CDC_Transmit_FS(UserRxBufferFS, *Len);

 

USBD_CDC_ReceivePacket(&hUsbDeviceFS);

 

 

if(((USBD_CDC_HandleTypeDef*) hUsbDeviceFS.pClassData)->RxState==0)

{

//USB_CAN_SwitchReceive();

 

}

 

 

return (USBD_OK);

/* USER CODE END 6 */

}

```

This topic has been closed for replies.

9 replies

KakyoukaAuthor
Associate
April 5, 2024

Little precision:

I'm using a STM32F411E-Disco

Pavel A.
April 5, 2024

Even 10 ms latency seems a bit too much. Depends on the size of the data, though.

The code snippet that you've shared does not provide enough clue to answer.

 

 

KakyoukaAuthor
Associate
April 8, 2024

I don't know what part of code i must share because my question i about the HAL library provided by ST.

10ms is too much but i don't need less than that. The issue i encounter is that the switch between reading and writing is slow. If i just read, i can acheive 10ms without problem and it's the same if i just write.

I don't understand why the retransmit seems to be blocked while the board is receiving data. 

do you have any explanation why?

 

 

AScha.3
Super User
April 8, 2024

Just - how often you call the "USB service" , MX_USB_HOST_Process(); , in main  ?

I call it about every 300us and USB running fine.

If you feel a post has answered your question, please click on " Best Answer ".