Serial /dev/ttyTHS1 C++. Strange problem

Hi,
I detected a strange behaviour of the serial /dev/ttyTHS1:
I connected a device sending a serial data frame to pin10/J41 of nano board (/dev/ttyTHS1)
and also to a USB-to-serial converter on /dev/ttyUSB0.
The data received on /dev/ttyUSB0 corresppond perfectly to data expected but the data received on /dev/ttyTHS1
are erronous (lot of 0 and some data erronous).
I’ve worked 3 days trying to solve this problem, without success.

Some information:

  • For the serial /dev/ttyTHS1: I have disable the getty service and when I enter the command ls -l /dev/ttyTHS1 and also the command stty -F /dev/ttyTHS1
    answers are corrects (serial well configured and not used any TTY service:

Image1

  • Code is in C++ and I use termios to configure the serials
  • The 2 serials(/dev/ttyTHS1 and /dev/ttyUSB0) are configured the same way (2 instances of the same class)
  • baudrate is 115200 bauds
  • I plugged a logic analyser on pin10/J41 of nano board and the data frame received is perfect (data are OK, baudrate is OK, signal level 3V3 is OK, no glitch,…)
  • I used nano board kit B01

Here is the termios configuration code :

int serialPort::init(void)
{
speed_t bRateCode;

// read in existing settings in tty and handle any error
memset(&tty, 0, sizeof(tty));
if (tcgetattr(fd_serial, &tty) != 0)
    return -1; // error reading parameters of USB-COM

cfmakeraw(&tty);

tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used
tty.c_cflag &= ~CSIZE; // Clear all the size bits, then use one of the statements below
tty.c_cflag |= CS8; // 8 bits per byte
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
tty.c_cflag &= ~HUPCL;

tty.c_lflag = 0;

tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
tty.c_iflag |= 0;
tty.c_iflag &= ~(IGNPAR | BRKINT | PARMRK | ISTRIP | INLCR | ICRNL | INPCK | ISTRIP | IGNCR | IMAXBEL | IGNBRK); // Disable any special handling of received bytes
tty.c_iflag &= ~IUTF8;

tty.c_oflag = 0;

tty.c_cc[VTIME] = 0;    // No blocking, return immediately with what is available.
tty.c_cc[VMIN] = 0;

// Set baudrate (input and output the same one)
bRateCode = B115200;   // Defaut value
cfsetispeed(&tty, bRateCode);
cfsetospeed(&tty, bRateCode);

// Flush port, then apply attributes
tcflush(fd_serial, TCIFLUSH);

// Save tty settings and handle any error
if (tcsetattr(fd_serial, TCSANOW, &tty) != 0)
    return -2; // error saving parameters of USB-COM

return 0; // Init was OK
}

Here are the data frames received (we can see the difference) :

I definitively dont understand from where are coming all these zeros in the data frame received on /dev/ttyTHS1…
But not all bytes received are erronous, some are corrects.

After having read all the posts on this forum concerning the /dev/ttyTHS1 serial link, I think that the nano board kit has a problem on this serial because many have given up to make it work, and even some say that it is a hardware problem specific to all nanos.
And I came to the same conclusion.

If anyone had managed to make this serial work correctly, let me know what is the secret …

Thanks by advance for help.

hello bf1,

could you please have a try for stopping and disabling the nvgetty service.
for example,

$ systemctl stop nvgetty
$ systemctl disable nvgetty

Hello,

1- It is the first thing I did! and I get the same result.
2- After that I’ve enter the command ls -l /dev/ttyTHS1 and I saw that the group is dialout and not tty, so everything ok.
3- I ve also check the parameters for /dev/ttyTHS1: see terminal below
Image1

rgds,
Bernard