cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F207VE UART Routing mistake

JTan
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

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)

View solution in original post

9 REPLIES 9

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 Up vote any posts that you find helpful, it shows what's working..
berendi
Principal

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)

Nice trick, berendi!

JW

JTan
Associate II

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
Guru

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
Associate II

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
Guru

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
Associate II

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.

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