cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L412C8 USART2 RX TX pin swap not working

KAsim
Associate II

I am using the STM32L412C8 and I am having trouble with the USART2 RX/TX pin swapping. I enabled it in CubeMX but if I send data to the PA2 pin (originally TX but should be RX after the swap) I get nothing. If however I send my data to PA3(should be TX after the swap) data instantly comes in. Checking the CR2 register of the USART, the SWAP bit is set.

What am I doing wrong?

17 REPLIES 17

And what about a simple status-register-based polling loop?

You could also read out and post the content of the UART registers, and maybe also the relevant GPIO registers.

Have you observed the received waveform directly on the Rx pin, using oscilloscope or LA?

Can you disconnect the target device and loop back Tx to Rx?

JW

KAsim
Associate II

I will try it tommorow and I'll let you know.

I have connected a USB-to-Serial in parallel and I can read data correctly so the waveform seems to be OK.

I can't disconnect it as it's soldered on a PCB but I might be able to short the two pins together.

Thank you for your help either way.

So an update:

A simple polling of RDR shows nothing received.

The USART registers are: CR1: 0xd , CR2: 0x8000, CR3:0

GPIOA MODER:0x6aa8a6a8 (so PA2, PA3 are 0x2)

GPIOA AFRL2=0x7,AFRL3=0x7

Also, trying to use LPUART1 instead as it can be mapped to the same pins and also swap TX/RX has the exact same problem.

Hi @KAsim​  ,

Have you solved this issue?

JW

KAsim
Associate II

Due to changes in the project, the whole PCB was redesigned, eliminating the need for pin swapping.

I never did manage to actually track down the problem though.

Thanks anyway for the info.

JW

DOsbo
Senior

I have the same problem with an STM32F030RC.  The UART has been configured with the Swap bit enabled (verified), but I get nothing on the new Tx line.  Disabling the Swap bit allows data to be sent on the original Tx line. I'd like to know if anyone has got Tx/Rx swapping working?