Sleeping for a longer period of time

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Sleeping for a longer period of time

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Sleeping for a longer period of time

Post 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
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Sleeping for a longer period of time

Post by kulve »

Ijust started to read the thread from the start, but so far so good.

Thanks.
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Sleeping for a longer period of time

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Sleeping for a longer period of time

Post 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
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Sleeping for a longer period of time

Post 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.
colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Re: Sleeping for a longer period of time

Post 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.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Sleeping for a longer period of time

Post by barthess »

colin
Yes, you correct. But kulve says that he copypasted code from F4 test application. That application uses STANDBY mode.
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: Sleeping for a longer period of time

Post 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.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Sleeping for a longer period of time

Post 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?
Post Reply