py32f002b_hal_pwr.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_hal_pwr.h
  4. * @author MCU Application Team
  5. * @brief Header file of PWR HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya 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. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F002B_HAL_PWR_H
  32. #define __PY32F002B_HAL_PWR_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f002b_hal_def.h"
  38. /** @addtogroup PY32F002B_HAL_Driver
  39. * @{
  40. */
  41. /** @defgroup PWR PWR
  42. * @brief PWR HAL module driver
  43. * @{
  44. */
  45. /* Exported types ------------------------------------------------------------*/
  46. /** @defgroup PWR_Exported_Types PWR Exported Types
  47. * @{
  48. */
  49. /**
  50. * @brief PWR Stop configuration structure definition
  51. */
  52. typedef struct
  53. {
  54. uint32_t WakeUpHsiEnableTime; /*!< WakeUpHsiEnableTime: Set the flash delay time after wake up.
  55. This parameter can be a value of @ref PWR_STOP_WakeUp_HSIEN_Timing. */
  56. #if defined(PWR_DEEPSTOP_SUPPORT)
  57. uint32_t SramRetentionVoltDlp; /*!< SramRetentionVolt: Set the SRAM retention voltage in deep stop mode.
  58. This parameter can be a value of @ref PWR_SRAM_RETENTIONE_VOLTAGE_CONTROL. */
  59. #endif /* PWR_DEEPSTOP_SUPPORT */
  60. uint32_t SramRetentionVolt; /*!< SramRetentionVolt: Set the SRAM retention voltage in stop mode.
  61. This parameter can be a value of @ref PWR_SRAM_RETENTIONE_VOLTAGE_CONTROL. */
  62. uint32_t FlashDelay; /*!< FlsahDelay: Set the flash delay time after wake up.
  63. This parameter can be a value of @ref PWR_STOP_WakeUp_Flash_Delay. */
  64. } PWR_StopModeConfigTypeDef;
  65. /**
  66. * @brief PWR BIAS configuration structure definition
  67. */
  68. typedef struct
  69. {
  70. uint32_t BiasCurrentSource; /*!< BiasCurrentSource: Set the bias currents load source.
  71. This parameter can be a value of @ref PWR_MR_BiasCurrent_Source. */
  72. uint32_t BiasCurrentValue; /*!< BiasCurrentValue: Set the bias currents config value.
  73. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF. */
  74. } PWR_BIASConfigTypeDef;
  75. /**
  76. * @}
  77. */
  78. /* Exported constants --------------------------------------------------------*/
  79. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  80. * @{
  81. */
  82. /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode
  83. * @{
  84. */
  85. #define PWR_MAINREGULATOR_ON (0x00000000u) /*!< Regulator in main mode */
  86. #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR_0 /*!< Regulator in low-power mode */
  87. #if defined(PWR_DEEPSTOP_SUPPORT)
  88. #define PWR_DEEPLOWPOWERREGULATOR_ON PWR_CR1_LPR_1 /*!< Regulator in deep-low-power mode */
  89. #endif /* PWR_DEEPSTOP_SUPPORT */
  90. /**
  91. * @}
  92. */
  93. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  94. * @{
  95. */
  96. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01u) /*!< Wait For Interruption instruction to enter Sleep mode */
  97. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02u) /*!< Wait For Event instruction to enter Sleep mode */
  98. /**
  99. * @}
  100. */
  101. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  102. * @{
  103. */
  104. #define PWR_STOPENTRY_WFI ((uint8_t)0x01u) /*!< Wait For Interruption instruction to enter Stop mode */
  105. #define PWR_STOPENTRY_WFE ((uint8_t)0x02u) /*!< Wait For Event instruction to enter Stop mode */
  106. /**
  107. * @}
  108. */
  109. /** @defgroup PWR_STOP_WakeUp_HSIEN_Timing PWR STOP mode WakeUp HSI Enable Timing.
  110. * @{
  111. */
  112. #define PWR_WAKEUP_HSIEN_AFTER_MR 0x00000000U /* Wake up from the STOP mode, After the MR becomes stable, enable HSI */
  113. #define PWR_WAKEUP_HSIEN_IMMEDIATE PWR_CR1_HSION_CTRL /* Wake up from the STOP mode, Enable HSI immediately */
  114. /**
  115. * @}
  116. */
  117. /** @defgroup PWR_SRAM_RETENTIONE_VOLTAGE_CONTROL SRAM RETENTIONE VOLTAGE CONTROL
  118. * @{
  119. */
  120. #define PWR_SRAM_RETENTION_VOLT_CTRL_LDO 0x00000001U /* SRAM voltage is the same as LDO output. */
  121. #define PWR_SRAM_RETENTION_VOLT_CTRL_LOW 0x00000000U /* SRAM voltage is low. */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup PWR_STOP_WakeUp_Flash_Delay PWR STOP WakeUp Flash Delay.
  126. * @{
  127. */
  128. #define PWR_WAKEUP_FLASH_DELAY_0US (PWR_CR1_FLS_SLPTIME_1 | PWR_CR1_FLS_SLPTIME_0) /* Wake up from the STOP mode, Enable falsh immediately*/
  129. #define PWR_WAKEUP_FLASH_DELAY_2US ( PWR_CR1_FLS_SLPTIME_0) /* Wake up from the STOP mode, Delay 2us enable falsh*/
  130. #define PWR_WAKEUP_FLASH_DELAY_3US (PWR_CR1_FLS_SLPTIME_1 ) /* Wake up from the STOP mode, Delay 3us enable falsh*/
  131. #define PWR_WAKEUP_FLASH_DELAY_5US 0x00000000U /* Wake up from the STOP mode, Delay 5us enable falsh*/
  132. /**
  133. * @}
  134. */
  135. /** @defgroup PWR_MR_BiasCurrent_Source PWR MainRegulator BiasCurrent Source.
  136. * @{
  137. */
  138. #define PWR_BIAS_CURRENTS_FROM_FACTORY_BYTES 0x00000000U /* MR bias currents source load from Factory config bytes */
  139. #define PWR_BIAS_CURRENTS_FROM_BIAS_CR (PWR_CR1_BIAS_CR_SEL) /* MR bias currents source load from BIAS_CR */
  140. /**
  141. * @}
  142. */
  143. /**
  144. * @}
  145. */
  146. /* Exported macros -----------------------------------------------------------*/
  147. /** @defgroup PWR_Exported_Macros PWR Exported Macros
  148. * @{
  149. */
  150. /**
  151. * @}
  152. */
  153. /* Private macros --------------------------------------------------------*/
  154. /** @defgroup PWR_Private_Macros PWR Private Macros
  155. * @{
  156. */
  157. #if defined(PWR_DEEPSTOP_SUPPORT)
  158. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  159. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON) || \
  160. ((REGULATOR) == PWR_DEEPLOWPOWERREGULATOR_ON))
  161. #else
  162. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  163. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  164. #endif /* PWR_DEEPSTOP_SUPPORT */
  165. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || \
  166. ((ENTRY) == PWR_SLEEPENTRY_WFE))
  167. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || \
  168. ((ENTRY) == PWR_STOPENTRY_WFE))
  169. #define IS_PWR_WAKEUP_HSIEN_TIMING(TIMING) (((TIMING) == PWR_WAKEUP_HSIEN_AFTER_MR) || \
  170. ((TIMING) == PWR_WAKEUP_HSIEN_IMMEDIATE))
  171. #define IS_PWR_SRAM_RETENTION_VOLT(VOLT) (((VOLT) == PWR_SRAM_RETENTION_VOLT_CTRL_LDO) || \
  172. ((VOLT) == PWR_SRAM_RETENTION_VOLT_CTRL_LOW))
  173. #define IS_PWR_WAKEUP_FLASH_DELAY(DELAY) (((DELAY) == PWR_WAKEUP_FLASH_DELAY_0US) || \
  174. ((DELAY) == PWR_WAKEUP_FLASH_DELAY_2US) || \
  175. ((DELAY) == PWR_WAKEUP_FLASH_DELAY_3US) || \
  176. ((DELAY) == PWR_WAKEUP_FLASH_DELAY_5US))
  177. #define IS_BIAS_CURRENTS_SOURCE(SOURCE) (((SOURCE) == PWR_BIAS_CURRENTS_FROM_FACTORY_BYTES) || \
  178. ((SOURCE) == PWR_BIAS_CURRENTS_FROM_BIAS_CR))
  179. /**
  180. * @}
  181. */
  182. /* Include PWR HAL Extended module */
  183. /* Exported functions --------------------------------------------------------*/
  184. /** @defgroup PWR_Exported_Functions PWR Exported Functions
  185. * @{
  186. */
  187. /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  188. * @{
  189. */
  190. /* Initialization and de-initialization functions *******************************/
  191. void HAL_PWR_DeInit(void);
  192. /**
  193. * @}
  194. */
  195. /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions
  196. * @{
  197. */
  198. /* Peripheral Control functions ************************************************/
  199. HAL_StatusTypeDef HAL_PWR_ConfigStopMode(PWR_StopModeConfigTypeDef *sStopModeConfig);
  200. HAL_StatusTypeDef HAL_PWR_ConfigBIAS(PWR_BIASConfigTypeDef *sBIASConfig);
  201. /* Low Power modes configuration functions ************************************/
  202. void HAL_PWR_EnterSLEEPMode(uint8_t SLEEPEntry);
  203. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  204. void HAL_PWR_EnableSleepOnExit(void);
  205. void HAL_PWR_DisableSleepOnExit(void);
  206. void HAL_PWR_EnableSEVOnPend(void);
  207. void HAL_PWR_DisableSEVOnPend(void);
  208. /**
  209. * @}
  210. */
  211. /**
  212. * @}
  213. */
  214. /**
  215. * @}
  216. */
  217. /**
  218. * @}
  219. */
  220. #ifdef __cplusplus
  221. }
  222. #endif
  223. #endif /* __PY32F002B_HAL_PWR_H */
  224. /************************ (C) COPYRIGHT Puya *****END OF FILE****/