2024-09-17
07:18 AM
- last edited on
2024-09-17
07:28 AM
by
Lina_DABASINSKA
Hi,
I work with STM32F412ZG processor. I have also external LSE.
I have the next problem related to STOP mode.
There are some scenarios we want the processor to go to sleep for x hours.
The processor goes to sleep for 5 seconds, doing some job and return to sleep for 5 seconds and so on in infinite loop till it is broke by interrupt or if time elapsed( the x hours ).
The problem: from time to time the CPU is stuck at STOP MODE!!!
The next is a sample of the relevant code:
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) ;
RTC_TimeTypeDef sTimeBefore, sTimeAfter ;
RTC_DateTypeDef sDateBefore, sDateAfter ;
int sleepTime = 0 ;
int totalSleepTime = 0 ;
while(sleep) {
ReadRTC(&sTimeBefore, &sDateBefore);// This function calls the HAL_RTC_GetTime function and after that
the HAL_RTC_GetDate function
HAL_PWR_EnterSTOPMode( PWR_LOWPOWERREGULATOR_ON , PWR_STOPENTRY_WFE ) ;
ReadRTC(&sTimeAfter, &sDateAfter);
sleepTime = CalculateSleepTime(sTimeBefore, sDateBefore, sTimeAfter, sDateAfter);
totalSleepTime += sleepTime;
if (totalSleepTime > x)
sleep = 0 ;
}
Please any assistance.
Shai
2024-09-20 07:10 AM
Hello @Shush1908 ,
Try to disable the Systick interrupt.
You can refer to the PWR_STOP example within STM32CubeF4:
2024-09-25 01:35 AM
Hi,
Thanks for your reply.
I got hard fault from time to time ( it seems that we stuck in the STOP MODE) and also the sleep time calculation is not good(from time to time).
Shai
2024-09-25 01:36 AM
Of course after I add what you wrote: HAL_SuspendTick() and HAL_ResumeTick()