2019-09-30 01:15 AM
/*
I have attached code here, This explains if you press interrupt button it enters into the sleep mode, In sleep mode It is initializing all GPIO and clk are fine but after Disable GPIOs clock board breaks means showing ST link error . This error I can fix but I need run Sleep mode function perfectly please help me out by referring this code.
*/
/*In main Function*/
while (1)
{
/* USER CODE END WHILE */
UserButtonStatus = 0;
/* Configure Key Button */
BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_EXTI);
/* Wait until Key button is pressed to enter the Low Power mode */
while(UserButtonStatus == 0)
{
/* Toggle The LED6 */
BSP_LED_Toggle(LED_GREEN);
/* Inserted Delay */
HAL_Delay(100);
}
/* Loop while Key button is maintained pressed */
while(BSP_PB_GetState(BUTTON_WAKEUP) != RESET)
{
}
SleepMode_Measure();
/* USER CODE BEGIN 3 */
}
/*Sleep Mode Function*/
void SleepMode_Measure(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Configure all GPIO as analog to reduce current consumption on non used IOs */
/* Enable GPIOs clock */
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__GPIOE_CLK_ENABLE();
__GPIOF_CLK_ENABLE();
__GPIOG_CLK_ENABLE();
__GPIOH_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_All;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Disable GPIOs clock */
__GPIOA_CLK_DISABLE();
__GPIOB_CLK_DISABLE();
__GPIOC_CLK_DISABLE();
__GPIOD_CLK_DISABLE();
__GPIOE_CLK_DISABLE();
__GPIOF_CLK_DISABLE();
__GPIOG_CLK_DISABLE();
__GPIOH_CLK_DISABLE();
/* Configure Key Button */
BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_EXTI);
/* Suspend Tick increment to prevent wakeup by Systick interrupt.
Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base) */
HAL_SuspendTick();
/* Request to enter SLEEP mode */
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
/* Resume Tick interrupt if disabled prior to sleep mode entry */
HAL_ResumeTick();
/* Initialize LED6 */
BSP_LED_Init(LED_GREEN);
/* Turn LED6 On */
BSP_LED_On(LED_GREEN);
/* Inserted Delay */
HAL_Delay(200);
}