2024-03-21 04:25 AM
Hi all.
We are using a bidirectional UART with hardware-flow control lines (RTS/CTS) between two microcontrollers.
One of the controllers (A) is an STM32H7, the other controller's type (B) should not be relevant. I write this from the perspective of A.
A's peripheral is configured with the correct baudate, word configuration and 16x oversampling.
We're using STM32 HAL drivers and initially configure the UART as follows:
(where mUartHandle is basicaly of type UART_HandleTypeDef)
Please note that this is only a snippet to demonstrate our function calls as return values are handled in our code.
So far, so good - communication has been working so far.
A new requirement in our project is that A now needs to control the reset line of B during runtime for multiple times.
This introduces a new challenge:
Assume UART of A is already configured, B is kept in reset (by A, reset line B_nRST is active low). While B is in reset, its TX line is not at the usual UART idle high level but at low level. A controls B out of reset. It takes some time until B comes out of reset and finally pulls its TX line to UART idle high level.
Afterwards, B transmits data and A controls its CTS line as expected. The bigger picture:
Let's zoom to the very end. After exchanging some data, A will put B back to reset (zoomed in at the end of the previous screenshot):
It can be seen that after having pulled the reset line low, that B's TX line falls from UART idle high level to low.
Having B's UART TX line low leads to framing errors in A's UART peripheral in the RX path. (That spike in the CTS signal may be an artifact that originates from A UART de-initialization.)
B is kept in reset for a while. Before starting another phase of UART communication, B is pulled out of reset again and the procedure is expected to repeat, but I only see two "unexpected" cases:
Case 1) A's CTS line is permanently pulled high after A has received the first byte from B so that B will stop sending any furhter data:
Case 2) A's CTS line is permanently pulled high from the very beginning:
Cases 1 and 2 may stem from two different approaches when trying to re-initialize A's UART peripheral.
TL;DR: My core questions are:
What I've tried so far:
For "de-init" of A's UART after reset of B:
For "re-init" of A's UART after pulling B out of reset:
As an alternate approach I see a way to prevent framing errors coming from B's resets (from A's perspective again):
However, I don't know if this approach is a good way - it seems more tedious and error-prone and the UART may still be not re-configured properly.
Your help is very much appreciated!