Page 1 of 3

Sleeping for a longer period of time

Posted: Tue Jan 31, 2012 7:09 pm
by kulve
Hi

I would like to implement a logger application. It takes a measurement (e.g. temperature), sends it over an xBee and then sleeps e.g. a minute. Idea is to save power by being in as deep power saving mode as possible for most of the time.

Is this possible with ChibiOS? Or does it wake up for every tick even though all the threads (probably just one) would be sleeping?

Thanks.

Re: Sleeping for a longer period of time

Posted: Tue Jan 31, 2012 7:33 pm
by Giovanni
Hi,

It is possible using the RTC driver on the STM32F1xx platform, it will be extended to L1, F2 and F4 too (soon). There is a topic regarding the RTC driver in the development forum and a test application in the latest unstable release.

Giovanni

Re: Sleeping for a longer period of time

Posted: Tue Jan 31, 2012 7:53 pm
by kulve
Ijust started to read the thread from the start, but so far so good.

Thanks.

Re: Sleeping for a longer period of time

Posted: Thu Mar 08, 2012 9:15 pm
by kulve
I finally got around to check this a bit further.

Looks like the idle thread in ChibiOS is an empty busy-loop. I tried setting the CORTEX_ENABLE_WFI_IDLE to true but I didn't see any effect in the power consumption.

But I guess in my use cases it's enough to explicitly enter to sleep mode when needed. The testhal's RTC example for F4 looked like a nice starting point. I had to cut'n'paste some RTC related register names from F4's RTC_TypeDef to F2 to get it compiled (I assume the F2 and F4 are equal related to that as well) but it looked like it just resetted instead of sleeping the mentioned 10 secs.

Should the same code work for F2 as well?

Thanks.

Re: Sleeping for a longer period of time

Posted: Thu Mar 08, 2012 9:21 pm
by Giovanni
The RTC is one of the few things that are different between F2 and F4. Our plan is to have a single driver for L1, F2 and F4 but apparently this will be more problematic than expected.

barthess?

Giovanni

Re: Sleeping for a longer period of time

Posted: Thu Mar 08, 2012 10:46 pm
by barthess
kulve wrote:Should the same code work for F2 as well?

Current implementation from trunk designed to be compatible between F2 and F4. As result of compatibility the lots of tasty F4 features not used.
kulve wrote:but it looked like it just resetted instead of sleeping the mentioned 10 secs.

Note that deep sleep mode is very close to total powering off. After waking up MCU performs startup just like after reset. In your case probably some forgotten interrupt flag wakes MCU up just after going sleep. It looks like immediate reset.

Re: Sleeping for a longer period of time

Posted: Fri Mar 09, 2012 12:58 am
by colin
barthess wrote:
kulve wrote:Should the same code work for F2 as well?

Current implementation from trunk designed to be compatible between F2 and F4. As result of compatibility the lots of tasty F4 features not used.
kulve wrote:but it looked like it just resetted instead of sleeping the mentioned 10 secs.

Note that deep sleep mode is very close to total powering off. After waking up MCU performs startup just like after reset. In your case probably some forgotten interrupt flag wakes MCU up just after going sleep. It looks like immediate reset.


@barthess
We should be clear about which specific STM32 sleep mode you are speaking. The Cortex-M3 “deep sleep” function (WFI/WFE instruction with SLEEPDEEP bit set) is used to enter either “Stop” or “Standby” mode of the STM32.

The STM32 power modes are RUN, SLEEP, STOP, and STANDBY. Only STANDBY performs a reset when it is exited. See ST AN2629 STM32F101xx, STM32F102xx and STM32F103xx low-power modes.

If I am mistaken, please correct me.

Re: Sleeping for a longer period of time

Posted: Fri Mar 09, 2012 1:17 am
by barthess
colin
Yes, you correct. But kulve says that he copypasted code from F4 test application. That application uses STANDBY mode.

Re: Sleeping for a longer period of time

Posted: Fri Mar 09, 2012 6:05 am
by kulve
This is what I copied:

Code: Select all

static void func_sleep(void){
  chSysLock();
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  PWR->CR |= (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
  RTC->ISR &= ~(RTC_ISR_ALRBF | RTC_ISR_ALRAF | RTC_ISR_WUTF | RTC_ISR_TAMP1F |
                RTC_ISR_TSOVF | RTC_ISR_TSF);
  __WFI();
}


Hmm.. Is there a way check if there's a forgotten interrupt flag? My main.c is pretty much copied from the RTC example and does nothing but blinks a led and sleeps. I don't have any external pins connected that I could think that could cause external interrupts. My halconfig.h do enable several subsystems though (UART, PWM, ICU, ADC) but they are not enabled in the code (except what halInit() does).

Thanks.

Re: Sleeping for a longer period of time

Posted: Fri Mar 09, 2012 12:32 pm
by barthess
It is hard to determine real reason of such behavior. Probably in EXTI cell. Try to look with memory browser what's exactly written to RTC registers. Are alarms and wakeups written in RTC correctly?