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
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.