Page 1 of 1

Stm32F103 standby problems

Posted: Sun Nov 03, 2013 7:00 pm
by Flautz
Hey guys,

I experience problems when trying to enter the standby mode and waking up after a few seconds again with a custom STM32F103C8 board.

I took the code from the testhal/RTC example and used it in a simple application:

Code: Select all

int main(void)
{
  halInit();
  chSysInit();
  palSetPadMode(PORT_DBG, PIN_DBG, PAL_MODE_OUTPUT_PUSHPULL); //DEBUG

  palSetPad(PORT_DBG, PIN_DBG);
  //wait some time
  chThdSleepMilliseconds(1000);
  palClearPad(PORT_DBG, PIN_DBG);

  //set RTC wakeup
  rtcGetTime(&RTCD1, &timespec);
  alarmspec.tv_sec = timespec.tv_sec + 5; //standby for 5 seconds
  rtcSetAlarm(&RTCD1, 0, &alarmspec);

  //enter standby mode
  chSysLock();
  PWR->CR |= (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  __WFI();

  return 0;
}


I would expect the debug pin to be periodically high for about one second and low for about 5 seconds.

What happens is that it is high for 1 second and then stays low. The chip seems to go asleep but never returns.

The RTC is clocked by LSI. Any ideas what is going wrong here?

Re: Stm32F103 standby problems

Posted: Sun Nov 03, 2013 8:57 pm
by Giovanni
Not sure, you may try to contact barthess, the person who wrote the example. He is often in the IRC channel or you may try forum messages.

Giovanni

Re: Stm32F103 standby problems

Posted: Sun Nov 03, 2013 9:05 pm
by barthess
Hi Flautz.
Are you absolutely sure your RTC runs? Does your board have battery? Does your MCU able to wake up using "Wakeup" pin?

Re: Stm32F103 standby problems

Posted: Sun Nov 03, 2013 9:13 pm
by Flautz
Hi Barthess,

thank you for the ideas.
The board does not have a battery, the vbat pin is connected to 3,3v.
As long as the program is running, the RTC works. The RTC alarm is working as long as I do not enter standby mode.
Do I have to reconfigure some registers to make sure that the RTC keeps running in standby mode?

Best,
Flautz

Re: Stm32F103 standby problems

Posted: Sun Nov 03, 2013 9:20 pm
by Flautz
PS: WakeupPin rising edge doesn't work either.

Re: Stm32F103 standby problems

Posted: Sun Nov 03, 2013 9:40 pm
by barthess
Your MCU wakes up correctly, but you can not catch this moment because program returns from main() immediately after wake up.

Re: Stm32F103 standby problems

Posted: Mon Nov 11, 2013 4:11 pm
by Flautz
When entering standby mode the program starts again from the beginning, so that's not the fault.

I found a solution now, it seems that the optimizations lead to problems. This solution works with -O0, but fails with -O2:

Code: Select all

...
    //enter standby mode
    chSysLock();
    PWR->CR |= PWR_CR_CWUF;
    PWR->CR |= PWR_CR_PDDS;
    SCB->SCR |= SCB_SCR_SLEEPDEEP;
    __WFI();
...

Re: Stm32F103 standby problems

Posted: Mon Nov 11, 2013 4:30 pm
by Giovanni
It could be matter of adding a small delay, try halPolledDelay().

Giovanni