参考标准库例子配置低功耗模式,是否存在问题呢
void System_Clk_Config(void)
{
RCC_HSI_Enable( RCC_HSIOSC_DIV2); //配置系统时钟为HSI 24M
//Enable Systick Clk
InitTick(24000000ul); //初始化SysTick
}
void RCC_CLK_Config(void)
{
//外设时钟使能
__RCC_GPIOA_CLK_ENABLE();
__RCC_GPIOB_CLK_ENABLE();
__RCC_GPIOC_CLK_ENABLE();
__RCC_GPIOF_CLK_ENABLE();
__RCC_UART2_CLK_ENABLE();
__RCC_BTIM_CLK_ENABLE();
__RCC_DMA_CLK_ENABLE();
}
void SleepModeTest(void)
{
GPIO_InitTypeDef GPIO_InitStructure = {0};
PWR_InitTypeDef PWR_InitStructure = {0};
/* Configure all GPIO as analog to reduce current consumption on non used IOs */
/* Enable GPIOs clock */
/* Warning : Reconfiguring all GPIO will close the connexion with the debugger */
//打开GPIO时钟
REGBITS_SET( CW_SYSCTRL->AHBEN, SYSCTRL_AHBEN_GPIOA_Msk | SYSCTRL_AHBEN_GPIOB_Msk |\
SYSCTRL_AHBEN_GPIOC_Msk | SYSCTRL_AHBEN_GPIOF_Msk);
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_InitStructure.Pins = GPIO_PIN_All;
GPIO_Init(CW_GPIOA, &GPIO_InitStructure);
GPIO_Init(CW_GPIOB, &GPIO_InitStructure);
GPIO_Init(CW_GPIOC, &GPIO_InitStructure);
GPIO_Init(CW_GPIOF, &GPIO_InitStructure);
/* Disable GPIOs clock */
REGBITS_CLR( CW_SYSCTRL->AHBEN, SYSCTRL_AHBEN_GPIOA_Msk | SYSCTRL_AHBEN_GPIOB_Msk |\
SYSCTRL_AHBEN_GPIOC_Msk | SYSCTRL_AHBEN_GPIOF_Msk);
/*Suspend Tick increment to prevent wakeup by Systick interrupt.
Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/
SuspendTick();
BTIM_Cmd(CW_BTIM1, DISABLE);
RCC_WAKEUPCLK_Config(RCC_SYSCTRL_WAKEUPCLKEN);
/* Request to enter SLEEP mode */
//HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
PWR_InitStructure.PWR_Sevonpend = PWR_Sevonpend_Disable;
PWR_InitStructure.PWR_SleepDeep = PWR_SleepDeep_Disable;
PWR_InitStructure.PWR_SleepOnExit = PWR_SleepOnExit_Enable;
PWR_Config(&PWR_InitStructure);
PWR_GotoLpmMode();
BTIM_Cmd(CW_BTIM1, ENABLE);
/* Resume Tick interrupt if disabled prior to sleep mode entry*/
ResumeTick();
}
int32_t main(void)
{
System_Clk_Config();
RCC_CLK_Config();
bsp_usart2_init(9600);
uart_device_init(DEV_UART2);
GPIO_LED_Init();
base_timer_init(1000,24);
app_task_led_creat();
while (1)
{
/* code */
ParseDataFromUsart2();
SysTickDelay(1000);
SysTickDelay(1000);
SysTickDelay(1000);
SysTickDelay(1000);
SysTickDelay(1000);
SleepModeTest();
}
}
|
面粉兑水了进入浆糊模式。没看到进入低功耗模式的语句。