Page 1 of 1

Standby and wakeup by RTC

Posted: Sat Apr 27, 2013 2:49 pm
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.

Re: Standby and wakeup by RTC

Posted: Sat Apr 27, 2013 6:28 pm
by Giovanni
Hi,

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

Giovanni

Re: Standby and wakeup by RTC

Posted: Sat Apr 27, 2013 6:46 pm
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.

Re: Standby and wakeup by RTC

Posted: Tue Apr 30, 2013 11:47 am
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.