Stm32F103 standby problems

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

Moderator: RoccoMarco

Post Reply
Flautz
Posts: 8
Joined: Sun Jun 02, 2013 9:32 pm
Been thanked: 1 time

Stm32F103 standby problems

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Stm32F103 standby problems

Post 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
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Stm32F103 standby problems

Post 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?
Flautz
Posts: 8
Joined: Sun Jun 02, 2013 9:32 pm
Been thanked: 1 time

Re: Stm32F103 standby problems

Post 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
Flautz
Posts: 8
Joined: Sun Jun 02, 2013 9:32 pm
Been thanked: 1 time

Re: Stm32F103 standby problems

Post by Flautz »

PS: WakeupPin rising edge doesn't work either.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Stm32F103 standby problems

Post by barthess »

Your MCU wakes up correctly, but you can not catch this moment because program returns from main() immediately after wake up.
Flautz
Posts: 8
Joined: Sun Jun 02, 2013 9:32 pm
Been thanked: 1 time

Re: Stm32F103 standby problems

Post 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();
...
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Stm32F103 standby problems

Post by Giovanni »

It could be matter of adding a small delay, try halPolledDelay().

Giovanni
Post Reply