134 lines
3.4 KiB
C
134 lines
3.4 KiB
C
/*******************************************************************************
|
|
* @file stm32_lpm_if.c
|
|
* @author MCD Application Team
|
|
* @brief Low layer function to enter/exit low power modes (stop, sleep)
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
|
* All rights reserved.</center></h2>
|
|
*
|
|
* This software component is licensed by ST under Ultimate Liberty license
|
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at:
|
|
* www.st.com/SLA0044
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "stm32_lpm_if.h"
|
|
#include "usart_if.h"
|
|
|
|
/* External variables --------------------------------------------------------*/
|
|
extern UART_HandleTypeDef huart1;
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
const struct UTIL_LPM_Driver_s UTIL_PowerDriver =
|
|
{
|
|
PWR_EnterSleepMode,
|
|
PWR_ExitSleepMode,
|
|
|
|
PWR_EnterStopMode,
|
|
PWR_ExitStopMode,
|
|
|
|
PWR_EnterOffMode,
|
|
PWR_ExitOffMode,
|
|
};
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* Exported variables --------------------------------------------------------*/
|
|
/* Exported functions --------------------------------------------------------*/
|
|
|
|
/**
|
|
* @brief Enters Low Power Off Mode
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void PWR_EnterOffMode(void)
|
|
{
|
|
}
|
|
/**
|
|
* @brief Exits Low Power Off Mode
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void PWR_ExitOffMode(void)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @brief Enters Low Power Stop Mode
|
|
* @note ARM exists the function when waking up
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void PWR_EnterStopMode(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
/* Clear Status Flag before entering STOP/STANDBY Mode */
|
|
LL_PWR_ClearFlag_C1STOP_C1STB();
|
|
/* USER CODE END 1 */
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
|
|
/* USER CODE END 2 */
|
|
}
|
|
/**
|
|
* @brief Exits Low Power Stop Mode
|
|
* @note Enable the pll at 32MHz
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void PWR_ExitStopMode(void)
|
|
{
|
|
/* USER CODE BEGIN 4 */
|
|
/*Not retained periph:
|
|
ADC interface
|
|
DAC interface USARTx, TIMx, i2Cx, SPIx
|
|
SRAM ctrls, DMAx, DMAMux, AES, RNG, HSEM */
|
|
/*to reenable lost DMA settings*/
|
|
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* USER CODE END 4 */
|
|
}
|
|
|
|
/**
|
|
* @brief Enters Low Power Sleep Mode
|
|
* @note ARM exits the function when waking up
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void PWR_EnterSleepMode(void)
|
|
{
|
|
/* Suspend sysTick */
|
|
HAL_SuspendTick();
|
|
|
|
/* USER CODE BEGIN 5 */
|
|
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
|
|
/* USER CODE END 5 */
|
|
}
|
|
|
|
/**
|
|
* @brief Enters Low Power Sleep Mode
|
|
* @note ARM exits the function when waking up
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void PWR_ExitSleepMode(void)
|
|
{
|
|
/* Suspend sysTick */
|
|
HAL_ResumeTick();
|
|
|
|
}
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
|