stm32f4xx_hal_pwr_ex.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_pwr_ex.h
  4. * @author MCD Application Team
  5. * @version V1.3.0
  6. * @date 09-March-2015
  7. * @brief Header file of PWR HAL Extension module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F4xx_HAL_PWR_EX_H
  39. #define __STM32F4xx_HAL_PWR_EX_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal_def.h"
  45. /** @addtogroup STM32F4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup PWREx
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /* Exported constants --------------------------------------------------------*/
  53. /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
  54. * @{
  55. */
  56. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx)
  57. /** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode
  58. * @{
  59. */
  60. #define PWR_MAINREGULATOR_UNDERDRIVE_ON PWR_CR_MRUDS
  61. #define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
  62. /**
  63. * @}
  64. */
  65. /** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag
  66. * @{
  67. */
  68. #define PWR_FLAG_ODRDY PWR_CSR_ODRDY
  69. #define PWR_FLAG_ODSWRDY PWR_CSR_ODSWRDY
  70. #define PWR_FLAG_UDRDY PWR_CSR_UDSWRDY
  71. /**
  72. * @}
  73. */
  74. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx */
  75. /** @defgroup PWR_Regulator_Voltage_Scale PWR Regulator Voltage Scale
  76. * @{
  77. */
  78. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F17xx)
  79. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS /* Scale 1 mode(default value at reset): the maximum value of fHCLK = 168 MHz. */
  80. #define PWR_REGULATOR_VOLTAGE_SCALE2 ((uint32_t)0x00000000) /* Scale 2 mode: the maximum value of fHCLK = 144 MHz. */
  81. #else
  82. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS /* Scale 1 mode(default value at reset): the maximum value of fHCLK is 168 MHz. It can be extended to
  83. 180 MHz by activating the over-drive mode. */
  84. #define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR_VOS_1 /* Scale 2 mode: the maximum value of fHCLK is 144 MHz. It can be extended to
  85. 168 MHz by activating the over-drive mode. */
  86. #define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR_VOS_0 /* Scale 3 mode: the maximum value of fHCLK is 120 MHz. */
  87. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  88. /**
  89. * @}
  90. */
  91. /**
  92. * @}
  93. */
  94. /* Exported macro ------------------------------------------------------------*/
  95. /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
  96. * @{
  97. */
  98. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx)
  99. /** @brief Macros to enable or disable the Over drive mode.
  100. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  101. */
  102. #define __HAL_PWR_OVERDRIVE_ENABLE() (*(__IO uint32_t *) CR_ODEN_BB = ENABLE)
  103. #define __HAL_PWR_OVERDRIVE_DISABLE() (*(__IO uint32_t *) CR_ODEN_BB = DISABLE)
  104. /** @brief Macros to enable or disable the Over drive switching.
  105. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  106. */
  107. #define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = ENABLE)
  108. #define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = DISABLE)
  109. /** @brief Macros to enable or disable the Under drive mode.
  110. * @note This mode is enabled only with STOP low power mode.
  111. * In this mode, the 1.2V domain is preserved in reduced leakage mode. This
  112. * mode is only available when the main regulator or the low power regulator
  113. * is in low voltage mode.
  114. * @note If the Under-drive mode was enabled, it is automatically disabled after
  115. * exiting Stop mode.
  116. * When the voltage regulator operates in Under-drive mode, an additional
  117. * startup delay is induced when waking up from Stop mode.
  118. */
  119. #define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR |= (uint32_t)PWR_CR_UDEN)
  120. #define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR &= (uint32_t)(~PWR_CR_UDEN))
  121. /** @brief Check PWR flag is set or not.
  122. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  123. * @param __FLAG__: specifies the flag to check.
  124. * This parameter can be one of the following values:
  125. * @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode
  126. * is ready
  127. * @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode
  128. * switching is ready
  129. * @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode
  130. * is enabled in Stop mode
  131. * @retval The new state of __FLAG__ (TRUE or FALSE).
  132. */
  133. #define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
  134. /** @brief Clear the Under-Drive Ready flag.
  135. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  136. */
  137. #define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR |= PWR_FLAG_UDRDY)
  138. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx */
  139. /**
  140. * @}
  141. */
  142. /* Exported functions --------------------------------------------------------*/
  143. /** @addtogroup PWREx_Exported_Functions PWREx Exported Functions
  144. * @{
  145. */
  146. /** @addtogroup PWREx_Exported_Functions_Group1
  147. * @{
  148. */
  149. void HAL_PWREx_EnableFlashPowerDown(void);
  150. void HAL_PWREx_DisableFlashPowerDown(void);
  151. HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void);
  152. HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void);
  153. uint32_t HAL_PWREx_GetVoltageRange(void);
  154. HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
  155. #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
  156. void HAL_PWREx_EnableMainRegulatorLowVoltage(void);
  157. void HAL_PWREx_DisableMainRegulatorLowVoltage(void);
  158. void HAL_PWREx_EnableLowRegulatorLowVoltage(void);
  159. void HAL_PWREx_DisableLowRegulatorLowVoltage(void);
  160. #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
  161. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx)
  162. HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void);
  163. HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void);
  164. HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  165. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx */
  166. /**
  167. * @}
  168. */
  169. /**
  170. * @}
  171. */
  172. /* Private types -------------------------------------------------------------*/
  173. /* Private variables ---------------------------------------------------------*/
  174. /* Private constants ---------------------------------------------------------*/
  175. /** @defgroup PWREx_Private_Constants PWREx Private Constants
  176. * @{
  177. */
  178. /** @defgroup PWREx_register_alias_address PWREx Register alias address
  179. * @{
  180. */
  181. /* ------------- PWR registers bit address in the alias region ---------------*/
  182. /* --- CR Register ---*/
  183. /* Alias word address of FPDS bit */
  184. #define FPDS_BIT_NUMBER POSITION_VAL(PWR_CR_FPDS)
  185. #define CR_FPDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (FPDS_BIT_NUMBER * 4))
  186. /* Alias word address of ODEN bit */
  187. #define ODEN_BIT_NUMBER POSITION_VAL(PWR_CR_ODEN)
  188. #define CR_ODEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (ODEN_BIT_NUMBER * 4))
  189. /* Alias word address of ODSWEN bit */
  190. #define ODSWEN_BIT_NUMBER POSITION_VAL(PWR_CR_ODSWEN)
  191. #define CR_ODSWEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (ODSWEN_BIT_NUMBER * 4))
  192. /* Alias word address of MRLVDS bit */
  193. #define MRLVDS_BIT_NUMBER POSITION_VAL(PWR_CR_MRLVDS)
  194. #define CR_MRLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (MRLVDS_BIT_NUMBER * 4))
  195. /* Alias word address of LPLVDS bit */
  196. #define LPLVDS_BIT_NUMBER POSITION_VAL(PWR_CR_LPLVDS)
  197. #define CR_LPLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (LPLVDS_BIT_NUMBER * 4))
  198. /**
  199. * @}
  200. */
  201. /** @defgroup PWREx_CSR_register_alias PWRx CSR Register alias address
  202. * @{
  203. */
  204. /* --- CSR Register ---*/
  205. /* Alias word address of BRE bit */
  206. #define BRE_BIT_NUMBER POSITION_VAL(PWR_CSR_BRE)
  207. #define CSR_BRE_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32) + (BRE_BIT_NUMBER * 4))
  208. /**
  209. * @}
  210. */
  211. /**
  212. * @}
  213. */
  214. /* Private macros ------------------------------------------------------------*/
  215. /** @defgroup PWREx_Private_Macros PWREx Private Macros
  216. * @{
  217. */
  218. /** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters
  219. * @{
  220. */
  221. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx)
  222. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \
  223. ((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON))
  224. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx */
  225. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F17xx)
  226. #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  227. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
  228. #else
  229. #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  230. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
  231. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
  232. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  233. /**
  234. * @}
  235. */
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248. #endif /* __STM32F4xx_HAL_PWR_EX_H */
  249. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/