2025-07-22 6:12 AM
I am recently working on USB CDC in STM32F407 and i have the following doubts:
2025-07-22 1:12 PM - edited 2025-07-22 1:13 PM
1) The peripheral will do the chunking. Send it as much as you want. The operation needs to be complete before you call CDC_Transmit_FS again.
2) N/A
3) No. You get called on every packet received. Each packet will be up to 64 bytes. Shove it into a buffer if that's what you need. After you return from CDC_Receive_FS, the data is stale and effectively lost.
4) See previous answers.
2025-07-31 7:33 AM
I would like to add to what @TDK mentioned
If you want to process data in larger chunks (e.g., 2KB), make sure that you give the transmit function enough time before attempting to transmit data again for example HAL_Delay(1). You can send the received data again over USB CDC as a loopback. Then to avoid stale data, you can clear buffer. Here is an example:
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
USB_CDC_RxHandler(UserRxBufferFS, *Len);
memset(UserRxBufferFS, '\0', *Len);
return (USBD_OK);
}
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.