KW36进入低功耗的处理函数是PWR_HandleDeepSleepMode_x这种函数,以PWR_HandleDeepSleepMode_1为例,进入休眠前要调用BOARD_BLPEtoBLPI(),把时钟从BLPE(外部)切换到BLPI(内部),关闭高频晶振,才能进入休眠模式。但是,SDK中BOARD_BLPEtoBLPI没有实现代码,是一个空函数。
所以并没有实现关闭高频晶振,导致功耗一直很高。此时要实现低功耗,需要自己实现BOARD_BLPEtoBLPI、BOARD_BLPItoBLPE,参考代码如下:
void BOARD_BLPEtoBLPI(void)
{
/* Change FEE -> FBI
* It's transitional mode, don't need to wait for FLL stable,
* so NULL is passed as variable here.
*/
CLOCK_SetFbiMode(kMCG_Dmx32Default, kMCG_DrsLow, NULL);
assert(kMCG_ModeFBI == CLOCK_GetMode());
/* Change FBI -> BLPI */
CLOCK_SetLowPowerEnable(true);
assert(kMCG_ModeBLPI == CLOCK_GetMode());
}
/*!
* @brief Delay function used to wait FLL stable.
*/
static void APP_FllStableDelay(void)
{
volatile uint32_t i = 30000U;
while (i--)
{
__NOP();
}
}
void BOARD_BLPItoBLPE(void)
{
extern const mcg_config_t mcgConfig_BOARD_BootClockRUN;
while((RSIM->CONTROL & RSIM_CONTROL_RF_OSC_READY_MASK) == 0 )
{}
/* Change BLPI -> FBI */
CLOCK_SetLowPowerEnable(false);
assert(kMCG_ModeFBI == CLOCK_GetMode());
/* Change FBI -> FEE */
CLOCK_SetFeeMode(mcgConfig_BOARD_BootClockRUN.frdiv,
mcgConfig_BOARD_BootClockRUN.dmx32,
mcgConfig_BOARD_BootClockRUN.drs,
APP_FllStableDelay);
assert(kMCG_ModeFEE == CLOCK_GetMode());
}
这样就可以实现进入低功耗时关闭高频晶振,退出低功耗恢复高频晶振,从而降低功耗。实测休眠电流为4.33uA
但是测试主机功能时,发现扫描功能异常,退出低功耗,进行第二次扫描时,扫描不到设备。如果需要BLE功能正常,不能使用外部高频时钟作为时钟源,可使用外部32k晶振。修改代码如附件:
previewFile.do?fileId=1522512010617733122