STM32F103xB HAL User Manual
stm32f1xx_hal_pwr.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_hal_pwr.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of PWR HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef __STM32F1xx_HAL_PWR_H
00022 #define __STM32F1xx_HAL_PWR_H
00023 
00024 #ifdef __cplusplus
00025  extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f1xx_hal_def.h"
00030 
00031 /** @addtogroup STM32F1xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup PWR
00036   * @{
00037   */
00038 
00039 /* Exported types ------------------------------------------------------------*/
00040 
00041 /** @defgroup PWR_Exported_Types PWR Exported Types
00042   * @{
00043   */ 
00044 
00045 /**
00046   * @brief  PWR PVD configuration structure definition
00047   */
00048 typedef struct
00049 {
00050   uint32_t PVDLevel;   /*!< PVDLevel: Specifies the PVD detection level.
00051                             This parameter can be a value of @ref PWR_PVD_detection_level */
00052 
00053   uint32_t Mode;      /*!< Mode: Specifies the operating mode for the selected pins.
00054                            This parameter can be a value of @ref PWR_PVD_Mode */
00055 }PWR_PVDTypeDef;
00056 
00057 
00058 /**
00059   * @}
00060   */
00061 
00062 
00063 /* Internal constants --------------------------------------------------------*/
00064 
00065 /** @addtogroup PWR_Private_Constants
00066   * @{
00067   */ 
00068 
00069 #define PWR_EXTI_LINE_PVD  ((uint32_t)0x00010000)  /*!< External interrupt line 16 Connected to the PVD EXTI Line */
00070 
00071 /**
00072   * @}
00073   */
00074 
00075  
00076 /* Exported constants --------------------------------------------------------*/
00077 
00078 /** @defgroup PWR_Exported_Constants PWR Exported Constants
00079   * @{
00080   */ 
00081 
00082 /** @defgroup PWR_PVD_detection_level PWR PVD detection level
00083   * @{
00084   */
00085 #define PWR_PVDLEVEL_0                  PWR_CR_PLS_2V2
00086 #define PWR_PVDLEVEL_1                  PWR_CR_PLS_2V3
00087 #define PWR_PVDLEVEL_2                  PWR_CR_PLS_2V4
00088 #define PWR_PVDLEVEL_3                  PWR_CR_PLS_2V5
00089 #define PWR_PVDLEVEL_4                  PWR_CR_PLS_2V6
00090 #define PWR_PVDLEVEL_5                  PWR_CR_PLS_2V7
00091 #define PWR_PVDLEVEL_6                  PWR_CR_PLS_2V8
00092 #define PWR_PVDLEVEL_7                  PWR_CR_PLS_2V9 
00093                                                           
00094 /**
00095   * @}
00096   */
00097 
00098 /** @defgroup PWR_PVD_Mode PWR PVD Mode
00099   * @{
00100   */
00101 #define PWR_PVD_MODE_NORMAL                 0x00000000U   /*!< basic mode is used */
00102 #define PWR_PVD_MODE_IT_RISING              0x00010001U   /*!< External Interrupt Mode with Rising edge trigger detection */
00103 #define PWR_PVD_MODE_IT_FALLING             0x00010002U   /*!< External Interrupt Mode with Falling edge trigger detection */
00104 #define PWR_PVD_MODE_IT_RISING_FALLING      0x00010003U   /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
00105 #define PWR_PVD_MODE_EVENT_RISING           0x00020001U   /*!< Event Mode with Rising edge trigger detection */
00106 #define PWR_PVD_MODE_EVENT_FALLING          0x00020002U   /*!< Event Mode with Falling edge trigger detection */
00107 #define PWR_PVD_MODE_EVENT_RISING_FALLING   0x00020003U   /*!< Event Mode with Rising/Falling edge trigger detection */
00108 
00109 /**
00110   * @}
00111   */
00112 
00113 
00114 /** @defgroup PWR_WakeUp_Pins PWR WakeUp Pins
00115   * @{
00116   */
00117 
00118 #define PWR_WAKEUP_PIN1                 PWR_CSR_EWUP
00119 
00120 /**
00121   * @}
00122   */
00123 
00124 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR Regulator state in SLEEP/STOP mode
00125   * @{
00126   */
00127 #define PWR_MAINREGULATOR_ON                        0x00000000U
00128 #define PWR_LOWPOWERREGULATOR_ON                    PWR_CR_LPDS
00129 
00130 /**
00131   * @}
00132   */
00133 
00134 /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
00135   * @{
00136   */
00137 #define PWR_SLEEPENTRY_WFI              ((uint8_t)0x01)
00138 #define PWR_SLEEPENTRY_WFE              ((uint8_t)0x02)
00139 
00140 /**
00141   * @}
00142   */
00143 
00144 /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
00145   * @{
00146   */
00147 #define PWR_STOPENTRY_WFI               ((uint8_t)0x01)
00148 #define PWR_STOPENTRY_WFE               ((uint8_t)0x02)
00149 
00150 /**
00151   * @}
00152   */
00153 
00154 /** @defgroup PWR_Flag PWR Flag
00155   * @{
00156   */
00157 #define PWR_FLAG_WU                     PWR_CSR_WUF
00158 #define PWR_FLAG_SB                     PWR_CSR_SBF
00159 #define PWR_FLAG_PVDO                   PWR_CSR_PVDO
00160 
00161 
00162 /**
00163   * @}
00164   */
00165 
00166 /**
00167   * @}
00168   */
00169 
00170 /* Exported macro ------------------------------------------------------------*/
00171 /** @defgroup PWR_Exported_Macros PWR Exported Macros
00172   * @{
00173   */
00174 
00175 /** @brief  Check PWR flag is set or not.
00176   * @param  __FLAG__: specifies the flag to check.
00177   *           This parameter can be one of the following values:
00178   *            @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
00179   *                  was received from the WKUP pin or from the RTC alarm
00180   *                  An additional wakeup event is detected if the WKUP pin is enabled
00181   *                  (by setting the EWUP bit) when the WKUP pin level is already high.
00182   *            @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
00183   *                  resumed from StandBy mode.
00184   *            @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
00185   *                  by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode
00186   *                  For this reason, this bit is equal to 0 after Standby or reset
00187   *                  until the PVDE bit is set.
00188   * @retval The new state of __FLAG__ (TRUE or FALSE).
00189   */
00190 #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
00191 
00192 /** @brief  Clear the PWR's pending flags.
00193   * @param  __FLAG__: specifies the flag to clear.
00194   *          This parameter can be one of the following values:
00195   *            @arg PWR_FLAG_WU: Wake Up flag
00196   *            @arg PWR_FLAG_SB: StandBy flag
00197   */
00198 #define __HAL_PWR_CLEAR_FLAG(__FLAG__) SET_BIT(PWR->CR, ((__FLAG__) << 2))
00199 
00200 /**
00201   * @brief Enable interrupt on PVD Exti Line 16.
00202   * @retval None.
00203   */
00204 #define __HAL_PWR_PVD_EXTI_ENABLE_IT()      SET_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
00205 
00206 /**
00207   * @brief Disable interrupt on PVD Exti Line 16. 
00208   * @retval None.
00209   */
00210 #define __HAL_PWR_PVD_EXTI_DISABLE_IT()     CLEAR_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
00211 
00212 /**
00213   * @brief Enable event on PVD Exti Line 16.
00214   * @retval None.
00215   */
00216 #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT()   SET_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
00217 
00218 /**
00219   * @brief Disable event on PVD Exti Line 16.
00220   * @retval None.
00221   */
00222 #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT()  CLEAR_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
00223 
00224 
00225 /**
00226   * @brief  PVD EXTI line configuration: set falling edge trigger.  
00227   * @retval None.
00228   */
00229 #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE()  SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
00230 
00231 
00232 /**
00233   * @brief Disable the PVD Extended Interrupt Falling Trigger.
00234   * @retval None.
00235   */
00236 #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
00237 
00238 
00239 /**
00240   * @brief  PVD EXTI line configuration: set rising edge trigger.
00241   * @retval None.
00242   */
00243 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE()   SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
00244 
00245 /**
00246   * @brief Disable the PVD Extended Interrupt Rising Trigger.
00247   * This parameter can be:
00248   * @retval None.
00249   */
00250 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE()  CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
00251 
00252 /**
00253   * @brief  PVD EXTI line configuration: set rising & falling edge trigger.
00254   * @retval None.
00255   */
00256 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE()   __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
00257 
00258 /**
00259   * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
00260   * This parameter can be:
00261   * @retval None.
00262   */
00263 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE()  __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
00264 
00265 
00266 
00267 /**
00268   * @brief Check whether the specified PVD EXTI interrupt flag is set or not.
00269   * @retval EXTI PVD Line Status.
00270   */
00271 #define __HAL_PWR_PVD_EXTI_GET_FLAG()       (EXTI->PR & (PWR_EXTI_LINE_PVD))
00272 
00273 /**
00274   * @brief Clear the PVD EXTI flag.
00275   * @retval None.
00276   */
00277 #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG()     (EXTI->PR = (PWR_EXTI_LINE_PVD))
00278 
00279 /**
00280   * @brief Generate a Software interrupt on selected EXTI line.
00281   * @retval None.
00282   */
00283 #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT()  SET_BIT(EXTI->SWIER, PWR_EXTI_LINE_PVD)
00284 /**
00285   * @}
00286   */
00287 
00288 /* Private macro -------------------------------------------------------------*/
00289 /** @defgroup PWR_Private_Macros PWR Private Macros
00290   * @{
00291   */
00292 #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
00293                                  ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
00294                                  ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
00295                                  ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
00296 
00297 
00298 #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
00299                               ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
00300                               ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \
00301                               ((MODE) == PWR_PVD_MODE_NORMAL)) 
00302 
00303 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1))
00304 
00305 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
00306                                      ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
00307 
00308 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
00309 
00310 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
00311 
00312 /**
00313   * @}
00314   */
00315 
00316 
00317 
00318 /* Exported functions --------------------------------------------------------*/
00319 
00320 /** @addtogroup PWR_Exported_Functions PWR Exported Functions
00321   * @{
00322   */
00323   
00324 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 
00325   * @{
00326   */
00327 
00328 /* Initialization and de-initialization functions *******************************/
00329 void HAL_PWR_DeInit(void);
00330 void HAL_PWR_EnableBkUpAccess(void);
00331 void HAL_PWR_DisableBkUpAccess(void);
00332 
00333 /**
00334   * @}
00335   */
00336 
00337 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 
00338   * @{
00339   */
00340 
00341 /* Peripheral Control functions  ************************************************/
00342 void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
00343 /* #define HAL_PWR_ConfigPVD 12*/
00344 void HAL_PWR_EnablePVD(void);
00345 void HAL_PWR_DisablePVD(void);
00346 
00347 /* WakeUp pins configuration functions ****************************************/
00348 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx);
00349 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
00350 
00351 /* Low Power modes configuration functions ************************************/
00352 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
00353 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
00354 void HAL_PWR_EnterSTANDBYMode(void);
00355 
00356 void HAL_PWR_EnableSleepOnExit(void);
00357 void HAL_PWR_DisableSleepOnExit(void);
00358 void HAL_PWR_EnableSEVOnPend(void);
00359 void HAL_PWR_DisableSEVOnPend(void);
00360 
00361 
00362 
00363 void HAL_PWR_PVD_IRQHandler(void);
00364 void HAL_PWR_PVDCallback(void);
00365 /**
00366   * @}
00367   */
00368 
00369 /**
00370   * @}
00371   */
00372 
00373 /**
00374   * @}
00375   */
00376 
00377 /**
00378   * @}
00379   */
00380 
00381 #ifdef __cplusplus
00382 }
00383 #endif
00384 
00385 
00386 #endif /* __STM32F1xx_HAL_PWR_H */
00387 
00388 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/