Skip to main content
KAsim
Associate II
May 26, 2019
Question

STM32L412C8 USART2 RX TX pin swap not working

  • May 26, 2019
  • 11 replies
  • 3732 views

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?

This topic has been closed for replies.

11 replies

Uwe Bonnes
Chief
May 26, 2019

Did you configure PA2 as peripheral?

KAsim
KAsimAuthor
Associate II
May 26, 2019

Yes, and I tried both push-pull and open drain.

S.Ma
Principal
May 26, 2019

Both pins should be alternate function configured. Otherwise, check the errata sheet.

KAsim
KAsimAuthor
Associate II
May 26, 2019

Both have been configured for USART2. The errata sheet has nothing relevant.

S.Ma
Principal
May 26, 2019

I've got STM32L4R5 connected to HC-06 BT module with wires, will give it a try tomorrow to check it at my desk.

S.Ma
Principal
May 27, 2019

Well it works on stm32l4r5. However, UE can t apparently be reset manually in debug mode.

KAsim
KAsimAuthor
Associate II
May 27, 2019

Would you mind sharing your code or the ioc file from CubeMX?

waclawek.jan
Super User
May 27, 2019

OP's problem may also be the way how Rx is handled, regardless of the swap...

JW

KAsim
KAsimAuthor
Associate II
May 27, 2019

What do you mean? I have used both HAL and LL functions to receive data and the result was the same.

waclawek.jan
Super User
May 27, 2019

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
KAsimAuthor
Associate II
May 28, 2019

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

KAsim
KAsimAuthor
Associate II
May 27, 2019

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.

waclawek.jan
Super User
October 11, 2019

Hi @KAsim​  ,

Have you solved this issue?

JW

KAsim
KAsimAuthor
Associate II
October 12, 2019

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.

waclawek.jan
Super User
October 12, 2019

Thanks anyway for the info.

JW