Skip to main content
JTan
Associate II
October 11, 2019
Solved

STM32F207VE UART Routing mistake

  • October 11, 2019
  • 9 replies
  • 1787 views

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?

This topic has been closed for replies.
Best answer by berendi

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)

9 replies

Tesla DeLorean
Guru
October 11, 2019

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.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
berendi
berendiBest answer
Principal
October 11, 2019

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)

waclawek.jan
Super User
October 11, 2019

Nice trick, berendi!

JW

JTan
JTanAuthor
Associate II
October 12, 2019

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?

TDK
October 12, 2019

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JTan
JTanAuthor
Associate II
October 12, 2019

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

TDK
October 12, 2019

Gonna need more info than "could not get it to transmit data". Why not? What happened? What did you expect?

"If you feel a post has answered your question, please click ""Accept as Solution""."
JTan
JTanAuthor
Associate II
October 12, 2019

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.

waclawek.jan
Super User
October 15, 2019

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