2020-07-04 10:20 PM
Apparently it is not possible to set a custom baud rates for UARTs on the STM32MP1.
ioctl TIOCSSERIAL fails. With a USB UART dongle that supports custom baud rates this works. Is there a something that can be changed in the device tree or config to enable custom baud rate support on the STM32MP1 U(S)ARTS ? The base rate seems 4MHz so that should be sufficient for several custom baud rates. Looked at stm32-usart.c but did not find supporting code. Custom baud rate is crucial as the serial device connected must be used with a non standard baud rate.
Edit: after looking at stm32-uart.c it seems it is not supporting ioctl. Adding this support looks to be pretty straightforward by adding the ioctl call and the 2 or 3 needed functions to set and get the user info together with the magic baudrate hack. The driver seems to use uart structure instead of the tty structures so I did not get far changing the driver.. A developer familiar with the driver probably could do this in a day. If STM could reply this post with a beta version of such stm32-uart.c that would be great to be able to move forward.
Edit : Since no reply from ST, have no other option and have started to change the driver myself to add the ioctcl's... and related code.
Solved! Go to Solution.
2020-07-09 02:15 AM
TIOCSSERIAL looks like deprecated, try TCSETS2
struct termios2 tio;
ioctl(fd, TCGETS2, &tio);
tio.c_cflag &= ~CBAUD;
tio.c_cflag |= BOTHER;
tio.c_ispeed = custom_baudrate;
tio.c_ospeed = custom_baudrate;
ioctl(fd, TCSETS2, &tio);
2020-07-08 01:29 AM
Hi,
have you already look at this page?
https://wiki.st.com/stm32mpu/wiki/Serial_TTY_overview
you may change the baud rate using this command for instance 4MB/s
/* USART3 port configuration and opening for RX */
cat /proc/tty/driver/stm32-usart /* serial counters and modem lines state per UART */
stty -F /dev/ttySTM1 4000000 cs8 -parenb parodd -echo -icanon -onlcr ocrnl onlret crtscts
cat /dev/ttySTM1 & /* port opening for RX, only for tests 2 and 3 */
cat /proc/tty/driver/stm32-usart /* serial counters and modem lines state per UART */
0: uart:stm32-usart mmio:0x40010000 irq:52 tx:11212 rx:517 RTS|CTS|DTR|DSR|CD
1: uart:stm32-usart mmio:0x4000F000 irq:50 tx:211 rx:0 CTS|CD
2: uart:stm32-usart mmio:0x40018000 irq:53 tx:0 rx:0 CTS|DSR|CD
Otherwise the serdev interface might be an option.
2020-07-09 12:17 AM
Hi,
Yes I looked at that page, I also checked again and did not find the text you may change the baud rate using this command for instance or /* USART3 port configuration and opening for RX */on that page. Could 4000000 work because this is a high custom baud-rate (actually it is the base rate, so the divider is 1) and not a custom one that is somewhere in the standard defined range, say under 115200 ? my code uses TIOCGSERIAL and TIOCSSERIAL and this works with interfaces/drivers that support custom rates . Looked at the st32-usart.c code and did not found supporting code. I am not sure what stty does to set the rate but will try. I actually wish to set the rate from C code or to the custom rate at boot time. Not familiar with serdev (how to find the ports , how to call the API from C )
2020-07-09 02:15 AM
TIOCSSERIAL looks like deprecated, try TCSETS2
struct termios2 tio;
ioctl(fd, TCGETS2, &tio);
tio.c_cflag &= ~CBAUD;
tio.c_cflag |= BOTHER;
tio.c_ispeed = custom_baudrate;
tio.c_ospeed = custom_baudrate;
ioctl(fd, TCSETS2, &tio);
2020-07-12 05:39 AM
Thanks, that worked.