Standby and wakeup by RTC

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

Standby and wakeup by RTC

Post by kreyl »

stm32f205ve, chibios v2.5.1
Task is to enter Standby mode and wakeup once a second or so.
I used RTC wakeup example from testhal\STM32F4xx\RTC, namely RTC wakeup setup and func_sleep():

Code: Select all

  /* set wakeup */
  wakeupspec.wakeup = ((uint32_t)4) << 16; /* select 1 Hz clock source */
  wakeupspec.wakeup |= 9; /* set counter value to 9. Period will be 9+1 seconds. */
  rtcSetPeriodicWakeup_v2(&RTCD1, &wakeupspec);

  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();

It works for first time only. I.e. after power up, CPU enters Standby, stays there 10 seconds, wakes, (does something), enters Standby - and does not wake up.
Power switch leads to repeat of the scenario.
I outputted RTC registers values, namely ISR:
    After PowerOn: 000027
    After RtcInit(): 000007
    After Wakeup setup: 000027
    After Standby-and-wakeup: 000423
    After RtcInit(): 000403
    After Wakeup setup: 000427
Obviously, WUTF flag remains set during Wakeup setup.
When I put string

Code: Select all

  RTC->ISR &= ~(RTC_ISR_ALRBF | RTC_ISR_ALRAF | RTC_ISR_WUTF | RTC_ISR_TAMP1F |
                RTC_ISR_TSOVF | RTC_ISR_TSF);

before

Code: Select all

rtcSetPeriodicWakeup_v2(&RTCD1, &wakeupspec);

it started to work of properly. Namely, CPU wakes every time when expected.
It seems that WUTF should be cleared before setting up wakeup, it is insufficient to clear WUTWF only.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Standby and wakeup by RTC

Post by Giovanni »

Hi,

I never played with the wakeup modes, barthess could probably help you there. I know he was using that.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Standby and wakeup by RTC

Post by barthess »

I will check it. Wakeups was checked by me only on STM32F1xx. Looks like I need to check it deeper on STM32F4xx too.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Standby and wakeup by RTC

Post by barthess »

Probably there is some differences between STM32F4x and STM32F2x in RTC cell. On my F4x it works fine without clearing of WUTF before rtcSetPeriodicWakeup_v2(). I can not test it on F2x because have no one board with it.
Post Reply