使用官方的WKUP例程,进入主循环后只有一个sleep()函数,上电后功耗是正常睡眠功耗,然后通过按键唤醒后能看到功耗上去了,但是没降回来,按理说主循环会重复休眠啊!
主循环:
while(1) { Sleep(); }
sleep函数:
void Sleep(void) { FL_RCC_RCMF_Disable(); //关闭RCMF FL_RMU_PDR_Enable(RMU); //打开PDR FL_RMU_BORPowerDown_Disable(RMU); //关闭BOR 2uA /*使用ADC时ADCMonitor功能以及Vref需同时开始,同时关闭*/ FL_VREF_Disable(VREF); //关闭VREF1p2 FL_SVD_DisableADCMonitor(SVD); //关闭ADC电源检测 FL_ADC_Disable(ADC); //关闭ADC使能 FL_PMU_SetLowPowerMode(PMU, FL_PMU_POWER_MODE_SLEEP_OR_DEEPSLEEP); __WFI(); }
初始化函数:
void MF_PMU_Init(void) { /*IO CONFIG*/ FL_PMU_SleepInitTypeDef defaultInitStruct; defaultInitStruct.deepSleep = FL_PMU_SLEEP_MODE_DEEP; defaultInitStruct.LDOLowPowerMode = FL_PMU_LDO_LPM_DISABLE; defaultInitStruct.wakeupFrequency = FL_PMU_RCHF_WAKEUP_FREQ_8MHZ; defaultInitStruct.wakeupDelay = FL_PMU_WAKEUP_DELAY_2US; defaultInitStruct.coreVoltageScaling = FL_DISABLE; FL_PMU_Sleep_Init(PMU,&defaultInitStruct ); } void NMI_Handler(void) { //NWKUP默认连接到了cpu的NMI不可屏蔽中断,不受NVIC控制,不受全局中断使能控制,唤醒后必然进NMI中断 if(FL_SET == FL_PMU_IsActiveFlag_WakeupPIN(PMU, FL_PMU_WKUP7PIN)) { FL_PMU_ClearFlag_WakeupPIN(PMU, FL_PMU_WKUP7PIN); } FL_PMU_ClearFlag_WakeupPIN(PMU, FL_PMU_WKUP7PIN); } // 外部引脚中断初始化 void WKUP_init(void) { FL_GPIO_InitTypeDef GPIO_InitStruct = {0}; //引脚边沿触发选择 FL_RCC_EnableEXTIOnSleep();//休眠使能外部中断采样 FL_RCC_EnableGroup1OperationClock(FL_RCC_GROUP1_OPCLK_EXTI);//EXTI工作时钟使能 //用到的GPIO引脚 设为输入 GPIO_InitStruct.pin = FL_GPIO_PIN_6; GPIO_InitStruct.mode = FL_GPIO_MODE_INPUT; GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL; GPIO_InitStruct.pull = FL_DISABLE; GPIO_InitStruct.remapPin = FL_DISABLE; FL_GPIO_Init(GPIOD, &GPIO_InitStruct); FL_GPIO_SetWakeupInterruptEntry(GPIO, FL_GPIO_WAKEUP_INT_ENTRY_NMI);//NMI中断入口 FL_GPIO_SetWakeupEdge(GPIO, FL_GPIO_WAKEUP_7, FL_GPIO_WAKEUP_TRIGGER_FALLING);//下降沿唤醒 FL_GPIO_EnableWakeup(GPIO, FL_GPIO_WAKEUP_7);//使能NWKUP功能 }