2018-07-27 08:13 AM
Hallo all
I have troubles using sleep mode with this MCU.
In our application there is a hardware watchdog (STM6822), which should be restarted every 1 second.
I use RTC alarm feature for periodic wake-up.
The problem is that the MCU sometimes freezes and the watchdog resets the MCU.
I have tried many variants (inlined SCU_EnterSleepMode, more nops), but nothing helped reliably.
Each unit behaves differently - one change helped with one device, but worsened that in other device.
Is there something I am missing to correctly put MCU into sleep mode and reliably wake-up?
Tomas
(shortened code follows)
void __attribute__ ((section (".fast"))) sleep_mode(void) {
(void)SCU_MCLKSourceConfig(SCU_MCLK_RTC);
bool should_sleep = true;
while (should_sleep) {
watchdog_reset();
while (rtc_hw_get_ms() > 950) {;} // to be sure the alarm will not be missed
rtc_set_alarm_after(WAKEUP_PERIOD); // set alarm to nearest second
RTC_ITConfig(RTC_IT_Alarm, ENABLE);
WIU_ClearITPendingBit(0xFFFFFFFF);
WIU_Cmd(ENABLE);
SCU_EnterSleepMode();
__asm__ volatile ("nop\r\n nop\r\n nop"); // see Errata 2.10.1
// here the MCU sleeps
WIU_Cmd(DISABLE);
rtc_clearAlarm();
watchdog_reset();
should_sleep = function_to_get_reason_for_wake_up();
}
}