cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Nucleo H7A3ZI board UART Issue

mahmanish
Associate II

Hi Community,

I am facing very basic issue. My UART in H7A3ZI Nucleo 144 board is not displaying correctly on terminal. 

My UART Setting: 

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.Init.ClockPrescaler = UART_PRESCALER_DIV1;

huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

if (HAL_UART_Init(&huart3) != HAL_OK)

My Code:

int _write(int file, char *ptr, int len)

{

HAL_UART_Transmit(&huart3, (uint8_t*)ptr, len, HAL_MAX_DELAY);

return len;



}

//and

while (1)

{

/* USER CODE END WHILE */



/* USER CODE BEGIN 3 */

printf("current number is %d\r\n", counter++);

HAL_Delay(500);

}

 

My Buad rate is 115200

This is basic code to get UART output data on ST link virtual serial port that is connected to Laptop.

1 ACCEPTED SOLUTION

Accepted Solutions

@mahmanish wrote:

Can you please explain why it is so 


A fundamental requirement of asynchronous serial comms - ie, UART comms, as here - is that the sender and receiver must be working at the same baud rate.

If the baud rates differ, the receiver will not be able to correctly recognise what was sent.

For reliable comms, the baud rate error should not exceed about 2%.

The above is all entirely general - not specific to ST or STM32.

 

The sending baud rate on your STM32 is derived from the clock; so, if your clock is not what you think, then the baud rate will be wrong - and you will get corrupted comms:

https://learn.sparkfun.com/tutorials/serial-communication/all#:~:text=If%20two%20devices%20aren%27t%20speaking%20at%20the%20same%20speed%2C%20data%20can%20be%20either%20misinterpreted%2C%20or%20completely%20missed.

 

https://electronics.stackexchange.com/questions/7610/what-is-the-maximum-acceptable-baud-rate-error-for-rs-232-serial-communication 

 

This is why I always suggest that people use an oscilloscope or logic analyser to look at the signal on the wire - and verify the actual baud rate.

 

#BaudRateError #SerialGarbage #BaudRate

View solution in original post

5 REPLIES 5

Watch what value HSE_VALUE is using, against the MCO frequency the ST-LINK/V3 is actually generating.

25 MHz / 3 = 8.333333 MHz, not 8.000 MHz

The firmware update tool should provide some clocking options.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi,

 

It is indeed 25 MHz, which i never changed it.

#if !defined  (HSE_VALUE)
#define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

Do i need to make change in this for UART to work properly? Because I have Nucleo F446RE board where i never changed anything and that worked.

Is it because of my nucleo board H7A3ZI which require some special settings?

 

Hello,

Could you please share your ioc file? What clock source you set? HSE or HSI?

If you are using HSE in Bypass mode you need to check the Clock source frequency generated by the ST-LINK over MCO.

Could you please check this information using ST-Link Upgrade tool and see what MCO output is set?

SofLit_0-1724774293519.png

By default it's set to HSE/3 = 8.33MHz

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

 Thank you SofLit,

 

You have pointed me in correct direction, earlier it was put up in PLL. Now i have changed it to HSI and it is coming correctly. 

Can you please explain why it is so or some link where i can get more details about it?


@mahmanish wrote:

Can you please explain why it is so 


A fundamental requirement of asynchronous serial comms - ie, UART comms, as here - is that the sender and receiver must be working at the same baud rate.

If the baud rates differ, the receiver will not be able to correctly recognise what was sent.

For reliable comms, the baud rate error should not exceed about 2%.

The above is all entirely general - not specific to ST or STM32.

 

The sending baud rate on your STM32 is derived from the clock; so, if your clock is not what you think, then the baud rate will be wrong - and you will get corrupted comms:

https://learn.sparkfun.com/tutorials/serial-communication/all#:~:text=If%20two%20devices%20aren%27t%20speaking%20at%20the%20same%20speed%2C%20data%20can%20be%20either%20misinterpreted%2C%20or%20completely%20missed.

 

https://electronics.stackexchange.com/questions/7610/what-is-the-maximum-acceptable-baud-rate-error-for-rs-232-serial-communication 

 

This is why I always suggest that people use an oscilloscope or logic analyser to look at the signal on the wire - and verify the actual baud rate.

 

#BaudRateError #SerialGarbage #BaudRate