cancel
Showing results for 
Search instead for 
Did you mean: 

Doubts Regarding USB CDC in STM32F407

deepakelango05
Associate II

I am recently working on USB CDC in STM32F407 and i have the following doubts:

  1. Based on my understanding 64  bytes can be send using CDC_Transmit_FS, so can we give a array of some size which is greater than 2KBytes and DO we need to do any chunking here ?
  2. Is the data send via USB CDC is always 64 bytes or can we configure it if yes How can we configure it to transmit more bytes?
  3. So CDC_Recevice_FS in usb_cdc_if.c is a application hook function which is called for every 64 byte. Is these configurable let us say i want to call these function only when 2KBytes is received?
  4. What is the maximum data that can be received and send using USB_CDC Functions.
2 REPLIES 2
TDK
Super User

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.

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

Hi @deepakelango05 

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.