cancel
Showing results for 
Search instead for 
Did you mean: 

BUG: Incorrect handling of halfduplex UART with TX/RX pin swap enabled (v. 5.0.1)

kha
Associate II

It seems that STM32CubeMX does not properly handle tx/rx swap when UART is set to half duplex mode.

Steps to reproduce

-start a project with a MCU with pin swappable uart, like STM32F030x

-enable UART in half duplex mode

-enable pinswapping

The incorrect behavior can be seen on CubeMX GUI as the wrong CPU pin is highlighted as well as in generated code where the GPIO config in xxxx_hal_msp.c is done for the TX pin instead of RX.

8 REPLIES 8

Hi @kha​ 

According to the reference manual, in half duplex mode, the TX pin is a standard I/O in receive or in transmit. That's why only the TX pin is highlighted.

0690X000006Dl8CQAS.png

Regards,

Nesrine.

kha
Associate II

Then there is the 'SWAP' which exchanges the RX and TX pins, notably it will make halfduplex to use the pin normallyused for RX. I have confirmed this to be the case with hardware.

kha
Associate II

0690X000006DlGLQA0.png

Hi @kha​ 

As shown in the figure, in USART single wire half duplex mode:

  • TX and RX lines are internally connected
  • TX pin is used for both transmission and reception ==> Only TX pin is used (RX is no longer used)

0690X000006DlREQA0.png

So, SWAP will exchange the TX and TX pins .

Regards,

Nesrine.

kha
Associate II

Ok, you lost me this time...

You seem to ignore the fact that I have tested this on real hardware, if swap is enabled on halfduplex UART the physical pin will change.

The "halfduplex" mode connects the TX and RX lines internally on one UART to its TX line, now the swapping feature is on the IO pin side of this and thus will map the (combined) UART TX signal to the RX pin0690X000006DlTtQAK.png.

Hi @kha​ 

Thank you for the feedback.

You are right, i was able to reproduce the issue and it will be fixed in the next CubeMX release.

Best Regards,

Nesrine.

kha
Associate II

Hi Nesrine,

Thank you for your efforts, this is a very corner case but it is good to have it patched up.

Best regards, Kari

trv
Associate

This still seems to be broken in Stm32CubeIDE v1.13.1 (with included Stm32CubeMX v6.9.1).

Repro steps:

  1. Start a new project with STM32G431KBU3.
  2. Enable USART1 as "Single Wire (Half-Duplex). PA9 is assigned as USART1_TX.
  3. Enable "TX and RX Pins Swapping". PA9 is still incorrectly assigned as USART1_TX. This should have moved to PA10 as this configuration uses the USART1_RX pin instead.