Skip to main content
Graduate
November 13, 2024
Question

LSI frequency not stable when switching power

  • November 13, 2024
  • 0 replies
  • 553 views

Hello everyone,

I'm working on a project using STM32U031, and using RTC with LSI(32kHz) to calculate elapsed time, and everything working fine, the waveform of LSI output also looks great.

And I need to switching power supply in sometimes, and there could happen the frequency of LSI become weird and average frequency change to ~52kHz, so i using LSCO and MCO2 to output the LSI and HSI, the HSI working fine when LSI abnormal, just like picture blow:

kein_1-1731487049901.png

And here is my code to initial system clock which is copy from cubeMX:

void SystemClock_Config(void)
{
 LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
 while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1);

 LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE2);
 while (LL_PWR_IsActiveFlag_VOS() != 0);
 LL_RCC_HSI_Enable();

 /* Wait till HSI is ready */
 while (LL_RCC_HSI_IsReady() != 1);

 LL_RCC_HSI_SetCalibTrimming(64);
 LL_PWR_EnableBkUpAccess();
 while (LL_PWR_IsEnabledBkUpAccess () == 0U);

 LL_RCC_LSI_Enable();

 /* Wait till LSI is ready */
 while (LL_RCC_LSI_IsReady() != 1);

 LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);

 /* Wait till System clock is ready */
 while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI);

 LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
 LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
 LL_Init1msTick(16000000);
 LL_SetSystemCoreClock(16000000);

 LL_RCC_ConfigMCO(LL_RCC_MCO2SOURCE_SYSCLK, LL_RCC_MCO2_DIV_1);
 LL_RCC_LSCO_Enable();
 LL_RCC_LSCO_SetSource(LL_RCC_LSCO_CLKSOURCE_LSI);

 LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI); // Set RCC->CFGR.STOPWUCK

 // ************** LSI clock output to PA2
 LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
 GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
 GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
 LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 // ************** HSI clock output to PA10
 GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
 GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
 GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
 GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
 LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

when LSI is not stable, the problem could be slove by switch off power supply for few second to ensure the board is totally discharge. and power on, everything works perfect.

I'm not sure why this happed, and i can't keep this issue in final product.

Do i missed any configure or other? any suggestion to slove the problem?

    This topic has been closed for replies.