stm32f4xx_hal_pwr_ex.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_pwr_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR HAL Extension module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F4xx_HAL_PWR_EX_H
  37. #define __STM32F4xx_HAL_PWR_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f4xx_hal_def.h"
  43. /** @addtogroup STM32F4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup PWREx
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /* Exported constants --------------------------------------------------------*/
  51. /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
  52. * @{
  53. */
  54. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  55. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  56. /** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode
  57. * @{
  58. */
  59. #define PWR_MAINREGULATOR_UNDERDRIVE_ON PWR_CR_MRUDS
  60. #define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
  61. /**
  62. * @}
  63. */
  64. /** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag
  65. * @{
  66. */
  67. #define PWR_FLAG_ODRDY PWR_CSR_ODRDY
  68. #define PWR_FLAG_ODSWRDY PWR_CSR_ODSWRDY
  69. #define PWR_FLAG_UDRDY PWR_CSR_UDSWRDY
  70. /**
  71. * @}
  72. */
  73. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  74. /** @defgroup PWREx_Regulator_Voltage_Scale PWREx Regulator Voltage Scale
  75. * @{
  76. */
  77. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
  78. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS /* Scale 1 mode(default value at reset): the maximum value of fHCLK = 168 MHz. */
  79. #define PWR_REGULATOR_VOLTAGE_SCALE2 0x00000000U /* Scale 2 mode: the maximum value of fHCLK = 144 MHz. */
  80. #else
  81. #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
  82. 180 MHz by activating the over-drive mode. */
  83. #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
  84. 168 MHz by activating the over-drive mode. */
  85. #define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR_VOS_0 /* Scale 3 mode: the maximum value of fHCLK is 120 MHz. */
  86. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  87. /**
  88. * @}
  89. */
  90. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  91. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  92. /** @defgroup PWREx_WakeUp_Pins PWREx WakeUp Pins
  93. * @{
  94. */
  95. #define PWR_WAKEUP_PIN2 0x00000080U
  96. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  97. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  98. #define PWR_WAKEUP_PIN3 0x00000040U
  99. #endif /* STM32F410xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Zx || STM32F412Vx || \
  100. STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
  101. /**
  102. * @}
  103. */
  104. #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx ||
  105. STM32F413xx || STM32F423xx */
  106. /**
  107. * @}
  108. */
  109. /* Exported macro ------------------------------------------------------------*/
  110. /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
  111. * @{
  112. */
  113. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
  114. /** @brief macros configure the main internal regulator output voltage.
  115. * @param __REGULATOR__ specifies the regulator output voltage to achieve
  116. * a tradeoff between performance and power consumption when the device does
  117. * not operate at the maximum frequency (refer to the datasheets for more details).
  118. * This parameter can be one of the following values:
  119. * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
  120. * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
  121. * @retval None
  122. */
  123. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \
  124. __IO uint32_t tmpreg = 0x00U; \
  125. MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)); \
  126. /* Delay after an RCC peripheral clock enabling */ \
  127. tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS); \
  128. UNUSED(tmpreg); \
  129. } while(0U)
  130. #else
  131. /** @brief macros configure the main internal regulator output voltage.
  132. * @param __REGULATOR__ specifies the regulator output voltage to achieve
  133. * a tradeoff between performance and power consumption when the device does
  134. * not operate at the maximum frequency (refer to the datasheets for more details).
  135. * This parameter can be one of the following values:
  136. * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
  137. * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
  138. * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode
  139. * @retval None
  140. */
  141. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \
  142. __IO uint32_t tmpreg = 0x00U; \
  143. MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)); \
  144. /* Delay after an RCC peripheral clock enabling */ \
  145. tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS); \
  146. UNUSED(tmpreg); \
  147. } while(0U)
  148. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  149. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  150. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  151. /** @brief Macros to enable or disable the Over drive mode.
  152. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  153. */
  154. #define __HAL_PWR_OVERDRIVE_ENABLE() (*(__IO uint32_t *) CR_ODEN_BB = ENABLE)
  155. #define __HAL_PWR_OVERDRIVE_DISABLE() (*(__IO uint32_t *) CR_ODEN_BB = DISABLE)
  156. /** @brief Macros to enable or disable the Over drive switching.
  157. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  158. */
  159. #define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = ENABLE)
  160. #define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = DISABLE)
  161. /** @brief Macros to enable or disable the Under drive mode.
  162. * @note This mode is enabled only with STOP low power mode.
  163. * In this mode, the 1.2V domain is preserved in reduced leakage mode. This
  164. * mode is only available when the main regulator or the low power regulator
  165. * is in low voltage mode.
  166. * @note If the Under-drive mode was enabled, it is automatically disabled after
  167. * exiting Stop mode.
  168. * When the voltage regulator operates in Under-drive mode, an additional
  169. * startup delay is induced when waking up from Stop mode.
  170. */
  171. #define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR |= (uint32_t)PWR_CR_UDEN)
  172. #define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR &= (uint32_t)(~PWR_CR_UDEN))
  173. /** @brief Check PWR flag is set or not.
  174. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  175. * @param __FLAG__ specifies the flag to check.
  176. * This parameter can be one of the following values:
  177. * @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode
  178. * is ready
  179. * @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode
  180. * switching is ready
  181. * @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode
  182. * is enabled in Stop mode
  183. * @retval The new state of __FLAG__ (TRUE or FALSE).
  184. */
  185. #define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
  186. /** @brief Clear the Under-Drive Ready flag.
  187. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  188. */
  189. #define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR |= PWR_FLAG_UDRDY)
  190. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  191. /**
  192. * @}
  193. */
  194. /* Exported functions --------------------------------------------------------*/
  195. /** @addtogroup PWREx_Exported_Functions PWREx Exported Functions
  196. * @{
  197. */
  198. /** @addtogroup PWREx_Exported_Functions_Group1
  199. * @{
  200. */
  201. void HAL_PWREx_EnableFlashPowerDown(void);
  202. void HAL_PWREx_DisableFlashPowerDown(void);
  203. HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void);
  204. HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void);
  205. uint32_t HAL_PWREx_GetVoltageRange(void);
  206. HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
  207. #if defined(STM32F469xx) || defined(STM32F479xx)
  208. void HAL_PWREx_EnableWakeUpPinPolarityRisingEdge(void);
  209. void HAL_PWREx_EnableWakeUpPinPolarityFallingEdge(void);
  210. #endif /* STM32F469xx || STM32F479xx */
  211. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F401xC) ||\
  212. defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) ||\
  213. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  214. void HAL_PWREx_EnableMainRegulatorLowVoltage(void);
  215. void HAL_PWREx_DisableMainRegulatorLowVoltage(void);
  216. void HAL_PWREx_EnableLowRegulatorLowVoltage(void);
  217. void HAL_PWREx_DisableLowRegulatorLowVoltage(void);
  218. #endif /* STM32F410xx || STM32F401xC || STM32F401xE || STM32F411xE || STM32F412Zx || STM32F412Vx ||\
  219. STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
  220. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) ||\
  221. defined(STM32F469xx) || defined(STM32F479xx)
  222. HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void);
  223. HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void);
  224. HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  225. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  226. /**
  227. * @}
  228. */
  229. /**
  230. * @}
  231. */
  232. /* Private types -------------------------------------------------------------*/
  233. /* Private variables ---------------------------------------------------------*/
  234. /* Private constants ---------------------------------------------------------*/
  235. /** @defgroup PWREx_Private_Constants PWREx Private Constants
  236. * @{
  237. */
  238. /** @defgroup PWREx_register_alias_address PWREx Register alias address
  239. * @{
  240. */
  241. /* ------------- PWR registers bit address in the alias region ---------------*/
  242. /* --- CR Register ---*/
  243. /* Alias word address of FPDS bit */
  244. #define FPDS_BIT_NUMBER PWR_CR_FPDS_Pos
  245. #define CR_FPDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (FPDS_BIT_NUMBER * 4U))
  246. /* Alias word address of ODEN bit */
  247. #define ODEN_BIT_NUMBER PWR_CR_ODEN_Pos
  248. #define CR_ODEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODEN_BIT_NUMBER * 4U))
  249. /* Alias word address of ODSWEN bit */
  250. #define ODSWEN_BIT_NUMBER PWR_CR_ODSWEN_Pos
  251. #define CR_ODSWEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODSWEN_BIT_NUMBER * 4U))
  252. /* Alias word address of MRLVDS bit */
  253. #define MRLVDS_BIT_NUMBER PWR_CR_MRLVDS_Pos
  254. #define CR_MRLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (MRLVDS_BIT_NUMBER * 4U))
  255. /* Alias word address of LPLVDS bit */
  256. #define LPLVDS_BIT_NUMBER PWR_CR_LPLVDS_Pos
  257. #define CR_LPLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (LPLVDS_BIT_NUMBER * 4U))
  258. /**
  259. * @}
  260. */
  261. /** @defgroup PWREx_CSR_register_alias PWRx CSR Register alias address
  262. * @{
  263. */
  264. /* --- CSR Register ---*/
  265. /* Alias word address of BRE bit */
  266. #define BRE_BIT_NUMBER PWR_CSR_BRE_Pos
  267. #define CSR_BRE_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (BRE_BIT_NUMBER * 4U))
  268. #if defined(STM32F469xx) || defined(STM32F479xx)
  269. /* Alias word address of WUPP bit */
  270. #define WUPP_BIT_NUMBER PWR_CSR_WUPP_Pos
  271. #define CSR_WUPP_BB (PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (WUPP_BIT_NUMBER * 4U))
  272. #endif /* STM32F469xx || STM32F479xx */
  273. /**
  274. * @}
  275. */
  276. /**
  277. * @}
  278. */
  279. /* Private macros ------------------------------------------------------------*/
  280. /** @defgroup PWREx_Private_Macros PWREx Private Macros
  281. * @{
  282. */
  283. /** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters
  284. * @{
  285. */
  286. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  287. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  288. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \
  289. ((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON))
  290. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  291. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
  292. #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  293. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
  294. #else
  295. #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  296. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
  297. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
  298. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  299. #if defined(STM32F446xx)
  300. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2))
  301. #elif defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) ||\
  302. defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\
  303. defined(STM32F423xx)
  304. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2) || \
  305. ((PIN) == PWR_WAKEUP_PIN3))
  306. #else
  307. #define IS_PWR_WAKEUP_PIN(PIN) ((PIN) == PWR_WAKEUP_PIN1)
  308. #endif /* STM32F446xx */
  309. /**
  310. * @}
  311. */
  312. /**
  313. * @}
  314. */
  315. /**
  316. * @}
  317. */
  318. /**
  319. * @}
  320. */
  321. #ifdef __cplusplus
  322. }
  323. #endif
  324. #endif /* __STM32F4xx_HAL_PWR_EX_H */
  325. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/