Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

345 Zeilen
16 KiB

  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.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32F4xx_HAL_PWR_EX_H
  21. #define __STM32F4xx_HAL_PWR_EX_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx_hal_def.h"
  27. /** @addtogroup STM32F4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup PWREx
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /* Exported constants --------------------------------------------------------*/
  35. /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
  36. * @{
  37. */
  38. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  39. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  40. /** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode
  41. * @{
  42. */
  43. #define PWR_MAINREGULATOR_UNDERDRIVE_ON PWR_CR_MRUDS
  44. #define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
  45. /**
  46. * @}
  47. */
  48. /** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag
  49. * @{
  50. */
  51. #define PWR_FLAG_ODRDY PWR_CSR_ODRDY
  52. #define PWR_FLAG_ODSWRDY PWR_CSR_ODSWRDY
  53. #define PWR_FLAG_UDRDY PWR_CSR_UDSWRDY
  54. /**
  55. * @}
  56. */
  57. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  58. /** @defgroup PWREx_Regulator_Voltage_Scale PWREx Regulator Voltage Scale
  59. * @{
  60. */
  61. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
  62. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS /* Scale 1 mode(default value at reset): the maximum value of fHCLK = 168 MHz. */
  63. #define PWR_REGULATOR_VOLTAGE_SCALE2 0x00000000U /* Scale 2 mode: the maximum value of fHCLK = 144 MHz. */
  64. #else
  65. #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
  66. 180 MHz by activating the over-drive mode. */
  67. #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
  68. 168 MHz by activating the over-drive mode. */
  69. #define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR_VOS_0 /* Scale 3 mode: the maximum value of fHCLK is 120 MHz. */
  70. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  71. /**
  72. * @}
  73. */
  74. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  75. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  76. /** @defgroup PWREx_WakeUp_Pins PWREx WakeUp Pins
  77. * @{
  78. */
  79. #define PWR_WAKEUP_PIN2 0x00000080U
  80. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  81. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  82. #define PWR_WAKEUP_PIN3 0x00000040U
  83. #endif /* STM32F410xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Zx || STM32F412Vx || \
  84. STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
  85. /**
  86. * @}
  87. */
  88. #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx ||
  89. STM32F413xx || STM32F423xx */
  90. /**
  91. * @}
  92. */
  93. /* Exported macro ------------------------------------------------------------*/
  94. /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
  95. * @{
  96. */
  97. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
  98. /** @brief macros configure the main internal regulator output voltage.
  99. * @param __REGULATOR__ specifies the regulator output voltage to achieve
  100. * a tradeoff between performance and power consumption when the device does
  101. * not operate at the maximum frequency (refer to the datasheets for more details).
  102. * This parameter can be one of the following values:
  103. * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
  104. * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
  105. * @retval None
  106. */
  107. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \
  108. __IO uint32_t tmpreg = 0x00U; \
  109. MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)); \
  110. /* Delay after an RCC peripheral clock enabling */ \
  111. tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS); \
  112. UNUSED(tmpreg); \
  113. } while(0U)
  114. #else
  115. /** @brief macros configure the main internal regulator output voltage.
  116. * @param __REGULATOR__ specifies the regulator output voltage to achieve
  117. * a tradeoff between performance and power consumption when the device does
  118. * not operate at the maximum frequency (refer to the datasheets for more details).
  119. * This parameter can be one of the following values:
  120. * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
  121. * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
  122. * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode
  123. * @retval None
  124. */
  125. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \
  126. __IO uint32_t tmpreg = 0x00U; \
  127. MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)); \
  128. /* Delay after an RCC peripheral clock enabling */ \
  129. tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS); \
  130. UNUSED(tmpreg); \
  131. } while(0U)
  132. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  133. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  134. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  135. /** @brief Macros to enable or disable the Over drive mode.
  136. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  137. */
  138. #define __HAL_PWR_OVERDRIVE_ENABLE() (*(__IO uint32_t *) CR_ODEN_BB = ENABLE)
  139. #define __HAL_PWR_OVERDRIVE_DISABLE() (*(__IO uint32_t *) CR_ODEN_BB = DISABLE)
  140. /** @brief Macros to enable or disable the Over drive switching.
  141. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  142. */
  143. #define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = ENABLE)
  144. #define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = DISABLE)
  145. /** @brief Macros to enable or disable the Under drive mode.
  146. * @note This mode is enabled only with STOP low power mode.
  147. * In this mode, the 1.2V domain is preserved in reduced leakage mode. This
  148. * mode is only available when the main regulator or the low power regulator
  149. * is in low voltage mode.
  150. * @note If the Under-drive mode was enabled, it is automatically disabled after
  151. * exiting Stop mode.
  152. * When the voltage regulator operates in Under-drive mode, an additional
  153. * startup delay is induced when waking up from Stop mode.
  154. */
  155. #define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR |= (uint32_t)PWR_CR_UDEN)
  156. #define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR &= (uint32_t)(~PWR_CR_UDEN))
  157. /** @brief Check PWR flag is set or not.
  158. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  159. * @param __FLAG__ specifies the flag to check.
  160. * This parameter can be one of the following values:
  161. * @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode
  162. * is ready
  163. * @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode
  164. * switching is ready
  165. * @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode
  166. * is enabled in Stop mode
  167. * @retval The new state of __FLAG__ (TRUE or FALSE).
  168. */
  169. #define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
  170. /** @brief Clear the Under-Drive Ready flag.
  171. * @note These macros can be used only for STM32F42xx/STM3243xx devices.
  172. */
  173. #define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR |= PWR_FLAG_UDRDY)
  174. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  175. /**
  176. * @}
  177. */
  178. /* Exported functions --------------------------------------------------------*/
  179. /** @addtogroup PWREx_Exported_Functions PWREx Exported Functions
  180. * @{
  181. */
  182. /** @addtogroup PWREx_Exported_Functions_Group1
  183. * @{
  184. */
  185. void HAL_PWREx_EnableFlashPowerDown(void);
  186. void HAL_PWREx_DisableFlashPowerDown(void);
  187. HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void);
  188. HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void);
  189. uint32_t HAL_PWREx_GetVoltageRange(void);
  190. HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
  191. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F401xC) ||\
  192. defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) ||\
  193. defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
  194. void HAL_PWREx_EnableMainRegulatorLowVoltage(void);
  195. void HAL_PWREx_DisableMainRegulatorLowVoltage(void);
  196. void HAL_PWREx_EnableLowRegulatorLowVoltage(void);
  197. void HAL_PWREx_DisableLowRegulatorLowVoltage(void);
  198. #endif /* STM32F410xx || STM32F401xC || STM32F401xE || STM32F411xE || STM32F412Zx || STM32F412Vx ||\
  199. STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
  200. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) ||\
  201. defined(STM32F469xx) || defined(STM32F479xx)
  202. HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void);
  203. HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void);
  204. HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  205. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  206. /**
  207. * @}
  208. */
  209. /**
  210. * @}
  211. */
  212. /* Private types -------------------------------------------------------------*/
  213. /* Private variables ---------------------------------------------------------*/
  214. /* Private constants ---------------------------------------------------------*/
  215. /** @defgroup PWREx_Private_Constants PWREx Private Constants
  216. * @{
  217. */
  218. /** @defgroup PWREx_register_alias_address PWREx Register alias address
  219. * @{
  220. */
  221. /* ------------- PWR registers bit address in the alias region ---------------*/
  222. /* --- CR Register ---*/
  223. /* Alias word address of FPDS bit */
  224. #define FPDS_BIT_NUMBER PWR_CR_FPDS_Pos
  225. #define CR_FPDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (FPDS_BIT_NUMBER * 4U))
  226. /* Alias word address of ODEN bit */
  227. #define ODEN_BIT_NUMBER PWR_CR_ODEN_Pos
  228. #define CR_ODEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODEN_BIT_NUMBER * 4U))
  229. /* Alias word address of ODSWEN bit */
  230. #define ODSWEN_BIT_NUMBER PWR_CR_ODSWEN_Pos
  231. #define CR_ODSWEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODSWEN_BIT_NUMBER * 4U))
  232. /* Alias word address of MRLVDS bit */
  233. #define MRLVDS_BIT_NUMBER PWR_CR_MRLVDS_Pos
  234. #define CR_MRLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (MRLVDS_BIT_NUMBER * 4U))
  235. /* Alias word address of LPLVDS bit */
  236. #define LPLVDS_BIT_NUMBER PWR_CR_LPLVDS_Pos
  237. #define CR_LPLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (LPLVDS_BIT_NUMBER * 4U))
  238. /**
  239. * @}
  240. */
  241. /** @defgroup PWREx_CSR_register_alias PWRx CSR Register alias address
  242. * @{
  243. */
  244. /* --- CSR Register ---*/
  245. /* Alias word address of BRE bit */
  246. #define BRE_BIT_NUMBER PWR_CSR_BRE_Pos
  247. #define CSR_BRE_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (BRE_BIT_NUMBER * 4U))
  248. /**
  249. * @}
  250. */
  251. /**
  252. * @}
  253. */
  254. /* Private macros ------------------------------------------------------------*/
  255. /** @defgroup PWREx_Private_Macros PWREx Private Macros
  256. * @{
  257. */
  258. /** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters
  259. * @{
  260. */
  261. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  262. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  263. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \
  264. ((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON))
  265. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  266. #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
  267. #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  268. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
  269. #else
  270. #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  271. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
  272. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
  273. #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */
  274. #if defined(STM32F446xx)
  275. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2))
  276. #elif defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) ||\
  277. defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\
  278. defined(STM32F423xx)
  279. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2) || \
  280. ((PIN) == PWR_WAKEUP_PIN3))
  281. #else
  282. #define IS_PWR_WAKEUP_PIN(PIN) ((PIN) == PWR_WAKEUP_PIN1)
  283. #endif /* STM32F446xx */
  284. /**
  285. * @}
  286. */
  287. /**
  288. * @}
  289. */
  290. /**
  291. * @}
  292. */
  293. /**
  294. * @}
  295. */
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299. #endif /* __STM32F4xx_HAL_PWR_EX_H */
  300. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/