What is expected error rate and drop rate on ST-Link VCP USART?
On the Nucleo STM32F446RE, my code reads the USART VCP (of ST-Link) and echoes it back. It uses DMA, FreeRTOS, and FreeRTOS queues (enqueing each byte individually). It ISRs the DMA Transfer Complete, but also ISRs the USART IDLE, so that it echoes byte by byte.
When testing it manually, it seems to work perfectly.
I wanted to benchmark it, and found a linux-serial-test
tool, which gives poor results:
$ linux-serial-test -p /dev/ttyACM0 -s -n -f -Z -o 5 -i 7
Linux serial test app
Flush RX buffer.
Stopped transmitting.
/dev/ttyACM0: count for this session: rx=24764, tx=49152, rx err=12
Stopped receiving.
/dev/ttyACM0: count for this session: rx=27121, tx=49152, rx err=12
Nearly half the bytes dropped! And a non-trivial amount of errors. (Note that errors were much higher until I tweaked the DMA buffer size. And if I use the -w
option, they go up also.)
Are these drops and errors hardware limits of the ST-Link (esp. since no flow control)? Are they potential issues in my code? Or perhaps the linux-serial-tester
itself isn't testing correctly?
What performance of the VCP should I expect, and how should I test it?
Adding a delay in transmission (-a 1000
) improves results:
$ linux-serial-test -p /dev/ttyACM0 -s -n -f -Z -o 15 -i 25 -a 1000
Linux serial test app
Flush RX buffer.
/dev/ttyACM0: count for this session: rx=17977, tx=20480, rx err=0
/dev/ttyACM0: count for this session: rx=44060, tx=45056, rx err=0
Stopped transmitting.
/dev/ttyACM0: No data received for 2.0s. Exiting due to timeout.
and turning on compiler optimizations (either -Os
or -O3
) improves the rx rate while slightly increasing errors:
$ linux-serial-test -p /dev/ttyACM0 -s -n -f -Z -o 5 -i 10
Linux serial test app
Flush RX buffer.
Stopped transmitting.
/dev/ttyACM0: count for this session: rx=36874, tx=53248, rx err=85
/dev/ttyACM0: No data received for 2.0s. Exiting due to timeout.
(the exact results vary, but that seems to be the pattern).