You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

185 lines
4.8 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_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) 2016 STMicroelectronics.
  15. * All rights reserved.</center></h2>
  16. *
  17. * This software component is licensed by ST under BSD 3-Clause license,
  18. * the "License"; You may not use this file except in compliance with the
  19. * License. You may obtain a copy of the License at:
  20. * opensource.org/licenses/BSD-3-Clause
  21. *
  22. ******************************************************************************
  23. */
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l0xx_hal.h"
  26. #ifdef HAL_PWR_MODULE_ENABLED
  27. /** @addtogroup STM32L0xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup PWREx
  31. * @{
  32. */
  33. /** @addtogroup PWREx_Private
  34. * @{
  35. */
  36. /** @defgroup PWR_Extended_TimeOut_Value PWREx Flag Setting Time Out Value
  37. * @{
  38. */
  39. #define PWR_FLAG_SETTING_DELAY_US 50U
  40. /**
  41. * @}
  42. */
  43. /**
  44. * @}
  45. */
  46. /** @addtogroup PWREx_Exported_Functions
  47. * @brief Low Power modes configuration functions
  48. *
  49. @verbatim
  50. ===============================================================================
  51. ##### Peripheral extended features functions #####
  52. ===============================================================================
  53. @endverbatim
  54. * @{
  55. */
  56. /**
  57. * @brief Return Voltage Scaling Range.
  58. * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1, PWR_REGULATOR_VOLTAGE_SCALE2 or PWR_REGULATOR_VOLTAGE_SCALE3)
  59. */
  60. uint32_t HAL_PWREx_GetVoltageRange(void)
  61. {
  62. return (PWR->CR & PWR_CR_VOS);
  63. }
  64. /**
  65. * @brief Enables the Fast WakeUp from Ultra Low Power mode.
  66. * @note This bit works in conjunction with ULP bit.
  67. * Means, when ULP = 1 and FWU = 1 :VREFINT startup time is ignored when
  68. * exiting from low power mode.
  69. * @retval None
  70. */
  71. void HAL_PWREx_EnableFastWakeUp(void)
  72. {
  73. /* Enable the fast wake up */
  74. SET_BIT(PWR->CR, PWR_CR_FWU);
  75. }
  76. /**
  77. * @brief Disables the Fast WakeUp from Ultra Low Power mode.
  78. * @retval None
  79. */
  80. void HAL_PWREx_DisableFastWakeUp(void)
  81. {
  82. /* Disable the fast wake up */
  83. CLEAR_BIT(PWR->CR, PWR_CR_FWU);
  84. }
  85. /**
  86. * @brief Enables the Ultra Low Power mode
  87. * @retval None
  88. */
  89. void HAL_PWREx_EnableUltraLowPower(void)
  90. {
  91. /* Enable the Ultra Low Power mode */
  92. SET_BIT(PWR->CR, PWR_CR_ULP);
  93. }
  94. /**
  95. * @brief Disables the Ultra Low Power mode
  96. * @retval None
  97. */
  98. void HAL_PWREx_DisableUltraLowPower(void)
  99. {
  100. /* Disable the Ultra Low Power mode */
  101. CLEAR_BIT(PWR->CR, PWR_CR_ULP);
  102. }
  103. /**
  104. * @brief Enable the Low Power Run mode.
  105. * @note Low power run mode can only be entered when VCORE is in range 2.
  106. * In addition, the dynamic voltage scaling must not be used when Low
  107. * power run mode is selected. Only Stop and Sleep modes with regulator
  108. * configured in Low power mode is allowed when Low power run mode is
  109. * selected.
  110. * @note The frequency of the system clock must be decreased to not exceed the
  111. * frequency of RCC_MSIRANGE_1.
  112. * @note In Low power run mode, all I/O pins keep the same state as in Run mode.
  113. * @retval None
  114. */
  115. void HAL_PWREx_EnableLowPowerRunMode(void)
  116. {
  117. /* Enters the Low Power Run mode */
  118. SET_BIT(PWR->CR, PWR_CR_LPSDSR);
  119. SET_BIT(PWR->CR, PWR_CR_LPRUN);
  120. }
  121. /**
  122. * @brief Disable the Low Power Run mode.
  123. * @note Before HAL_PWREx_DisableLowPowerRunMode() completion, the function checks that
  124. * REGLPF has been properly reset (otherwise, HAL_PWREx_DisableLowPowerRunMode
  125. * returns HAL_TIMEOUT status). The system clock frequency can then be
  126. * increased above 2 MHz.
  127. * @retval HAL_StatusTypeDef
  128. */
  129. HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
  130. {
  131. uint32_t wait_loop_index = 0U;
  132. /* Exit the Low Power Run mode */
  133. CLEAR_BIT(PWR->CR, PWR_CR_LPRUN);
  134. CLEAR_BIT(PWR->CR, PWR_CR_LPSDSR);
  135. /* Wait until REGLPF is reset */
  136. wait_loop_index = (PWR_FLAG_SETTING_DELAY_US * (SystemCoreClock / 1000000U));
  137. while ((wait_loop_index != 0U) && (HAL_IS_BIT_SET(PWR->CSR, PWR_CSR_REGLPF)))
  138. {
  139. wait_loop_index--;
  140. }
  141. if (HAL_IS_BIT_SET(PWR->CSR, PWR_CSR_REGLPF))
  142. {
  143. return HAL_TIMEOUT;
  144. }
  145. return HAL_OK;
  146. }
  147. /**
  148. * @}
  149. */
  150. /**
  151. * @}
  152. */
  153. /**
  154. * @}
  155. */
  156. #endif /* HAL_PWR_MODULE_ENABLED */
  157. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/