TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_pwr.h Source File

stm32l4xx_hal_pwr.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_pwr.h
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   Header file of PWR HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_HAL_PWR_H
00040 #define __STM32L4xx_HAL_PWR_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx_hal_def.h"
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup PWR
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/ 
00058 
00059 /** @defgroup PWR_Exported_Types PWR Exported Types
00060   * @{
00061   */
00062 
00063 /**
00064   * @brief  PWR PVD configuration structure definition
00065   */
00066 typedef struct
00067 {
00068   uint32_t PVDLevel;   /*!< PVDLevel: Specifies the PVD detection level.
00069                             This parameter can be a value of @ref PWR_PVD_detection_level. */
00070 
00071   uint32_t Mode;      /*!< Mode: Specifies the operating mode for the selected pins.
00072                            This parameter can be a value of @ref PWR_PVD_Mode. */
00073 }PWR_PVDTypeDef;
00074 
00075 
00076 /**
00077   * @}
00078   */
00079 
00080 /* Exported constants --------------------------------------------------------*/
00081 
00082 /** @defgroup PWR_Exported_Constants PWR Exported Constants
00083   * @{
00084   */
00085 
00086 
00087 /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels
00088   * @{
00089   */
00090 #define PWR_PVDLEVEL_0                  PWR_CR2_PLS_LEV0  /*!< PVD threshold around 2.0 V */
00091 #define PWR_PVDLEVEL_1                  PWR_CR2_PLS_LEV1  /*!< PVD threshold around 2.2 V */
00092 #define PWR_PVDLEVEL_2                  PWR_CR2_PLS_LEV2  /*!< PVD threshold around 2.4 V */
00093 #define PWR_PVDLEVEL_3                  PWR_CR2_PLS_LEV3  /*!< PVD threshold around 2.5 V */
00094 #define PWR_PVDLEVEL_4                  PWR_CR2_PLS_LEV4  /*!< PVD threshold around 2.6 V */
00095 #define PWR_PVDLEVEL_5                  PWR_CR2_PLS_LEV5  /*!< PVD threshold around 2.8 V */
00096 #define PWR_PVDLEVEL_6                  PWR_CR2_PLS_LEV6  /*!< PVD threshold around 2.9 V */
00097 #define PWR_PVDLEVEL_7                  PWR_CR2_PLS_LEV7  /*!< External input analog voltage (compared internally to VREFINT) */
00098 /**
00099   * @}
00100   */
00101 
00102 /** @defgroup PWR_PVD_Mode  PWR PVD interrupt and event mode
00103   * @{
00104   */
00105 #define PWR_PVD_MODE_NORMAL                 ((uint32_t)0x00000000)   /*!< Basic mode is used */
00106 #define PWR_PVD_MODE_IT_RISING              ((uint32_t)0x00010001)   /*!< External Interrupt Mode with Rising edge trigger detection */
00107 #define PWR_PVD_MODE_IT_FALLING             ((uint32_t)0x00010002)   /*!< External Interrupt Mode with Falling edge trigger detection */
00108 #define PWR_PVD_MODE_IT_RISING_FALLING      ((uint32_t)0x00010003)   /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
00109 #define PWR_PVD_MODE_EVENT_RISING           ((uint32_t)0x00020001)   /*!< Event Mode with Rising edge trigger detection */
00110 #define PWR_PVD_MODE_EVENT_FALLING          ((uint32_t)0x00020002)   /*!< Event Mode with Falling edge trigger detection */
00111 #define PWR_PVD_MODE_EVENT_RISING_FALLING   ((uint32_t)0x00020003)   /*!< Event Mode with Rising/Falling edge trigger detection */                               
00112 /**
00113   * @}
00114   */
00115   
00116   
00117 
00118 
00119 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode  PWR regulator mode
00120   * @{
00121   */
00122 #define PWR_MAINREGULATOR_ON            ((uint32_t)0x00000000) /*!< Regulator in main mode      */
00123 #define PWR_LOWPOWERREGULATOR_ON        PWR_CR1_LPR            /*!< Regulator in low-power mode */
00124 /**
00125   * @}
00126   */
00127 
00128 /** @defgroup PWR_SLEEP_mode_entry  PWR SLEEP mode entry
00129   * @{
00130   */
00131 #define PWR_SLEEPENTRY_WFI              ((uint8_t)0x01)        /*!< Wait For Interruption instruction to enter Sleep mode */
00132 #define PWR_SLEEPENTRY_WFE              ((uint8_t)0x02)        /*!< Wait For Event instruction to enter Sleep mode        */
00133 /**
00134   * @}
00135   */
00136 
00137 /** @defgroup PWR_STOP_mode_entry  PWR STOP mode entry
00138   * @{
00139   */
00140 #define PWR_STOPENTRY_WFI               ((uint8_t)0x01)       /*!< Wait For Interruption instruction to enter Stop mode */
00141 #define PWR_STOPENTRY_WFE               ((uint8_t)0x02)       /*!< Wait For Event instruction to enter Stop mode        */
00142 /**
00143   * @}
00144   */
00145   
00146 
00147 /** @defgroup PWR_PVD_EXTI_LINE  PWR PVD external interrupt line
00148   * @{
00149   */
00150 #define PWR_EXTI_LINE_PVD  ((uint32_t)0x00010000)   /*!< External interrupt line 16 Connected to the PVD EXTI Line */
00151 /**
00152   * @}
00153   */
00154 
00155 /** @defgroup PWR_PVD_EVENT_LINE  PWR PVD event line
00156   * @{
00157   */  
00158 #define PWR_EVENT_LINE_PVD  ((uint32_t)0x00010000)  /*!< Event line 16 Connected to the PVD Event Line */
00159 /**
00160   * @}
00161   */
00162 
00163 /**
00164   * @}
00165   */
00166 
00167 /* Exported macros -----------------------------------------------------------*/
00168 /** @defgroup PWR_Exported_Macros  PWR Exported Macros
00169   * @{
00170   */
00171 
00172 /** @brief  Check whether or not a specific PWR flag is set.
00173   * @param  __FLAG__: specifies the flag to check.
00174   *           This parameter can be one of the following values:
00175   *            @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
00176   *                  was received from the WKUP pin 1.
00177   *            @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
00178   *                  was received from the WKUP pin 2.
00179   *            @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
00180   *                  was received from the WKUP pin 3.
00181   *            @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
00182   *                  was received from the WKUP pin 4.
00183   *            @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
00184   *                  was received from the WKUP pin 5.          
00185   *            @arg @ref PWR_FLAG_SB StandBy Flag. Indicates that the system
00186   *                  entered StandBy mode.
00187   *            @arg @ref PWR_FLAG_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on
00188   *                 the internal wakeup line.
00189   *            @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the 
00190   *                 low-power regulator is ready.
00191   *            @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the 
00192   *                 regulator is ready in main mode or is in low-power mode. 
00193   *            @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready 
00194   *                 in the selected voltage range or is still changing to the required voltage level.
00195   *            @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is
00196   *                  below or above the selected PVD threshold.
00197   *            @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is
00198   *                  is below or above PVM1 threshold (applicable when USB feature is supported).
00199   @if STM32L486xx
00200   *            @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is
00201   *                  is below or above PVM2 threshold (applicable when VDDIO2 is present on device). 
00202   @endif
00203   *            @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is
00204   *                  is below or above PVM3 threshold. 
00205   *            @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is
00206   *                  is below or above PVM4 threshold.                           
00207   *    
00208   * @retval The new state of __FLAG__ (TRUE or FALSE).
00209   */
00210 #define __HAL_PWR_GET_FLAG(__FLAG__)  ( ((((uint8_t)(__FLAG__)) >> 5U) == 1)  ?\
00211                                       (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\
00212                                       (PWR->SR2 & (1U << ((__FLAG__) & 31U))) )
00213 
00214 /** @brief  Clear a specific PWR flag.
00215   * @param  __FLAG__: specifies the flag to clear.
00216   *          This parameter can be one of the following values:
00217   *            @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
00218   *                  was received from the WKUP pin 1.
00219   *            @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
00220   *                  was received from the WKUP pin 2.
00221   *            @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
00222   *                  was received from the WKUP pin 3.
00223   *            @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
00224   *                  was received from the WKUP pin 4.
00225   *            @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
00226   *                  was received from the WKUP pin 5.
00227   *            @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags.
00228   *            @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system
00229   *                  entered Standby mode.
00230   * @retval None   
00231   */
00232 #define __HAL_PWR_CLEAR_FLAG(__FLAG__)   ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\
00233                                          (PWR->SCR  = (__FLAG__)) :\
00234                                          (PWR->SCR = (1U << ((__FLAG__) & 31U))) )
00235 /**
00236   * @brief Enable the PVD Extended Interrupt Line.
00237   * @retval None
00238   */
00239 #define __HAL_PWR_PVD_EXTI_ENABLE_IT()   SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
00240 
00241 /**
00242   * @brief Disable the PVD Extended Interrupt Line.
00243   * @retval None
00244   */
00245 #define __HAL_PWR_PVD_EXTI_DISABLE_IT()  CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
00246 
00247 /**
00248   * @brief Enable the PVD Event Line.
00249   * @retval None
00250   */
00251 #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT()   SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
00252 
00253 /**
00254   * @brief Disable the PVD Event Line.
00255   * @retval None
00256   */
00257 #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT()  CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
00258 
00259 /**
00260   * @brief Enable the PVD Extended Interrupt Rising Trigger.
00261   * @retval None
00262   */
00263 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE()   SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
00264 
00265 /**
00266   * @brief Disable the PVD Extended Interrupt Rising Trigger.
00267   * @retval None
00268   */
00269 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE()  CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
00270 
00271 /**
00272   * @brief Enable the PVD Extended Interrupt Falling Trigger.
00273   * @retval None
00274   */
00275 #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE()   SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
00276 
00277 
00278 /**
00279   * @brief Disable the PVD Extended Interrupt Falling Trigger.
00280   * @retval None
00281   */
00282 #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
00283 
00284 
00285 /**
00286   * @brief  Enable the PVD Extended Interrupt Rising & Falling Trigger.
00287   * @retval None
00288   */
00289 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE()  \
00290   do {                                                   \
00291     __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();             \
00292     __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();            \
00293   } while(0)
00294 
00295 /**
00296   * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
00297   * @retval None
00298   */
00299 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE()  \
00300   do {                                                    \
00301     __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();             \
00302     __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();            \
00303   } while(0)
00304 
00305 /**
00306   * @brief  Generate a Software interrupt on selected EXTI line.
00307   * @retval None
00308   */
00309 #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD)
00310 
00311 /**
00312   * @brief Check whether or not the PVD EXTI interrupt flag is set.
00313   * @retval EXTI PVD Line Status.
00314   */
00315 #define __HAL_PWR_PVD_EXTI_GET_FLAG()  (EXTI->PR1 & PWR_EXTI_LINE_PVD)
00316 
00317 /**
00318   * @brief Clear the PVD EXTI interrupt flag.
00319   * @retval None
00320   */
00321 #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG()  WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD)
00322 
00323 /**
00324   * @}
00325   */
00326   
00327 
00328 /* Private macros --------------------------------------------------------*/
00329 /** @addtogroup  PWR_Private_Macros   PWR Private Macros
00330   * @{
00331   */
00332 
00333 #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
00334                                  ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
00335                                  ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
00336                                  ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
00337                                  
00338 #define IS_PWR_PVD_MODE(MODE)  (((MODE) == PWR_PVD_MODE_NORMAL)              ||\
00339                                 ((MODE) == PWR_PVD_MODE_IT_RISING)           ||\
00340                                 ((MODE) == PWR_PVD_MODE_IT_FALLING)          ||\
00341                                 ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING)   ||\
00342                                 ((MODE) == PWR_PVD_MODE_EVENT_RISING)        ||\
00343                                 ((MODE) == PWR_PVD_MODE_EVENT_FALLING)       ||\
00344                                 ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING)) 
00345                                 
00346 #define IS_PWR_REGULATOR(REGULATOR)      (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
00347                                           ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
00348                                           
00349 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
00350 
00351 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) )
00352                                       
00353 /**
00354   * @}
00355   */  
00356 
00357 /* Include PWR HAL Extended module */
00358 #include "stm32l4xx_hal_pwr_ex.h"
00359 
00360 /* Exported functions --------------------------------------------------------*/
00361 
00362 /** @addtogroup PWR_Exported_Functions PWR Exported Functions
00363   * @{
00364   */
00365   
00366 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 
00367   * @{
00368   */
00369   
00370 /* Initialization and de-initialization functions *******************************/
00371 void HAL_PWR_DeInit(void);
00372 void HAL_PWR_EnableBkUpAccess(void);
00373 void HAL_PWR_DisableBkUpAccess(void);
00374 
00375 /**
00376   * @}
00377   */
00378 
00379 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 
00380   * @{
00381   */
00382 
00383 /* Peripheral Control functions  ************************************************/
00384 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
00385 void HAL_PWR_EnablePVD(void);
00386 void HAL_PWR_DisablePVD(void);
00387 
00388 
00389 /* WakeUp pins configuration functions ****************************************/
00390 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
00391 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
00392 
00393 /* Low Power modes configuration functions ************************************/
00394 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
00395 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
00396 void HAL_PWR_EnterSTANDBYMode(void);
00397 
00398 void HAL_PWR_EnableSleepOnExit(void);
00399 void HAL_PWR_DisableSleepOnExit(void);
00400 void HAL_PWR_EnableSEVOnPend(void);
00401 void HAL_PWR_DisableSEVOnPend(void);
00402 
00403 void HAL_PWR_PVDCallback(void);
00404 
00405 
00406 /**
00407   * @}
00408   */
00409   
00410 /**
00411   * @}
00412   */  
00413 
00414 /**
00415   * @}
00416   */
00417 
00418 /**
00419   * @}
00420   */
00421   
00422 #ifdef __cplusplus
00423 }
00424 #endif
00425 
00426 
00427 #endif /* __STM32L4xx_HAL_PWR_H */
00428 
00429 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/