'How to change the size of the system buffer in linux for uart?
Please tell me, I'm making a uart logger based on arabian linux on an orange pizero single-board computer, the following code turned out, but I can't beat the problem. I lose information if I transfer large text files, the order of several hundred bytes inside the text disappears. My assumptions are related to the overflow of the system buffer, but I could not figure out how to increase it using the ioctl() system call. The transfer rate is 921600.
My code-
struct termios2 SerialPortSettings;
ioctl(fd_uart,TCGETS2,&SerialPortSettings);
SerialPortSettings.c_cflag &= ~CBAUD; //Remove current baud rate
SerialPortSettings.c_cflag |= BOTHER; //Allow custom baud rate using int input
SerialPortSettings.c_ispeed = 921600; //Set the input baud rate
SerialPortSettings.c_ospeed = 921600; //Set the output baud rate
//tcgetattr(fd_uart, &SerialPortSettings); /* Get the current attributes of the Serial port */
/* Setting the Baud rate */
// cfsetispeed(&SerialPortSettings,921600); /* Set Read Speed as 921600 */
// cfsetospeed(&SerialPortSettings,921600); /* Set Write Speed as 921600
/* 8N1 Mode */
SerialPortSettings.c_cflag &= ~PARENB; //Disables the Parity Enable bit(PARENB),So No Parity
SerialPortSettings.c_cflag &= ~CSTOPB; /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
SerialPortSettings.c_cflag &= ~CSIZE; /* Clears the mask for setting the data size */
SerialPortSettings.c_cflag |= CS8; /* Set the data bits = 8 */
SerialPortSettings.c_cflag &= ~CRTSCTS; /* No Hardware flow Control */
SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines */
SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY); /* Disable XON/XOFF flow control both i/p and o/p */
SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ISIG | ECHOE| IGNCR); /* Non Cannonical mode */
//SerialPortSettings.c_lflag = 0;
SerialPortSettings.c_oflag &= ~OPOST;/*No Output Processing*/
// ioctl(fd_uart, TIOCINQ, 8000);
// ioctl(fd_uart, TIOCOUTQ, 8000);
// serial_struct serinfo;
// memset(&serinfo, 0, sizeof(serinfo));
// ioctl(device_handler, TIOCGSERIAL, &serinfo);
// serinfo.xmit_fifo_size;
// /* Setting Time outs */
SerialPortSettings.c_cc[VMIN] = 0;
SerialPortSettings.c_cc[VTIME] = 0;
// serial_struct serinfo;
// memset(&serinfo, 0, sizeof(serinfo));
// ioctl(device_handler, TIOCGSERIAL, &serinfo);
// serinfo.xmit_fifo_size;
tcflush(fd_uart, TCIOFLUSH); /* Discards old data in the rx buffer*/
//tcsetattr(fd_uart, TCSANOW, &SerialPortSettings);
if((ioctl(fd_uart, TCSETS2, &SerialPortSettings)) != 0) /* Set the attributes to the termios structure*/
printf("\n ERROR ! in Setting attributes\n");
else{
printf(" BaudRate = 921600 \n StopBits = 1 \n Parity = none \n");
}
Solution 1:[1]
Non Cannonical mode
In non-cannonical mode, the buffer is fixed at 4096 characters. This is following the documentation, see man termios and https://elixir.bootlin.com/linux/latest/source/drivers/tty/n_tty.c#L1583 . The kernel setting is like here https://elixir.bootlin.com/linux/latest/source/include/linux/tty.h#L247 .
How to change the size of the system buffer in linux for uart?
Recompile the kernel with bigger value of the buffer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KamilCuk |
