USB devices affect stty (uart)

106 Views Asked by At

I'm writing program that communicates with MCUs via UART (stty) The platform I use is Acmesystems Acqua A5 (SAMA5D31) with Debian. The protocol between MCU and PC is following: MCU address, data, CRC. If all is ok, MCU generates a coresponding answer. The problem is - when I type something on a USB keyboard or plug flash drive, communication freezes. So, I think USB strangely affects stty. I found out that if I disable IGNBRK, there are no freezes, but lot of errors during communication (that's true, I don't need any special characters) Here is COM port initialization:

struct termios options;

tcgetattr (fd, &options);

cfsetispeed (&options, B115200);
cfsetospeed (&options, B115200);

options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~(PARENB | CSTOPB | CSIZE);
options.c_cflag |= CS8;

options.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOCTL | ECHOPRT);
options.c_lflag |= NOFLSH;

options.c_iflag &= ~(INPCK | INLCR | IXON | IXOFF | IXANY | IGNCR | ICRNL | IUCLC);
options.c_iflag |= (IGNBRK | IGNPAR);

options.c_oflag &= ~(OPOST | OFILL);

options.c_cc[VINTR]    = 0;
options.c_cc[VQUIT]    = 0;
options.c_cc[VERASE]   = 0;
options.c_cc[VKILL]    = 0;
options.c_cc[VEOF]     = 0;
options.c_cc[VTIME]    = 0;
options.c_cc[VMIN]     = 1;
options.c_cc[VSWTC]    = 0;
options.c_cc[VSTART]   = 0;
options.c_cc[VSTOP]    = 0;
options.c_cc[VSUSP]    = 0;
options.c_cc[VEOL]     = 0;
options.c_cc[VREPRINT] = 0;
options.c_cc[VDISCARD] = 0;
options.c_cc[VWERASE]  = 0;
options.c_cc[VLNEXT]   = 0;
options.c_cc[VEOL2]    = 0;

tcsetattr (fd, TCSANOW, &options);

fcntl (fd, F_SETFL, FNDELAY);
0

There are 0 best solutions below