Skip to main content
po221
Senior
August 9, 2022
Solved

USART2 on STM32L431 does not support parity with CubeMx

  • August 9, 2022
  • 3 replies
  • 3880 views

Hello

I'm using a stm32L431. here the documentation :

https://www.st.com/en/microcontrollers-microprocessors/stm32l4x1.html#documentation

HSI is enabled at 16MHz for USART2, used to receive a 1200Bd signal (7bit data + even parity + 1 stop).

I receive wrong characters because of the trim. of parity

I already asked a question about the TRIM but that's not the problem

https://community.st.com/s/question/0D53W00001iwHrbSAE/how-to-trim-the-stm32-hsi-easily

I connect a USB converter (With FT232) on the RX of UART2 to send data to the stm32

I use CubeMx to configure UART2

>> Case 1 that works : (no parity)

Configuration by CubeMX :

 huart2.Instance = USART2;

 huart2.Init.BaudRate = 1200;

 huart2.Init.WordLength = UART_WORDLENGTH_8B;

 huart2.Init.StopBits = UART_STOPBITS_1;

 huart2.Init.Parity = UART_PARITY_NONE;

 huart2.Init.Mode = UART_MODE_RX;

 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart2.Init.OverSampling = UART_OVERSAMPLING_16;

 huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if (HAL_UART_Init(&huart2) != HAL_OK)

Teraterm configuration :

0693W00000QNIhrQAH.pngI receive the data without fault...

>> Case 2 not working : (even parity)

Configuration by CubeMX :

huart2.Instance = USART2;

 huart2.Init.BaudRate = 1200;

 huart2.Init.WordLength = UART_WORDLENGTH_8B; // including parity

 huart2.Init.StopBits = UART_STOPBITS_1;

 huart2.Init.Parity = UART_PARITY_EVEN;

 huart2.Init.Mode = UART_MODE_RX;

 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart2.Init.OverSampling = UART_OVERSAMPLING_16;

 huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if (HAL_UART_Init(&huart2) != HAL_OK)

Teraterm configuration :

0693W00000QNIiLQAX.pngHere I receive wrong things, part of the characters are correct, another incoherent

I know that the probability is high that the problem is between the keyboard and the chair but... I'm standing, without a chair! so it can come from a concern of HAL as for the TRIM which is strangely managed?

Thanks in advance

This topic has been closed for replies.
Best answer by Tesla DeLorean

You will need to mask the parity bit off data read in such a fashion

ie int data = USART2->RDR & 0x7F; // mask down to 7-bit

3 replies

waclawek.jan
Super User
August 9, 2022

> Teraterm configuration :

Probably failed screenshot insertion? Try through uploading, on bottom of the editor window click on the "picture" icon.

Also, read out the USART registers content and check/post.

JW

Tesla DeLorean
Guru
August 9, 2022

You will need to mask the parity bit off data read in such a fashion

ie int data = USART2->RDR & 0x7F; // mask down to 7-bit

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
po221
po221Author
Senior
August 9, 2022

I'm afraid to understand...

When using parity do we need to manually remove the parity bit?

Here I recover the data by the DMA ; I have to loop on all my buffer to delete the 7th bit of all buffer éléments ?

I'm testing...it would correspond well to the fact that some characters pass and others do not

po221
po221Author
Senior
August 9, 2022

>> Case 1 that works : (no parity)

0693W00000QNIoiQAH.png 

>> Case 2 not working : (even parity)

0693W00000QNIpMQAX.png