cancel
Showing results for 
Search instead for 
Did you mean: 

Bug when starting a UART port with UART inversion enabled on STM32303 and STM32F722

mlars.1
Associate

Hello ST

I have a project where I need to start and stop the UART during runtime, and I have noticed a possible bug in the stm32f3xx_hal_uart.c file.

The issue is that when initializing the UART to use the UART_ADVFEATURE_TXINVERT_INIT parameter, the Tx pin goes high for a very short time (~10us). I suspected that it was because the inversion of the pin took place after the UART was started, and i did some digging in the HAL code.

0693W00000YAugEQAT.png 

By setting the breakpoints as above, i concluded that the signal that was on the Tx pin was high after UART_SetConfig was called, and it went low again after UART_AdvFeatureConfig was called. This seems to me that the pin goes high (UART Idle), before the inversion takes place (UART idle low after inversion).

0693W00000YAudUQAT.jpgThe Tx pin viewed under an oscilloscope where the code is initializing and deinitializing the UART every ~100ms, resulted in a consistent voltage spike.

0693W00000YAubOQAT.pngI tried to confirm my suspicion by swapping the order the two functions were called, so the inversion took place before setting the config, and that seemed to fix the issue.

To check if it was a hardware specific issue, i also checked on an STM32F722, and the behavior was the same.

Uart parameters used:

BAUD: 100000

Databits: 8

Stopbits: 2

Parity: even

Tx inversion: enabled

HAL version on stm32f303: V1.5.6

14 REPLIES 14

Hello,

In step by step debug, pin never goes high. It is configured as PP.

After init, due to this, code stucks in RX interrupt. But now I'm thinking, why is RX push pull when it needs to receive signal? :)

BR,

Miroslav 

miroslav
Associate III

Ah, I answered my questionby myself. Thanx Tesla :)

Generated code by stm cube is a bit wrong.

miroslav
Associate III

Ah, no. There is no such thing as  GPIO_MODE_AF_INPUT. Any clue?

miroslav
Associate III

OK, I was totally wrong. It was not RX but TX. Interrupt routine confused me.
So, RX is always in interrupt because inversion actually didn't happen at all. Logic one on RX keeps it in receive interrupt. TX is low as no transmit occur. It means that TX and RX were not inverted at all.

Here is code for STM476:

 

 

static void MX_USART3_UART_Init(void)

{

huart3.Instance = USART3;

huart3.Init.BaudRate = 115200;

huart3.Init.WordLength = UART_WORDLENGTH_8B;

huart3.Init.StopBits = UART_STOPBITS_1;

huart3.Init.Parity = UART_PARITY_NONE;

huart3.Init.Mode = UART_MODE_TX_RX;

huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart3.Init.OverSampling = UART_OVERSAMPLING_16;

huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 

huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_TXINVERT_INIT|UART_ADVFEATURE_RXINVERT_INIT;

huart3.AdvancedInit.TxPinLevelInvert = UART_ADVFEATURE_TXINV_ENABLE;

huart3.AdvancedInit.RxPinLevelInvert = UART_ADVFEATURE_RXINV_ENABLE;

if (HAL_UART_Init(&huart3) != HAL_OK)

{

Error_Handler();

}

}

Any clue on this?

miroslav
Associate III

OK, problem resolved. Wrong interpretation from my side. RX and TX are active low in non inverted operation.
I thought non inverted is active high.