I'm using an STM32L151 to communicate with a PC using USB CDC. I used the STM32 HAL libraries to create my project. I found that the USB sends data in 1 ms intervals, and each time 64 bytes are being sent. So, is the maximum speed of the USB CDC 64 kbyte/s? That is much lower than the USB Full Speed data rate of 12 Mbit/s. How can I reach this speed, or at least a fraction of this speed?
Asked
Active
Viewed 2.0k times
2 Answers
10
Nope. If your code is "fast enough", the maximum CDC speed is about 1MByte/sec
. This may require a big (>1KB) FIFO on the device side. Oh, and the PC side must be able to read the data fast enough, e.g. with big buffers.
The 64KByte/s limit applies for USB HID which uses interrupt endpoints. USB CDC interface uses faster bulk endpoints.

Turbo J
- 7,563
- 1
- 23
- 43
-
1Thanks @Turbo J. As stated before, I use HAL library, I send data to PC using the function CDC_Transmit_FS(). How should I use this function to reach 1MB/s? I have a big buffer with 2Kbyte size, However endpoint size is 64 byte. I saw in the oscilloscope that the usb send data every 1 ms. and if the CDC function uses endpoint to send data, it could send 64byte every 1ms? am I think wrong? one more question: Is there any free software to check the incoming data baud rate? thanks – Mohammad May 31 '17 at 11:39
-
1You need to have the COM port open for reading in order to see anything other than the SOF every ms. Once it is open and being read, you should see a DATA token every couple of µs. – Turbo J Nov 04 '19 at 12:50
4
USB FS frame is 1ms so if you put 64 bytes to the buffer (using the HAL function) - it will send those 64 bytes in the next frame. And it will not send any more data until another 1ms frame
How to increase this speed -> aggregate your data in larger chunks and send more data in the one transaction (up to 8kB using HAL libraries).

0___________
- 60,014
- 4
- 34
- 74
-
2Thanks so much for your helpful answer. So, we can say the maximum speed using the HAL libraries will be 8kB*64=512kByte/second or 4096Mbit/second? is it true? how we can reach near full speed such as 8 Mbit/s or 1MByte/s? Thanks – Mohammad Jun 05 '17 at 06:13
-
1You need to have a bit better USB library than the one provided by STM. Remember that windows itself will limit that speed as the built in implementation of the VCOM is not very good – 0___________ Jun 05 '17 at 09:11
-
1Thank again @ PeterJ. I could reach the maximum speed of 500kByte/second using the HAL libraries. Is there any trick to increase this speed using HAL libraries? Or can you introduce me better usb library than HAL libraries, please? – Mohammad Jun 07 '17 at 06:08