cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401 RTC ALARMA wake up CPU from StandBy with 16 seconds error. Why?

Spider
Associate II

I'm configuring RTC AlarmA to wake up CPU from StandBy. I'am expecting to CPU became back at specified time, but it event occurs up to 16 seconds later.

uint32_t time;
uint32_t date;
uint32_t subsec;
 
do {		
	time = LL_RTC_TIME_Get(RTC);
	date = LL_RTC_DATE_Get(RTC);
	subsec = LL_RTC_TIME_GetSubSecond(RTC);
} while (subsec != LL_RTC_TIME_GetSubSecond(RTC));
 
sec = __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_SECOND(time));
min = __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_MINUTE(time));
hour= __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_HOUR(time));
 
sec+=10; //
 
LL_RTC_DisableWriteProtection(RTC);
CLEAR_BIT(PWR->CSR, PWR_CSR_EWUP);
LL_RTC_ALMA_Disable(RTC);
do {} while (!LL_RTC_IsActiveFlag_ALRAW(RTC));
 
LL_RTC_ClearFlag_ALRA(RTC);
 
LL_RTC_ALMA_ConfigTime(RTC, LL_RTC_ALMA_TIME_FORMAT_AM, __LL_RTC_CONVERT_BIN2BCD(hour), __LL_RTC_CONVERT_BIN2BCD(min), __LL_RTC_CONVERT_BIN2BCD(sec));
  LL_RTC_ALMA_SetMask(RTC, LL_RTC_ALMA_MASK_DATEWEEKDAY | LL_RTC_ALMA_MASK_HOURS | LL_RTC_ALMA_MASK_MINUTES);
LL_RTC_ALMA_SetSubSecondMask(RTC, 0);
LL_RTC_ALMA_Enable(RTC);
 
LL_RTC_EnableWriteProtection(RTC);
 
TRACE_INFO("RTC->ALRMAR: 0x%08X\r\n",RTC->ALRMAR);
 
/* Enable the wake up pin */
SET_BIT(PWR->CSR, PWR_CSR_EWUP);
 
SET_BIT(PWR->CR, PWR_CR_PDDS | PWR_CR_CWUF | PWR_CR_CSBF);
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
__WFI();

If set time to WakeUp for example 00:00:10 -> CPU will WakeUp at 00:00:26 and so on. Always up to 16 seconds later.

What I do wrong?

1 REPLY 1
Mohamed Aymen HZAMI
ST Employee

Hello,

How you configure the RTC alarm ?

Try to use HAL library function.

Best Regards,

Mohamed Aymen.