Serial port stops working after upgrade to kernel 5.4.70

  • I have a sensor connected to /dev/ttymxc2 and this works fine with kernel 4.1.15. After upgrading to kernel 5.4.70, the communication stops working. The sensor uses a binary protocol with request and reply. After the upgrade, some of the replies from the sensor are lost, but some are still received. This is consistent. Certain commands always work and others never work. Typical for commands that doesn't work is that the delay before response is higher, 20-30ms.

    I've verified with an oscilloscope that the sensor sends the response.

    I use pyserial, but I've also verified the issue using stty and dd.

    Is there any reason why serial communication behaves differently in the two kernel versions? Kernel configuration and devicetree is unchanged.

  • After some more investigation, I've found out that the problem depends on the length of the payload. I have short circuited RX and TX on port ttymxc2 and run the following python script (requires pyserial):

    1. from serial import Serial
    2. with Serial('/dev/ttymxc2', baudrate=115200, timeout=0.5) as serial:
    3. for i in range(100):
    4. request = b'a' * i
    5. serial.write(request)
    6. response =
    7. if request != response:
    8. print(f'Length {i} failed')

    The code produces the following output:

    Length 9 failed

    Length 18 failed

    Length 27 failed

    Length 36 failed

    Length 45 failed

    Length 54 failed

    Length 63 failed

    Length 72 failed

    Length 81 failed

    Length 90 failed

    Length 99 failed

    All requests of length dividable by 9 are lost. This happens on kernel 5.4.70, but not on 4.1.15. Is anyone able to reproduce this behavior?

  • Hi, I also remember an issue with the serial port in the new 5.4.70 kernel (RS485). If I remember correctly I fixed this by setting the FIFO to 1 byte (instead of the default value) in the device tree. This is may be only a workaround until a better solution was found:

    rx_fifo_trig = <1>

    1. &uart4 {
    2.     pinctrl-names = "default";
    3.     pinctrl-0 = <&pinctrl_uart4_1>;
    4.     uart-has-rtscts;
    5.     fsl,rx_fifo_trig = <1>;
    6.     linux,rs485-enabled-at-boot-time;
    7.     status = "okay";
    8. };
  • Hello,

    this is normally not an issue. You have a requirement which needs configuration of the uart port. The drivers offers the device tree settings to configure this. Please see driver documentation for uart node. In general you may have better response if dma is disabled too.


    1. &uart4 {
    2. pinctrl-names = "default";
    3. pinctrl-0 = <&pinctrl_uart4_1>;
    4. uart-has-rtscts;
    5. fsl,rx_fifo_trig = <1>;
    6.     no-dma;
    7. linux,rs485-enabled-at-boot-time;
    8. status = "okay";
    9. };

    Hope this helps.

    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.