Skip to main content
Graduate
February 5, 2024
Question

STM32 UART stops At High Temperature

  • February 5, 2024
  • 5 replies
  • 3278 views

Hi,

I am Using an stm32f205 on our board. All the Uarts works fine at room temperature. But when the temp increases above 58 degress, messages started get missed in the uarts or sometimes it completely stops sending messages.

I am running the board at 120MHZ Here is my clock setup 

RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 13;
  RCC_OscInitStruct.PLL.PLLN = 195;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  {
    Error_Handler();
  }
 
Any help would be much appreciated 
    This topic has been closed for replies.

    5 replies

    Super User
    February 5, 2024

    HSI is not a particularly accurate source, especially over temperature. That's likely the cause of communication problems. Consider using an external crystal instead or other accurate clock source.

    You can also adjust RCC_HSICALIBRATION_DEFAULT if you have a means of measuring/calibrating it.

    JThom.15Author
    Graduate
    February 5, 2024

    Thanks for the response. Currently we don't have any source for measuring/calibrating HSI.

    Is there any other hack around without using an external clock

    Super User
    February 5, 2024

    Adjust RCC_HSICALIBRATION_DEFAULT randomly until it works.

    Technical Moderator
    February 5, 2024

    Well, the UART works asynchronously and the bits are already sampled with oversampling when UART signals are read in, so as @TDK mentioned, a clock with a corresponding accuracy is required. If you absolutely want to use UART, you must have an appropriate clock; stable communication cannot be guaranteed with internal clock sources.

    Unfortunately, the STM32F2 does not yet have an ABR (Automatic Baud Rate, AN4908) function.

    Regards
    /Peter

    Super User
    February 5, 2024

    As the others have said, UART communication absolutely relies upon the accuracy of the clock - an uncalibrated RC really isn't going to be good enough over a wide temperature  range.

    This is nothing specifically to do with STM32 - the same applies to any microcontroller.

     

    BTW:

    Use this button to properly post source code:

    AndrewNeil_0-1707124989557.png

     

    To get that extra row of icons, press this button:

    AndrewNeil_1-1707124989564.png

    Graduate II
    February 5, 2024

    Try to lower the baud rate, if nothing else works.

    HSI is ... terrible...

    Technical Moderator
    February 5, 2024

    A lower baud rate will not help because the frequency stability of the HSI is relative and has the same effect on all derived baud rates. Only a stable clock can help here, which is unfortunately only available from HSI in a limited temperature range.

    JThom.15Author
    Graduate
    February 5, 2024

    Our board has an esp32 also which is used to connect to internet. Would it be possible to use the Epoch timestamp to calibrate the HSI?