cancel
Showing results for 
Search instead for 
Did you mean: 

Waking up from RTC on a STM32G030

WSpar.1
Associate III

Hi all,

I'm struggling for days why my RTC wakeup doesn't work.
The program is running FreeRTOS, but I want the uC in Lowpower Sleep for 3 minutes.

So I set RTC on 1Hz, counter 180 and internal wakeup.
Activated the EXTI RTC interrupt.

But it immediately exit SLEEP after 1 sec or so.

I found this topic, but haven't luck so far:
https://community.st.com/t5/stm32-mcus-embedded-software/clearing-the-rtc-wutf-saving-your-sanity-by-sharing-my-hard/m-p/200677

 

void goToSleep(void)

{

__disable_irq();

__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);

 

vTaskDelay(pdMS_TO_TICKS(1000));

 

HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

HAL_SuspendTick();

HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x500B, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

 

//__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

 

//__enable_irq();

HAL_NVIC_ClearPendingIRQ(TIM1_BRK_UP_TRG_COM_IRQn);

HAL_NVIC_ClearPendingIRQ(RCC_IRQn);

HAL_NVIC_ClearPendingIRQ(PIR_EXTI_IRQn);

HAL_NVIC_ClearPendingIRQ(ROTARY1_EXTI_IRQn);

HAL_NVIC_ClearPendingIRQ(ROTARY2_EXTI_IRQn);

HAL_NVIC_ClearPendingIRQ(EXTI4_15_IRQn);

 

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFI);

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);

 

 

/* Enter sleep mode */

HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFI);

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);

 

__disable_irq();

 

HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

SystemClock_Config();

__enable_irq();

HAL_ResumeTick();

 

 

 

}

 

I'm really out of options atm.
Timer in code above was sit on 10s for testing purpose

UPDATE:

With STOP mode I got the behavior I wanted, but that is too much current.
Sleep modes basically behave like one __NOP()

 

HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI); //skips sleep

//HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); //skips sleep

//HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); //291uA

//HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); //362uA

 

 

 

3 REPLIES 3
GET
ST Employee

Hello @WSpar.1 ,

 

Not sure it would answer directly to your problem, but please note also there is an Application Note dedicated to RTC and tamper management: Using the hardware real-time clock (RTC) and the tamper management unit (TAMP) with STM32 microcontrollers - Application note  , if it can help.

Also, would there be another interrupt source in your application that could activate and bring the STM32G0 out of sleep ?

Best Regards,

WSpar.1
Associate III

Maybe FreeRTOS SysTick is still running although I've selected TIM1 as SYS Timebase?

Hi @WSpar.1 ,

 

Sorry, your question is too deep technical knowledge for me, and I cannot answer by myself.

I hope you found any clue/solution since you posted this topic ?

If not the case, I hope someoneelse could help you on this subject.

 

Best Regards,