最近在做一个项目需要用到低功耗,项目中选择进入STOP2模式。程序设计在RTC中断中,满足某一条件进入STOP2模式,等待下一个RTC中断唤醒,但是进入SOP2模式后,MCU就一直在低功耗状态,RTC没有唤醒,程序一直在:SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP); 位置,还有一个比较奇怪的是,明明设置的是中断模式,但是程序会跑到 __SEV();__WFE();__WFE(); 程序位置,这个是等待事件唤醒。程序的整体架构是,封装一个函数处理数据报文,当满足一些条件后执行进入低功耗,这个封装的函数在RTC中断中运行,或者在while循环中运行,但是结果都是一样的,请各位大佬,麻烦给点意见。
void PWR_EnterSTOP2Mode(uint8_t PWR_STOPEntry,uint32_t RetentionMode)
{
uint32_t tmpreg = 0;
/* Check the parameters */
assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
/* Wait MR Voltage Adjust Complete */
while((PWR->STS2 &0X2) != 2);
tmpreg = PWR->CTRL3;
/* Clear SRAMRET bits */
tmpreg &= (~PWR_CTRL3_RAMRETMASK);
/* Set SRAM1/2 select */
tmpreg |= RetentionMode;
PWR->CTRL3 = tmpreg;
/* Select the regulator state in STOP2 mode ---------------------------------*/
tmpreg = PWR->CTRL1;
/* Clear LPMS bits */
tmpreg &= (~PWR_CTRL1_LPMSELMASK);
/* Set stop2 mode select */
tmpreg |= PWR_CTRL1_STOP2;
/* Store the new value */
PWR->CTRL1 = tmpreg;
/* Set SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR |= SCB_SCR_SLEEPDEEP;
/* Select STOP mode entry --------------------------------------------------*/
if(PWR_STOPEntry == PWR_STOPENTRY_WFI)
{
/* Request Wait For Interrupt */
__WFI();
}
else
{
/* Request Wait For Event */
__SEV();
__WFE();
__WFE();
}
/* Reset SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
}
|