1

note that this is a duplicate of my question on stackoverflow

I am currently working on a software that use Python3 (pyserial) to interface with a lot of serial port (~24) on a Raspberry Pi Compute Module 3+ Lite. The serial ports are interfaced using multiple FTDI4232H chips. We access the board through a Ethernet USB interface. All of these are connected to the only USB OTG port of the Compute Module.

What I noticed is that when all serial ports are open, even if there is no serial communication going on, the Ethernet speed slows down drastically. speedtest result goes from 198.78 Mbits/sec to 1.48 Mbits/s. When using ssh to access the device, everything is stuttery.

My guess is that there is a pre-allowed minimum data bandwidth for each Serial connection, but have no clues as how to fix this.

Here is a MRE

import multiprocessing
import time
from serial import Serial


QTY = 23
STOP_TEST_AFTER = 30


def serial_test(serial_port):
    serial_port = Serial(port=f"/dev/ttyUSB{serial_port}", baudrate=19200)
    timer = time.time()
    while time.time() - timer < STOP_TEST_AFTER:
        time.sleep(0.1)


if __name__ == "__main__":
    process_list = []
    for i in range(0, QTY):
        new_process = multiprocessing.Process(target=serial_test, args=(i,))
        new_process.start()

    for proc in process_list:
        proc.join()

Thanks for your help!

Martin

4

This cannot be easily fixed. Upstream USB communication is polling-based: the host periodically sends a request to each device on the bus and checks their reply, and even an empty reply takes a time slot. The shortest polling interval is 1 millisecond.

See if you can change the endpoint polling interval in the FTDI driver configuration (AFAIK 32 milliseconds should be possible), but note that this will be a compromise: longer interval will mean less bus load, but also a longer delay until the incoming data is received.

Many FTDI chips also implement an adjustable latency timer and buffer size used to optimize the response time and data throughput, which you may need to do if you manage to increase the polling interval. Check out application note AN232B-04 on FTDI website.

1
  • 1
    This is in line with what I suspected. Many thanks! Jul 30 '20 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.