文章目录
STM32 低功耗模式
系统或电源复位后,微控制器处于运行状态之下,HCLK为CPU提供时钟,内核执行代码。
CPU不需要运行时,可用低功耗模式节省功耗
运行模式下,可降低系统时钟,关闭APB和AHB总线上未被使用的外设时钟来降低功耗。
3种低功耗模式
睡眠模式
内核停止,外设运行
停止模式(典型的电流为350uA)
时钟停止,1.8V内核电源工作
PLL,HIS,HSE RC振荡器功能禁止
寄存器和SARM内容保留
待机模式-(最低功耗2.2uA电流)
1.8V 内核电源关闭
只有备份寄存器和待机电路维持供电
寄存器和SRAM内容全部丢失
大部分的I/O引脚都处于高阻态,除复位引脚、RTC_AF1引脚、使能的WKUP引脚
对于使能了RTC中断后的待机模式
操作步骤:
1、禁止RTC中断
2、清零对应中断标志位
3、清除PWR唤醒标志
4、重新使能RTC对应中断
5、进入低功耗模式
相关寄存器和库函数
void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
{
uint32_t tmpreg = 0;
/* Check the parameters */
assert_param(IS_PWR_REGULATOR(PWR_Regulator));
assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
/* Select the regulator state in STOP mode ---------------------------------*/
tmpreg = PWR->CR;
/* Clear PDDS and LPDS bits */
tmpreg &= CR_DS_MASK;
/* Set LPDS, MRLVDS and LPLVDS bits according to PWR_Regulator value */
tmpreg |= PWR_Regulator;
/* Store the new value */
PWR->CR = tmpreg;
/* Set SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* Select STOP mode entry --------------------------------------------------*/
if(PWR_STOPEntry == PWR_STOPEntry_WFI)
{
/* Request Wait For Interrupt */
__WFI();
}
else
{
/* Request Wait For Event */
__WFE();
}
/* Reset SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
}
void PWR_EnterSTANDBYMode(void)
{
/* Select STANDBY mode */
PWR->CR |= PWR_CR_PDDS;
/* Set SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* This option is used to ensure that store operations are completed */
#if defined ( __CC_ARM )
__force_stores();
#endif
/* Request Wait For Interrupt */
__WFI();
}
实验程序
待机唤醒配置步骤
需要配置电源控制寄存器
使能电源时钟
RCC_APB!PeriphClockCmd(RCC_APB!Periph_PWR,ENABLE);
RTC相关处理:关闭RTC相关中断
设置WK_UP引脚作为唤醒源。
PWR_WakeUpPinCmd(ENABLE);//使能唤醒管脚功能
设置SLEEPDEEP位,设置PDDS位 ,执行WFI指令,进入待机模式
void PWR_EnterSTANDBYMode(void);