cancel
Showing results for 
Search instead for 
Did you mean: 

Can USB CDC receive more than 256 bytes of data from the host?

No_Name
Associate III

Hi everyone.

I'm trying to send more than 256 bytes of data from the host to the STM32 using USB CDC VCP, and I don't know why VCP won't accept more than 64 bytes of data. My project is already halfway done. If I switch to the USB bulk method, do I have to replace the USB CDC library and rewrite all the code from scratch? And do I have to create my own library to replace USB CDC?

I'm using an STM32F407VET6.

I appreciate all your answers.
Thank you:).

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

You can send more than 256 bytes of data, but they will be split up into chunks of up to 64 bytes. The 64-byte limit is a limitation of USB FS. There is no way around this. You have to piece data together on the receiving end.

The is no way to "use a bulk endpoint" or change the CDC code or otherwise change things to avoid this. It is a limitation of USB FS.

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

View solution in original post

13 REPLIES 13
gbm
Principal

CDC data is sent in 64-byte packets. You may send any amount of data but it will be received as multiple 64-byte packets. Bigger packets are possible with High-Speed USB but it rarely matters for CDC VCP. CDC already uses Bulk transfer.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
No_Name
Associate III

Yes.
This is so that the STM32 can receive larger amounts of data at once without having to break it down into 64-byte chunks.

AScha.3
Super User

Hi,

64 B packet size is defined by USB full speed CDC , not the involved cpu.

+

When receiving data larger than the endpoint packet size (e.g., 512 bytes or more), the STM32 USB CDC firmware uses the USB core's multi-packet feature. The core automatically manages the transfer by receiving several packets of the configured endpoint size and reassembling them as needed. The application must process the data promptly to avoid buffer overruns, and the OUT endpoint is re-enabled for the next packet in the appropriate callback or handler.

single USB CDC transfer is determined by the endpoint's maximum packet size, which is typically:

  • 64 bytes for Full Speed (FS)
  • 512 bytes for High Speed (HS)

So USB CDC can receive more than 256 bytes from the host. The STM32 USB device core and middleware handle large data transfers by splitting them into multiple endpoint-sized packets and reassembling them in the firmware.

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

AFAIK, ST USB device stack may handle device-to-host (IN) multipacket transfers but not host-to device (OUT). The data received callback is called upon packet reception, at least for CDC VCP.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
No_Name
Associate III

@AScha.3 @gbm 

So, in conclusion, USB CDC VCP can receive more than 256 bytes, but it will be divided into 64-byte blocks, right?

If I want to migrate from USB CDC VCP to USB BULK so that STM32 can receive more than 64/256 bytes of data at once from the host, do I have to replace all USB CDC libraries, or can USB CDC be modified to receive 256 bytes or more at once?

No_Name
Associate III

Will all host-to-interface communications involving large data sizes, such as 256/512 bytes or more, still be divided into multiple packets?

What this means is, will all communications equally split packets larger than 256/512 bytes?

TDK
Super User

You can send more than 256 bytes of data, but they will be split up into chunks of up to 64 bytes. The 64-byte limit is a limitation of USB FS. There is no way around this. You have to piece data together on the receiving end.

The is no way to "use a bulk endpoint" or change the CDC code or otherwise change things to avoid this. It is a limitation of USB FS.

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

Okay, so all USB communication between the host and the interface will still be divided into 64 bytes? So there is no way to receive data all at once without it being divided?

> all USB [FS] communication between the host and the interface will still be divided into 64 bytes

> there is no way to receive data all at once without it being divided

That is correct.

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