cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Problems when waking up from StandBy mode

sergio23
Associate II
Posted on April 14, 2016 at 13:48

Hello,

I have noticed that when my system wake up from Standby mode seems to lose some time and RTC loses something like 2 ms for each second

Does anybody have anytime this kind of problem?

I have using an STM32L162.

Any idea will be welcomed

Best  regards

Carmen
17 REPLIES 17
Walid FTITI_O
Senior II
Posted on April 15, 2016 at 18:42

Hi RiseOfDeath,

I think your issue is coming from the fact that your code is confusing between the power-ON and the resuming from Standby mode.

So, you should proceed like the following:

/* Check and Clear the Wakeup flag if already set*/
if(__HAL_PWR_GET_FLAG(PWR_FLAG_WU) != RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
}
/* Check the status of standby flag SB*/
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET)
{
/* Power-ON routine */
- Clearing all flag
- RTC configuration
- Entering standby routine
}
else
{
/*Resuming from standby routine */
………..
}

You should also, make attention when you want to debug a low power mode, in this case you need to Enable the debug for that mode :

For standby mode debug:

/* Enable the Debug Module during STANDBY mode */

HAL_EnableDBGStandbyMode();

I recommend that you take a look to the application note AN4538 at this

http://www.st.com/web/en/resource/technical/document/application_note/DM001214pdf

: “Power consumption optimization with STM32F3xx microcontrollers “

Yo

u will be inspired from this AN where we have developed a use case similar to your application where all the power modes are used and it containes a (Power-On /standby resume) switching routine. You find the firmware at this

http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743/LN1734/PF257872

.

-Hannibal-

sergio23
Associate II
Posted on April 18, 2016 at 10:44

Hi Hannibal,

I have checked my code, comparing to AN4538, and they are equal.

There must be something I'm doing wrong, but I cannot find it.

Do you have any other suggestion?

Thanks for your answer

Carmen

Walid FTITI_O
Senior II
Posted on April 18, 2016 at 12:35

Hi Carmen, 

Would you share your code to check with you ?

Also, what is the hardware your are using and mention any connection are set-up .

-Hannibal-

sergio23
Associate II
Posted on April 18, 2016 at 15:53

Hi Hannibal,

First of all, thank you for your interest and help.

Attached is our code. We are using a STM32L162RDT6.

Best regards

Carmen

________________

Attachments :

main_-_copia.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtnY&d=%2Fa%2F0X0000000aX5%2F.zOC7hvs_VLfS67R46HBldg_prVpuMj_Mi27aUKDwpY&asPdf=false
Walid FTITI_O
Senior II
Posted on April 18, 2016 at 19:47

Hi Carmen,

I don’t think that you have implemented the same Power-on/resuming from standby conditionning as the AN example or as my recommendation. The hole project should be managed using the conditionning routine to handle only one time the RTC initialization and entering the standby mode at Power-on state (

PWR_FLAG_SB = 0)

. Otherwise the device always is resuming from standby (

PWR_FLAG_SB = 1

) and making the treatment you want.

if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET) 
{ 
/* Power-ON RESET*/ 
- RTC configuration 
- Entering standby routine 
} 
else 
{ 
/*Resuming from standby */ 
……….. 
}

-Hannibal-
sergio23
Associate II
Posted on April 19, 2016 at 08:55

Hi Hannibal,

Sorry, but I think, I have implemented the same powerOn /resuming from StandBy functions as AN example. I have configure RTC, just when (

PWR_FLAG_SB = 0),

in function MX_RTC_Init(). Other times, when system wakeUp from StandBy, RTC is not initialized.

I think this is not the real problem

Thank you very much

Carmen

Walid FTITI_O
Senior II
Posted on April 21, 2016 at 19:05

Hi fernandez.sergio,

Try to put the RTC instance initialization outside MX_RTC_Init() in the biginning of main() (before if condition) like this :

/* Initialize the RTC instance*/ 
RTCHandle.Instance = RTC; 
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET) 
{ 
/* Power-ON RESET*/ 
- Mx_RTC_init() 
- Enter standby mode 
} 
else 
{ 
/*Resuming from standby */ 
} 

Tell me if this reslove your problem. -Hannibal-
sergio23
Associate II
Posted on April 25, 2016 at 08:01

Hi Hannibal.

Thank you for your new suggestion. I have tried, and the result is exactly the same.

Best regards

Carmen

Walid FTITI_O
Senior II
Posted on April 25, 2016 at 15:46

Hi fernandez.sergio,

I recommend that you should create a simple/short project from your original one that duplicate the issue to investigate clearly the cause.

-Hannibal-