stm32l1xx_hal_pwr_ex.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_pwr_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended PWR HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Power Controller (PWR) peripheral:
  8. * + Extended Initialization and de-initialization functions
  9. * + Extended Peripheral Control functions
  10. *
  11. ******************************************************************************
  12. * @attention
  13. *
  14. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  15. *
  16. * Redistribution and use in source and binary forms, with or without modification,
  17. * are permitted provided that the following conditions are met:
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  35. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ******************************************************************************
  39. */
  40. /* Includes ------------------------------------------------------------------*/
  41. #include "stm32l1xx_hal.h"
  42. /** @addtogroup STM32L1xx_HAL_Driver
  43. * @{
  44. */
  45. /** @defgroup PWREx PWREx
  46. * @brief PWR HAL module driver
  47. * @{
  48. */
  49. #ifdef HAL_PWR_MODULE_ENABLED
  50. /* Private typedef -----------------------------------------------------------*/
  51. /* Private define ------------------------------------------------------------*/
  52. /* Private macro -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/
  54. /* Private function prototypes -----------------------------------------------*/
  55. /* Private functions ---------------------------------------------------------*/
  56. /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
  57. * @{
  58. */
  59. /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Features Functions
  60. * @brief Low Power modes configuration functions
  61. *
  62. @verbatim
  63. ===============================================================================
  64. ##### Peripheral extended features functions #####
  65. ===============================================================================
  66. @endverbatim
  67. * @{
  68. */
  69. /**
  70. * @brief Return Voltage Scaling Range.
  71. * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1, PWR_REGULATOR_VOLTAGE_SCALE2 or PWR_REGULATOR_VOLTAGE_SCALE3)
  72. */
  73. uint32_t HAL_PWREx_GetVoltageRange(void)
  74. {
  75. return (PWR->CR & PWR_CR_VOS);
  76. }
  77. /**
  78. * @brief Enables the Fast WakeUp from Ultra Low Power mode.
  79. * @note This bit works in conjunction with ULP bit.
  80. * Means, when ULP = 1 and FWU = 1 :VREFINT startup time is ignored when
  81. * exiting from low power mode.
  82. * @retval None
  83. */
  84. void HAL_PWREx_EnableFastWakeUp(void)
  85. {
  86. /* Enable the fast wake up */
  87. *(__IO uint32_t *) CR_FWU_BB = (uint32_t)ENABLE;
  88. }
  89. /**
  90. * @brief Disables the Fast WakeUp from Ultra Low Power mode.
  91. * @retval None
  92. */
  93. void HAL_PWREx_DisableFastWakeUp(void)
  94. {
  95. /* Disable the fast wake up */
  96. *(__IO uint32_t *) CR_FWU_BB = (uint32_t)DISABLE;
  97. }
  98. /**
  99. * @brief Enables the Ultra Low Power mode
  100. * @retval None
  101. */
  102. void HAL_PWREx_EnableUltraLowPower(void)
  103. {
  104. /* Enable the Ultra Low Power mode */
  105. *(__IO uint32_t *) CR_ULP_BB = (uint32_t)ENABLE;
  106. }
  107. /**
  108. * @brief Disables the Ultra Low Power mode
  109. * @retval None
  110. */
  111. void HAL_PWREx_DisableUltraLowPower(void)
  112. {
  113. /* Disable the Ultra Low Power mode */
  114. *(__IO uint32_t *) CR_ULP_BB = (uint32_t)DISABLE;
  115. }
  116. /**
  117. * @brief Enters the Low Power Run mode.
  118. * @note Low power run mode can only be entered when VCORE is in range 2.
  119. * In addition, the dynamic voltage scaling must not be used when Low
  120. * power run mode is selected. Only Stop and Sleep modes with regulator
  121. * configured in Low power mode is allowed when Low power run mode is
  122. * selected.
  123. * @note In Low power run mode, all I/O pins keep the same state as in Run mode.
  124. * @retval None
  125. */
  126. void HAL_PWREx_EnableLowPowerRunMode(void)
  127. {
  128. /* Enters the Low Power Run mode */
  129. *(__IO uint32_t *) CR_LPSDSR_BB = (uint32_t)ENABLE;
  130. *(__IO uint32_t *) CR_LPRUN_BB = (uint32_t)ENABLE;
  131. }
  132. /**
  133. * @brief Exits the Low Power Run mode.
  134. * @retval None
  135. */
  136. HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
  137. {
  138. /* Exits the Low Power Run mode */
  139. *(__IO uint32_t *) CR_LPRUN_BB = (uint32_t)DISABLE;
  140. *(__IO uint32_t *) CR_LPSDSR_BB = (uint32_t)DISABLE;
  141. return HAL_OK;
  142. }
  143. /**
  144. * @}
  145. */
  146. /**
  147. * @}
  148. */
  149. #endif /* HAL_PWR_MODULE_ENABLED */
  150. /**
  151. * @}
  152. */
  153. /**
  154. * @}
  155. */
  156. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/