/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32_lpm_if.c * @author MCD Application Team * @brief Low layer function to enter/exit low power modes (stop, sleep) ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "platform.h" #include "stm32_lpm.h" #include "stm32_lpm_if.h" #include "usart_if.h" /* USER CODE BEGIN Includes */ #include "gpio.h" /* USER CODE END Includes */ /* External variables ---------------------------------------------------------*/ /* USER CODE BEGIN EV */ /* USER CODE END EV */ /* Private typedef -----------------------------------------------------------*/ /** * @brief Power driver callbacks handler */ const struct UTIL_LPM_Driver_s UTIL_PowerDriver = { PWR_EnterSleepMode, PWR_ExitSleepMode, PWR_EnterStopMode, PWR_ExitStopMode, PWR_EnterOffMode, PWR_ExitOffMode, }; /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Exported functions --------------------------------------------------------*/ void PWR_EnterOffMode(void) { /* USER CODE BEGIN EnterOffMode_1 */ /* Enable Power Clock */ HAL_SuspendTick(); /* Disable all used wakeup sources: Pin1(PA.0) */ HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1|PWR_WAKEUP_PIN2|PWR_WAKEUP_PIN3); /* Clear all related wakeup flags */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Re-enable all used wakeup sources: Pin1(PA.0) */ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); /*## Enter Standby Mode ####################################################*/ /* Request to enter STANDBY mode */ HAL_PWR_EnterSTANDBYMode(); /* USER CODE END EnterOffMode_1 */ } void PWR_ExitOffMode(void) { /* USER CODE BEGIN ExitOffMode_1 */ //HAL_ResumeTick(); __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); /* USER CODE END ExitOffMode_1 */ } void PWR_EnterStopMode(void) { /* USER CODE BEGIN EnterStopMode_1 */ /* USER CODE END EnterStopMode_1 */ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_All, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, ~GPIO_PIN_0, GPIO_PIN_RESET); vcom_DeInit(); HAL_SuspendTick(); /* Clear Status Flag before entering STOP/STANDBY Mode */ LL_PWR_ClearFlag_C1STOP_C1STB(); /* USER CODE BEGIN EnterStopMode_2 */ /* USER CODE END EnterStopMode_2 */ HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI); /* USER CODE BEGIN EnterStopMode_3 */ /* USER CODE END EnterStopMode_3 */ } void PWR_ExitStopMode(void) { /* USER CODE BEGIN ExitStopMode_1 */ /* USER CODE END ExitStopMode_1 */ /* Resume sysTick : work around for debugger problem in dual core */ HAL_ResumeTick(); /*Not retained periph: ADC interface DAC interface USARTx, TIMx, i2Cx, SPIx SRAM ctrls, DMAx, DMAMux, AES, RNG, HSEM */ /* Resume not retained USARTx and DMA */ //MX_GPIO_Init(); //vcom_Resume(); /* USER CODE BEGIN ExitStopMode_2 */ /* USER CODE END ExitStopMode_2 */ } void PWR_EnterSleepMode(void) { /* USER CODE BEGIN EnterSleepMode_1 */ /* USER CODE END EnterSleepMode_1 */ /* Suspend sysTick */ HAL_SuspendTick(); /* USER CODE BEGIN EnterSleepMode_2 */ /* USER CODE END EnterSleepMode_2 */ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* USER CODE BEGIN EnterSleepMode_3 */ /* USER CODE END EnterSleepMode_3 */ } void PWR_ExitSleepMode(void) { /* USER CODE BEGIN ExitSleepMode_1 */ /* USER CODE END ExitSleepMode_1 */ /* Resume sysTick */ HAL_ResumeTick(); /* USER CODE BEGIN ExitSleepMode_2 */ /* USER CODE END ExitSleepMode_2 */ } /* USER CODE BEGIN EF */ /* USER CODE END EF */ /* Private Functions Definition -----------------------------------------------*/ /* USER CODE BEGIN PrFD */ /* USER CODE END PrFD */