My STM32L0 RTC stops in standby mode
Hi, I have a small custom board using an STM32L0xxx.
The RTC is running as expected in run mode.
When I enter Standby mode the RTC appears to stop.
The MCU is in standby most of the time, it wakes up for about 2 to 4 ms, checks some digital and analogs and goes back to standby for about 600ms.
What I am seeing is the RTC time freeze during standby, the RTC is working in run and the MCU wakes up OK.
Currently I am using the LSI oscillator for the RTC.
Im not sure whether I have an issue with the RTC or with the Standyby config??
Here is my code entering Standby:
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
HAL_RTCEx_DeactivateWakeUpTimer(&__g_rtc);
HAL_RTCEx_SetWakeUpTimer_IT(&__g_rtc, sleepTime, RTC_WAKEUPCLOCK_RTCCLK_DIV16); //0x0610 /* Clear all related wakeup flags */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); HAL_PWR_EnterSTANDBYMode();Here is the clock Init: sorry its a bit ugle looking, all of this is called with each wake up.
void sys_clock_init(int funct) // funct 0 = full init, 1 = ??
{ RCC_ClkInitTypeDef clk; RCC_OscInitTypeDef osc; __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);// Enable HSI Oscillator and activate PLL with HSI as source.
osc.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI; osc.HSEState = RCC_HSE_OFF; osc.HSIState = RCC_HSI_ON; osc.LSIState = RCC_LSI_ON; osc.PLL.PLLState = RCC_PLL_ON; osc.PLL.PLLSource = RCC_PLLSOURCE_HSI; osc.PLL.PLLMUL = RCC_PLLMUL_4; osc.PLL.PLLDIV = RCC_PLLDIV_2; osc.HSICalibrationValue = 0x10;if (HAL_RCC_OscConfig(&osc) != HAL_OK) {
sys_error(); }// Select PLL as system clock source and configure dividers.
clk.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; clk.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; clk.AHBCLKDivider = RCC_SYSCLK_DIV1; clk.APB1CLKDivider = RCC_HCLK_DIV1; clk.APB2CLKDivider = RCC_HCLK_DIV1;if (HAL_RCC_ClockConfig(&clk, FLASH_LATENCY_1) != HAL_OK) {
sys_error(); }// Required for HAL_Delay to work correctly
__HAL_RCC_TIM2_CLK_ENABLE(); __TIM2_CLK_ENABLE();// move stuff here that is not required in init after sleep
if (funct == 0) {}
}
// Initialize low power management.void sys_lp_init(void){}// Initialize the LSE clock which is used by LPUART.
void sys_clock_lse_init(void){ RCC_OscInitTypeDef osc;osc.OscillatorType = RCC_OSCILLATORTYPE_LSE;
osc.PLL.PLLState = RCC_PLL_NONE; osc.LSEState = RCC_LSE_ON;if (HAL_RCC_OscConfig(&osc) != HAL_OK) {
sys_error(); }}// Initialize the LSI clock which is used by LPTIM and RTC.
void sys_clock_lsi_init(void){ RCC_OscInitTypeDef osc;osc.OscillatorType = RCC_OSCILLATORTYPE_LSI;
osc.PLL.PLLState = RCC_PLL_NONE; osc.LSIState = RCC_LSI_ON; osc.LSEState = RCC_LSI_OFF;if (HAL_RCC_OscConfig(&osc) != HAL_OK) {
sys_error(); }}// Initializes the RTC based on the LSI.
// Notes: The LSI **must** be initialized prior to this.void sys_rtc_init(void){ // Configure LSI as RTC clock source RCC_PeriphCLKInitTypeDef pclk;pclk.PeriphClockSelection = RCC_PERIPHCLK_RTC;
pclk.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;if (HAL_RCCEx_PeriphCLKConfig(&pclk) != HAL_OK) {
sys_error(); }// Enable the RTC clock
__HAL_RCC_RTC_ENABLE();// Enable NVIC for RTC alarm
HAL_NVIC_SetPriority(RTC_IRQn, 0x0, 0); HAL_NVIC_EnableIRQ(RTC_IRQn);}If any one can help that would be great.
Thanks
Kevin
