Issue with reading processes for high speed UART connections
We’re facing an issue including balenaOS and the read of UART devices connected with our service running on the balena device. The received byte-string seems to contain corrupted information.
Setup
raspberry pi 4 (2GB RAM)
python 3.6.9
balenaOS (all (tested) versions, up to 2.75.0+rev1),
Balena supervisor (all (tested) versions, up to 12.8.3)
Device UART settings / overlays
We do use the independent UART connections exposed with the overlays,
- UART2, UART3, UART4
- Available through /dev/ttyAMA1, /dev/ttyAMA2, /dev/ttyAMA3
Container running as balena service.
The service does have following components,
- main-process
- reading-process for the UART connections
main-process
The main-process does read the provided data packages delivered by the reading-process via an multiprocessing Queue of Python. This multiprocessing queue implementation in python uses OS pipes to exchange byte data between processes.
reading-process
The reading process holds an UART connection with a sensor device over the pySerial library. The UART connection has following characteristics,
- Baudrate: 921600
- Parity: Even
- Stopbits: One
- Bytesize: 8
The sensor connected is able to send a data frame every 120 milliseconds of around 3000byte per frame. Each data frame contains multiple 4-byte strings representing headers for different data types. A header is followed by the payload-size and the payload itself. The code does check the 4-byte string for a valid header string, in case of an invalid header, the package is flagged as corrupted. It is called a “Corrupted header”-exception.
We do receive approximately 500 frames per minute. Of these 500 frames around 5 are corrupted.
Issue
Only when running the code on balenaOS in a balena service do we see “Corrupted header”-exceptions. On other tested installations this can not be observed.
Other installation on identical hardware
- Running code on Ubuntu 20.04 64bit on “plain” python interpreter. The OS was set up with the same commands used in balena service Dockerfile.
- Running code on Ubuntu 20.04 64bit in a docker container, built on the base of the balena service Dockerfile. Also, the used Docker version was identical to the used balena-docker version.
Known improvements
- Overclocking the raspberry pi 4 hardware over the standard clock of 1.5ghz seems to reduce the problem. Especially when using 1.7ghz.
- Update the supervisor to the newest version of 12.8.3 also seems to reduce the problem significantly.
All this leads to the conclusion that the issue is caused by the balena supervisor or the balenaOS itself. With the reduced appearance of the issue by updating the balena supervisor it seems to narrow it down to the supervisor.
Can somebody identify any issue with the configuration?
Can somebody confirm the supervisor is affecting the reading of the UART?
Does somebody have an idea to sabilise / fix this?
Any help is much appreciated! Lot of thanks in advance!