2019-10-11 03:01 AM
Hi,
I have design a custom board with the STM32F207VE. But I made a mistake in routing the UART TX as RX and UART RX as TX. Is there a way to change the STM32 UART TX port to an RX through the software?
Solved! Go to Solution.
2019-10-11 06:42 AM
Is there a way to change the STM32 UART TX port to an RX through the software?
Yes. Setting the HDSEL bit in USARTx->CR3 enables half-duplex mode, which uses the TX pin for both transmitting and receiving. Then setting RE and clearing TE in CR1 disables transmitting, so the TX pin will be only receiving.
Note that it doesn't work the other way round, to transmit data you'd need to shift it out one bit at a time on the RX pin, with proper timing and framing (adding start and stop bits)
2019-10-11 03:15 AM
Newer STM32 designs have a pin reverse option for the USART, the F2 and F4 parts are quite old and lack that logic.
You could perhaps implement a software uart, or drive the output via TIM+DMA+GPIO from a pattern buffer.
For getting a prototype board working you could lift the pins and use nano wire or such, or find some point along the traces to remediate.
2019-10-11 06:42 AM
Is there a way to change the STM32 UART TX port to an RX through the software?
Yes. Setting the HDSEL bit in USARTx->CR3 enables half-duplex mode, which uses the TX pin for both transmitting and receiving. Then setting RE and clearing TE in CR1 disables transmitting, so the TX pin will be only receiving.
Note that it doesn't work the other way round, to transmit data you'd need to shift it out one bit at a time on the RX pin, with proper timing and framing (adding start and stop bits)
2019-10-11 07:24 AM
Nice trick, berendi!
JW
2019-10-11 08:21 PM
Hi Berendi & Clive Two,
Thank you for the answers and nice trick. So if I wish to operate in full duplex mode and have UART TX as RX and UART RX as RX, I can only do it through software UART? I have been searching online, STM32 provides emulated UART for STM32F4. Is it possible to use emulated UART on STM32F2?
2019-10-11 08:41 PM
Yes, only way is through software. You can emulate UART on the F2 just as easily as the F4. The code should look similar since it's only accessing GPIO functions. But probably a better time investment to lay out a new board or rework the current one, if possible.
2019-10-11 09:24 PM
Sadly, I do not have sufficient time to lay out a new board. I will need RS422 as well, so operating in half duplex is not going to work. I have tried to convert F4 code to F2 on NUCLEO-F207ZG board but could not get it to transmit data. What could have been wrong? I have attached the project build with STM32CubeIDE.10.1
2019-10-11 09:29 PM
Gonna need more info than "could not get it to transmit data". Why not? What happened? What did you expect?
2019-10-11 10:16 PM
There is no error. The code runs smoothly. The transmit complete is also set. But I could not see the output through Hercules.exe. I am reading the UART output through the NUCLEO-F207ZG's ST-Link UART3.
The NUCLEO-F207ZG has UART3 connected to its ST-LINK. In this case, I am trying to perform a emulated UART instead of using the UART3. Using UART3, I can transmit data and view it using Hercules.exe through STLink Virtual COM port. If using emulated UART, I should see the same results. But no output is detected through STLink Virtual COM port.
2019-10-15 07:19 AM
Check if the output values for DMA have been generated properly. Read out and check the timer registers, to ensure proper timing. Read out and check the relevant GPIO registers for the given pin's settings. Observe the output of the pin using oscilloscope.
JW