Issue coming out of standby mode using RTC
Hi
I am having issues coming out of standby mode using RTC timers. I am using both timers and the periodic counter, all at different times. If I dont go into stanby mode all works as expected, and the interrupts are generated for each clock and timer. If I go into standby , then one interrupt wakes the processor, but the other interrupts dont wake the processor. I am using the stm32L433 processor.
I setup the RTC clocks :
void RTC_Set_Periodic(void)
{
RTC->ISR |= RTC_ISR_INIT;
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
RTC->CR &= ~RTC_CR_WUTE; //clear wakup timer
while ((RTC->ISR & RTC_ISR_WUTWF) != RTC_ISR_WUTWF)
RTC->CR &= ~RTC_CR_WUCKSEL;
RTC->CR |= RTC_CR_WUCKSEL_2;
RTC->WUTR=9; //wakeup every 10 seconds
EXTI->RTSR1 |= EXTI_RTSR1_RT20;
EXTI->IMR1 |= EXTI_IMR1_IM20;
EXTI->EMR1 |= EXTI_EMR1_EM20;
EXTI->PR1 |= EXTI_PR1_PIF20;
RTC->CR |= RTC_CR_WUTIE;
RTC->CR |= RTC_CR_WUTE;
RTC->ISR &= ~(RTC_ISR_WUTF);
NVIC_EnableIRQ(RTC_WKUP_IRQn);
NVIC_SetPriority(RTC_WKUP_IRQn,3);
RTC->ISR &=~ RTC_ISR_INIT;
RTC->WPR = 0xff;
}
void RTC_WKUP_IRQHandler(void)
{
if(RTC->ISR & RTC_ISR_WUTF)
{
while(!(RTC->ISR & RTC_ISR_RSF))
;
}
EXTI->PR1 |= EXTI_PR1_PIF20;
}
////////////////////////////////////////
void RTC_Set_ClockA()
{
unsigned long Alarm=CalcNextAlarm(ClockAPeriod); //calculate next time
RTC->ISR |= RTC_ISR_INIT;
RTC->CR &=~RTC_CR_ALRAE;
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
RTC->CR &= ~RTC_CR_ALRAE;
RTC->CR &= ~RTC_CR_ALRAIE;
RTC->ISR &= ~(RTC_ISR_ALRAWF); //clear any pending Interupts
while((RTC->ISR & RTC_ISR_ALRAWF)==0);
RTC->ALRMAR =Alarm;
RTC->CR |= RTC_CR_ALRAE;
RTC->CR |= RTC_CR_ALRAIE;
EnableRTCStoreAndSendTimer();
RTC->WPR = 0xff;
RTC->ISR &=~ RTC_ISR_INIT;
}
void RTC_Set_ClockB()
{
unsigned long Alarm=CalcNextAlarm(NodeTimesAlarmsStruct.SampleRate); //simply get next alarm...RTC->ISR |= RTC_ISR_INIT;
RTC->CR &=~RTC_CR_ALRBE;
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
RTC->CR &= ~RTC_CR_ALRBE;
RTC->CR &= ~RTC_CR_ALRBIE;
RTC->ISR &= ~(RTC_ISR_ALRBWF); //clear any pending Interupts
while((RTC->ISR & RTC_ISR_ALRBWF)==0);
RTC->ALRMBR =Alarm;
RTC->CR |= RTC_CR_ALRBE;
RTC->CR |= RTC_CR_ALRBIE;
EnableIRQs();
RTC->WPR = 0xff;
RTC->ISR &=~ RTC_ISR_INIT;
}
//Enable Interupts
void EnableIRQs()
{
EXTI->RTSR1 |= EXTI_RTSR1_RT18;
EXTI->IMR1 |= EXTI_IMR1_IM18;
EXTI->EMR1 |= EXTI_EMR1_EM18;
EXTI->PR1 |= EXTI_PR1_PIF18;
NVIC_SetPriority(RTC_Alarm_IRQn,0);
NVIC_EnableIRQ(RTC_Alarm_IRQn);
}
//interupt routines
void RTC_Alarm_IRQHandler(void)
{
//check for AlarmA,
if(RTC->ISR & RTC_ISR_ALRAF)
{
RTC->ISR &= ~(RTC_ISR_ALRAF);
}
//check for AlarmB
if(RTC->ISR & RTC_ISR_ALRBF)
{
RTC->ISR &= ~(RTC_ISR_ALRBF);
}
EXTI->PR1 |= EXTI_PR1_PIF18;
}
All the above works as expected in normal mode, but when I put in the lines
HAL_PWREx_EnableSRAM2ContentRetention()
HAL_PWR_EnterSTANDBYMode();
The processor goes into standby mode and gets woken only by one interupt.
In Main I have:
if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB)!=RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
if(RTC->ISR & RTC_ISR_WUTF) //check for periodic timer
{
PeriodicSet=1;
RTC->ISR &= ~(RTC_ISR_WUTF);
}
if(RTC->ISR & RTC_ISR_ALRAF)//check for clock A
{
ClockASet=1;
RTC->ISR &= ~(RTC_ISR_ALRAF);
}
//check for AlarmB, sample results
if(RTC->ISR & RTC_ISR_ALRBF)
{
ClockBSet=1;
RTC->ISR &= ~(RTC_ISR_ALRBF);
}
}
If any of the above is set (clockBSet etc), I go into standby mode again. But only ever 1 wakens up the processor. I assume all timers can wakeup the processor as above?
Best Regards
Scott