From: Eberhard Stoll <eberhard.stoll@gmx.de>
To: sherry.sun@nxp.com
Cc: festevam@gmail.com, gregkh@linuxfoundation.org,
jirislaby@kernel.org, kernel@pengutronix.de,
linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
rasmus.villemoes@prevas.dk, s.hauer@pengutronix.de,
shawnguo@kernel.org, eberhard.stoll@kontron.de
Subject: RE: [PATCH] serial: imx: also enable Transmit Complete interrupt in rs232 mode
Date: Tue, 21 Nov 2023 21:49:01 +0100 [thread overview]
Message-ID: <dbe5959d-2b68-4f16-89ee-32538aab4f34@gmx.de> (raw)
In-Reply-To: <AS8PR04MB8404D066C247F5B2979CBD1F92BBA@AS8PR04MB8404.eurprd04.prod.outlook.com>
> Currently, if one switches to rs232 mode, writes something to the
> device, and then switches to rs485 mode, the imx_port's ->tx_state is
> left as SEND. This then prevents a subsequent write in rs485 mode from
> properly asserting the rts pin (i.e. enabling the transceiver),
> because imx_uart_start_rx() does not enter the "if (sport->tx_state ==
> OFF)" branch. Hence nothing is actually transmitted.
>
> The problem is that in rs232 mode, ->tx_state never gets set to OFF,
> due to
>
> usr2 = imx_uart_readl(sport, USR2);
> if (!(usr2 & USR2_TXDC)) {
> /* The shifter is still busy, so retry once TC triggers */
> return;
> }
>
> in imx_uart_stop_tx(), and TC never triggers because the Transmit
> Complete interrupt is not enabled for rs232.
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
> I'm not sure this is the best fix.
>
> At first I considered doing something much more targeted, but
> definitely also more hacky: In imx_uart_rs485_config(), if switching
> on rs485 mode, simply add "sport->tx_state = OFF;".
>
> If someone has a better suggestion, I'm all ears.
Hello Rasmus,
i can observe a very similar situation, but with a litte different
configuration. This is how i can trigger the situation very quickly:
1) open the port
2) send 1 byte out
3) close the port
Do it in a loop. As faster, the lockup may occur earlier (but not
mandatory, 100ms is sufficient in my setup at 115200 Baud on an
i.mx8mm board).
With this configuration i get the lockup in around 1 minute.
For my setup it's clear what happens:
- when the tty is closed imx_uart_shutdown() is called. This calls
imx_uart_stop_tx()
- for a lockup, the shifter is still busy and imx_uart_stop_tx()
returns early (as you explained) without modifying ->tx_state.
- imx_uart_shutdown() proceeds and finally closes the port. Due to
imx_uart_stop_tx() is not executed completely tx_state is left in
state ->tx_state == SEND.
- When the port is opened again, tx_state is SEND and nothing can
be transmitted any more. The tx path has locked up!
Setting ->tx_state = SEND in imx_uart_shutdown() helps for my issue
(and should be ok IMHO).
But IMHO there is one next issue with this situation: When the port
operates with WAIT_AFTER_RTS and WAIT_AFTER_SEND then some timers
for callback functions might be active. I did not discover where they
are stopped for the case when the serial port is closed. Maybe stopping
is not required ...
I'd appreciate someone with more experience could review or revise it
Best Regards
Eberhard
next prev parent reply other threads:[~2023-11-21 20:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 13:22 [PATCH] serial: imx: also enable Transmit Complete interrupt in rs232 mode Rasmus Villemoes
2023-11-21 6:37 ` Sherry Sun
2023-11-21 7:26 ` Rasmus Villemoes
2023-11-21 20:49 ` Eberhard Stoll [this message]
2023-11-22 8:03 ` Rasmus Villemoes
2023-11-22 9:31 ` Eberhard Stoll
2023-11-22 13:01 ` Frieder Schrempf
2023-11-22 13:34 ` Rasmus Villemoes
2023-11-21 20:59 ` Eberhard Stoll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dbe5959d-2b68-4f16-89ee-32538aab4f34@gmx.de \
--to=eberhard.stoll@gmx.de \
--cc=eberhard.stoll@kontron.de \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=rasmus.villemoes@prevas.dk \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=sherry.sun@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox