stm32在进入standby状态如何唤醒,求个简单参考代码

2025-06-26 06:38:37
推荐回答(1个)
回答1:

STM32
的低功耗模式有
3种:

1)睡眠模式(CM3内核停止,外设仍然运行)

2)停止模式(所有时钟都停止)

3)待机(standby)模式(1.8V内核电源关闭)
从待机模式唤醒后的代码执行等同于复位后的执行
进入Standby模式后,只能有Wake-up脚和RTC唤醒,特别是唤醒后,程序将从最开始运行,也就是相当于软件复位。

我这里有一个我以前写的参考代码

void PWR_EnterSTANDBYMode(void)
{
/* Clear Wake-up flag */
PWR->CR |= CR_CWUF_Set;

/* Select STANDBY mode */
PWR->CR |= CR_PDDS_Set;

/* Set SLEEPDEEP bit of Cortex System Control Register */
*(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;

/* Request Wait For Interrupt */
__WFI();
}
/*******************************************************************************
* Function Name : PWR_WakeUpPinCmd
* Description : Enables or disables the WakeUp Pin functionality.
* Input : - NewState: new state of the WakeUp Pin functionality.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void PWR_WakeUpPinCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));

*(vu32 *) CSR_EWUP_BB = (u32)NewState;
}
/*******************************************************************************
* Function Name : LowPower_Init
* Description : Initializes Low Power application.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LowPower_Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

/* Enable WakeUp pin */
PWR_WakeUpPinCmd(ENABLE);

/* Enable Clock Security System(CSS) */
RCC_ClockSecuritySystemCmd(ENABLE);
}

PS,进入satandby之前要关闭看门狗,否则看门狗的复位,会导致MCU提前醒来