ls1021a : How to use lpuart1 as an RS485 serial link ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ls1021a : How to use lpuart1 as an RS485 serial link ?

1,734 Views
ThomasMeyer
Contributor I

Hi Community,

I have a question regarding the fsl-lpuart driver.

I made the following entry in my device tree:

 

&lpuart0 {
	linux,rs485-enabled-at-boot-time;
	status = "okay";
};

 

 And in the defconfig for my device I enabled the Lpuart drivers.

The interface is wired on the board as follows:

RS485.png

 

 

 

 

 

 

 

 

Under tty I have a ttyLP0 device and if I use following command:

 

echo Y > /dev/ttyLP0

 

I can send the character to my PC. Sendign from my device works fine. But now, the driver doesn´t pull down the LPUART_RTS pin. Everytime this pin is high. And the RTS pin does the same if I try to read character on my device.

 

cat /dev/ttyLP0

 

But read doesn´t work because the RTS pin is high.

Does anyone have experience with LPUART and RS485 and can help me? 

thx

best regards

t.meyer

 

 

0 Kudos
7 Replies

1,711 Views
ThomasMeyer
Contributor I

not really

Does that mean there is an error in the lpuart32_config_rs485() ?

0 Kudos

1,706 Views
yipingwang
NXP TechSupport
NXP TechSupport

Yes, please try to use lpuart32_config_rs485 in the above thread to replace lpuart_config_rs485 in drivers/tty/serial/fsl_lpuart.c.

0 Kudos

1,621 Views
Niklas
Contributor I

That would not help. As the ls1021a_data struct is hard configured to UPIO_MEM32BE. So the driver defaults to the lpuart32 API.

 

A little debugging showed that the driver goes into suspended state. When the driver is accessed, the function lpuart32_startup is called. This function calls  device_reset(), which resets the lpuart device and also the modem configuration. But the rs485 configuration is only applied during the device probing. So it is not reapplied after the device_reset() call.

And I am also confused. The mainline Kernel 5.10.9 from git.kernel.org/linux-stable/linux-5.10.y does not call device_reset() but the QorIQ Linux from https://source.codeaurora.org/external/qoriq/qoriq-components/linux/log/?h=linux-5.10 does so (Gatesgarth yocto-sdk). It is both the fsl_lpuart driver, why does it differ so much although it is the same kernel version? 

0 Kudos

1,641 Views
ThomasMeyer
Contributor I

any new ideas or knowledge?

0 Kudos

1,720 Views
yipingwang
NXP TechSupport
NXP TechSupport

Please check whether the resolution in the following thread would be helpful.

https://community.nxp.com/t5/QorIQ/ls1043-How-to-use-lpuart1-as-an-RS485-serial-link/m-p/772749

0 Kudos

1,666 Views
ThomasMeyer
Contributor I

If you rewrite the modem register in a C program, sending and receiving work. So, the modem register is reset by the driver or by the tty device? 

I removed the reset from startup. in lpuart32_startup() but no success.

Unfortunately, I don't even know whether lpuart32_startup or lpuart_startup is called. 

Perhaps the register is also written incorrectly in the Config function lpuart32_config_rs485() or lpuart_config_rs485(). the difference are the readb / writeb funktions and modem is u8 type. For _32 the lpuart32_read/lpuart32_write functions are used and modem is unsigned long type. 

The RTS pin is not changed because the modem register is corrupt!?! Anyone has the same problem and any solution ?

Thx

0 Kudos

1,658 Views
Niklas
Contributor I

I did some further testing and could also reproduce the behaviour. The test was done with qoriq linux tag lf-5.10.y-1.0.0 on an adjusted ls1021a board with a comparable RS485 transceiver. Before accessing the tty device, the LPUART Modem IrDA Register is configured correct. It is set to:

TXRTSPOL = 1

TXRTSE = 1

The signal levels are also correct.

But if the tty device is opened, the LPUART Modem IrDA Register is reset to its default value (every bit is 0). But the driver returns the initially set up rs485 configuration via  ioctl command TIOCGRS485. So the driver and hardware states differ. When den queried rs485 configuration is written back to the driver with the ioctl command TIOCSRS485 the modem has also the correct configuration and everything works fine.

But then if the tty device file is closed, the LPUART Modem IrDA Register is reset to default values again. My assumption is that there is a bug when opening and closing the tty device.

0 Kudos