1

I have problem to get the Pi UART flow control working - Pi as tx and Peripheral as rx. I tried with a Pi2 and a PiZero.

Here are the observations:

  1. Initially data flow is fine when peripheral's RTS (Pi's CTS) pin is asserted (logic low).

  2. When peripheral's RTS pin is de-asserted (logic high), the data flow stops, which is totally expected and correct.

  3. When peripheral's RTS pin is asserted again, sometime the data flow will resume but sometime will not. But once it cannot resume, it will stuck forever no matter the pin is asserted or de-asserted further. It is very easy to reproduce - trying 5 times will guarantee trapping in that stuck state.

I used DT overlay to enable the RTS/CTS function in Pi. The Pi's CTS pin was also set to pull up - so when nobody is driving the pin, Pi's CTS is default to de-asserted. Below is the overlay DTS file I used. And I follow the instruction here to compile and install the overlay DTB file.

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";

    fragment@0 {
        target-path = "/soc/gpio";
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&blevoice_pins>;

                blevoice_pins: blevoice_pins {
                brcm,pins = <17 18 16 21>;     /* gpio no. */
                brcm,function = <7 0 7 1>; /* 0:in, 1:out, 7:alt3 */
                brcm,pull = <0 1 2 0>;
            };
        };
    };
};

The code to open the UART port is as follows:

int UART_ComPort::open()
{    
    m_hComDev = ::open("/dev/ttyAMA0" , O_RDWR | O_NOCTTY | O_SYNC);
    if ( m_hComDev < 0 )
    {
        cout << "Could not open UART" << endl;
        return ComPort::COMPORT_ERROR;
    }
    struct termios options;
    tcgetattr(m_hComDev, &options);

    options.c_cflag = B460800 | CS8 | CLOCAL | CREAD | CRTSCTS;
    options.c_iflag = IGNPAR;
    options.c_oflag = 0;
    options.c_lflag = 0;

    cfsetospeed(&options, (speed_t)B460800);
    cfsetispeed(&options, (speed_t)B460800);
    cfmakeraw(&options);

    tcsetattr(m_hComDev, TCSANOW, &options);
    m_bInitiated = true;

    return ComPort::COMPORT_SUCCESS;
}

Have you guys seen Pi UART flow control working before? Have you spot anything I may have done wrong?

../ming

  • How did you "used DT overlay to enable the RTS/CTS function"? – Milliways Jul 28 '16 at 0:02
  • Edited the original post to include the DTS file used. – Ming Leung Aug 3 '16 at 12:55

Your Answer

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

Browse other questions tagged or ask your own question.