Click here to Skip to main content
16,022,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C
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

What I have tried:

To debug and found that the cpu is stuck
Posted
Updated 17-Sep-24 6:31am
v2

I would suspect the problems lie in the parts of the code that have not been shown.

1. The initialization of the RTC in the STM32 could be incomplete or incorrect. The following steps should likely be checked:
- Activate power and backup domain
- Configure the LSE
- Set the RTC clock source
- Enable RTC clock
- Initialize the RTC (if necessary reconfigure after a reset)

2. Hardware could be incomplete or incorrectly connected. The backup power supply for the RTC might be faulty, too low, or missing. Without a proper voltage for backup, the RTC will not continue running in low-power modes or after a restart.

3. An error in the sleep time calculation or incorrect wake-up timer settings could cause the condition to be unmet.
 
Share this answer
 
I'd start with ST themselves: STM32 32-bit Arm Cortex MCUs
[^] - they have both a Developer Zone and a Support link.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900