cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 . Sleep and STOP mode: Can they co-exist?

narayan
Associate II
Posted on March 16, 2011 at 23:17

STM32 . Sleep and STOP mode: Can they co-exist?

5 REPLIES 5
narayan
Associate II
Posted on May 17, 2011 at 14:28

Clive1,

Thanks for the response. I am using an External Interrupt to try and wake from the ''stop''. Do you think calling ''WFI()''

 to sleep causes the external interrupt bit to be cleared?

-AKN

Posted on May 17, 2011 at 14:28

Seems to work fine for me. I'm not using the same OS as you, but I do have an idle _WFI loop and go into a ~1mA PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); stop mode.

I guess, if I were you, I'd look at your external interrupt/RTC wakeup code, and make sure I didn't having any fighting inputs (wired-or kind of conditions) that would prevent the clear observation of the interrupt.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 14:28

Well first, I haven't seen your code so I don't know exactly what you're doing or how the RTOS is interacting with that, or how your hardware is designed.

The WFI is like the classic ''HALT'' function. It does not eat interrupts, it blocks execution until an interrupt occurs. One potential pitfall I can see though is a race condition, if your interrupt can occur before the processor executes the WFI, it will be serviced and then your main line code will hit the WFI. Absent another interrupt to break the WFI condition it will stay their indefinitely.

You need to make sure things like the RTC alarm is cleared, and I would suggest using the RTC alarm as a secondary method of recovering the system.

PWR_EnterSTOPMode() returns once it exits stop.

Are you using PWR_EnterSTOPMode() from a foreground task (ie not under interrupt)?

Are you using WFI in some background task (ie interrupt context).

Have you tried the STM32F10xFWLib\Examples\PWR\Stop example, does it work for you?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
narayan
Associate II
Posted on May 17, 2011 at 14:28

Thanks for your continued interest.  My sleep code is basically in the idle task. The Idle task is at the lowest priority and so will only run when nothing is running.

Idle_task()

{

      if(some timeout expired)

      {

            //Stop the OS scheduler

            ................

            // Turn off clock to different peripherals

                    

                PWR_EnterSTOPMode(PWR_Regulator_LowPower,

                                                              PWR_STOPEntry_WFI);

                 //Wakes up when an external int is generated

                 SYSCLKConfig_STOP();

                 //Enable clocks

                 .........................

                 //Resume the OS scheduler

        

       }

      else

      {

           __WFI();

       }

}

One thing I found is that when the processor wakes up from the ''STOP'' mode in response to my external interrupt, I see that the ''DEEPSLEEP'' bit is still set in the ''SCB_SYSCTRL'' register. Now when the __WFI is called in the normal course of the idle_task() operation, the system goes to deep sleep and does not wakeup at all. THis was probably what I my issue was. I tried fixing this temporarily by clearing the  ''SLEEPEP'' bit in the ''SCB_SYSCTRL'' register and it now seems to work. But I am not sure whether this is a proper approach. Now where is the ST's example code do they purposefully clear this register. For that matter I could not find any example code where both of them are used together.

-AKN

narayan
Associate II
Posted on May 17, 2011 at 14:28

Sorry for the typo

>>''SLEEPEP'' bit in the ''SCB_SYSCTRL'' register

should read as ''DEEPSLEEP'' bit in the ''SCB_SYSCTRL'' register