cancel
Showing results for 
Search instead for 
Did you mean: 

Error in default HSI calibration value in LL generated code for NCULEO L452RE

GSchr.3
Associate

This topic was covered for the case of HAL in this thread:

https://community.st.com/s/question/0D53W00000rZAQM/default-hsi-calibration-value-wrong-in-stm32cubeide

But my case is for LL which still seems to have this issue, in the generated code.

I found this problem because the baud rate of 115200 on USART2 was so far off that serial comms was not possible. This is only a problem when RCC is set to use LL. When RCC is set to use HAL, the correct value of 64 is used for HSI calibration and I had no serial comms problem.

I believe I am on latest STM32CubeIDE software and toolchain repository for my board:

STM32CubeIDE:

Version: 1.6.1

Build: 9958_20210326_1446 (UTC)

Repository version: STM32Cube_FW_L4_V1.17.0

Another issue: It seems the Configuration Pane for RCC will not let me set this parameter (HSI Calibration Value) to the correct default value of 64. It is being limited to 31.

The generated code from main.c is below. The line in question is:

LL_RCC_HSI_SetCalibTrimming(16);

-----------------------------

void SystemClock_Config(void)

{

 LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);

 while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_4)

 {

 }

 LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);

 LL_RCC_HSI_Enable();

  /* Wait till HSI is ready */

 while(LL_RCC_HSI_IsReady() != 1)

 {

 }

 LL_RCC_HSI_SetCalibTrimming(16);

 LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 10, LL_RCC_PLLR_DIV_2);

 LL_RCC_PLL_EnableDomain_SYS();

 LL_RCC_PLL_Enable();

  /* Wait till PLL is ready */

 while(LL_RCC_PLL_IsReady() != 1)

 {

 }

 LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);

  /* Wait till System clock is ready */

 while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)

 {

 }

 LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);

 LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);

 LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);

 LL_Init1msTick(80000000);

 LL_SetSystemCoreClock(80000000);

 LL_RCC_SetUSARTClockSource(LL_RCC_USART2_CLKSOURCE_PCLK1);

 LL_RCC_SetUSARTClockSource(LL_RCC_USART3_CLKSOURCE_PCLK1);

}

2 REPLIES 2
GSchr.3
Associate

I forgot to add: when setting RCC to use LL, if I edited the generated code to use 64 (rather than 16) for HSI calibration, this also fixed the problem. So it is very clear that is what the problem is.

Imen.D
ST Employee

Hello @GSchr.3​ and welcome to the Community :)

Thanks for your reported issue.

I rasied this to CubeMX team for check and analysis.

Thanks

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen