stm32h7xx_hal_pwr_ex.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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 PWR extension peripheral:
  8. * + Peripheral Extended features functions
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * Copyright (c) 2017 STMicroelectronics.
  13. * All rights reserved.
  14. *
  15. * This software is licensed under terms that can be found in the LICENSE file
  16. * in the root directory of this software component.
  17. * If no LICENSE file comes with this software, it is provided AS-IS.
  18. *
  19. ******************************************************************************
  20. @verbatim
  21. ==============================================================================
  22. ##### How to use this driver #####
  23. ==============================================================================
  24. [..]
  25. (#) Call HAL_PWREx_ConfigSupply() function to configure the regulator supply
  26. with the following different setups according to hardware (support SMPS):
  27. (+) PWR_DIRECT_SMPS_SUPPLY
  28. (+) PWR_SMPS_1V8_SUPPLIES_LDO
  29. (+) PWR_SMPS_2V5_SUPPLIES_LDO
  30. (+) PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO
  31. (+) PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO
  32. (+) PWR_SMPS_1V8_SUPPLIES_EXT
  33. (+) PWR_SMPS_2V5_SUPPLIES_EXT
  34. (+) PWR_LDO_SUPPLY
  35. (+) PWR_EXTERNAL_SOURCE_SUPPLY
  36. (#) Call HAL_PWREx_GetSupplyConfig() function to get the current supply setup.
  37. (#) Call HAL_PWREx_ControlVoltageScaling() function to configure the main
  38. internal regulator output voltage. The voltage scaling could be one of
  39. the following scales :
  40. (+) PWR_REGULATOR_VOLTAGE_SCALE0
  41. (+) PWR_REGULATOR_VOLTAGE_SCALE1
  42. (+) PWR_REGULATOR_VOLTAGE_SCALE2
  43. (+) PWR_REGULATOR_VOLTAGE_SCALE3
  44. (#) Call HAL_PWREx_GetVoltageRange() function to get the current output
  45. voltage applied to the main regulator.
  46. (#) Call HAL_PWREx_ControlStopModeVoltageScaling() function to configure the
  47. main internal regulator output voltage in STOP mode. The voltage scaling
  48. in STOP mode could be one of the following scales :
  49. (+) PWR_REGULATOR_SVOS_SCALE3
  50. (+) PWR_REGULATOR_SVOS_SCALE4
  51. (+) PWR_REGULATOR_SVOS_SCALE5
  52. (#) Call HAL_PWREx_GetStopModeVoltageRange() function to get the current
  53. output voltage applied to the main regulator in STOP mode.
  54. (#) Call HAL_PWREx_EnterSTOP2Mode() function to enter the system in STOP mode
  55. with core domain in D2STOP mode. This API is used only for STM32H7Axxx
  56. and STM32H7Bxxx devices.
  57. Please ensure to clear all CPU pending events by calling
  58. HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx
  59. in DEEP-SLEEP mode with __WFE() entry.
  60. (#) Call HAL_PWREx_EnterSTOPMode() function to enter the selected domain in
  61. DSTOP mode. Call this API with all available power domains to enter the
  62. system in STOP mode.
  63. Please ensure to clear all CPU pending events by calling
  64. HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx
  65. in DEEP-SLEEP mode with __WFE() entry.
  66. (#) Call HAL_PWREx_ClearPendingEvent() function always before entring the
  67. Cortex-Mx in any low power mode (SLEEP/DEEP-SLEEP) using WFE entry.
  68. (#) Call HAL_PWREx_EnterSTANDBYMode() function to enter the selected domain
  69. in DSTANDBY mode. Call this API with all available power domains to enter
  70. the system in STANDBY mode.
  71. (#) Call HAL_PWREx_ConfigD3Domain() function to setup the D3/SRD domain state
  72. (RUN/STOP) when the system enter to low power mode.
  73. (#) Call HAL_PWREx_ClearDomainFlags() function to clear the CPU flags for the
  74. selected power domain. This API is used only for dual core devices.
  75. (#) Call HAL_PWREx_HoldCore() and HAL_PWREx_ReleaseCore() functions to hold
  76. and release the selected CPU and and their domain peripherals when
  77. exiting STOP mode. These APIs are used only for dual core devices.
  78. (#) Call HAL_PWREx_EnableFlashPowerDown() and
  79. HAL_PWREx_DisableFlashPowerDown() functions to enable and disable the
  80. Flash Power Down in STOP mode.
  81. (#) Call HAL_PWREx_EnableMemoryShutOff() and
  82. HAL_PWREx_DisableMemoryShutOff() functions to enable and disable the
  83. memory block shut-off in DStop or DStop2. These APIs are used only for
  84. STM32H7Axxx and STM32H7Bxxx lines.
  85. (#) Call HAL_PWREx_EnableWakeUpPin() and HAL_PWREx_DisableWakeUpPin()
  86. functions to enable and disable the Wake-up pin functionality for
  87. the selected pin.
  88. (#) Call HAL_PWREx_GetWakeupFlag() and HAL_PWREx_ClearWakeupFlag()
  89. functions to manage wake-up flag for the selected pin.
  90. (#) Call HAL_PWREx_WAKEUP_PIN_IRQHandler() function to handle all wake-up
  91. pins interrupts.
  92. (#) Call HAL_PWREx_EnableBkUpReg() and HAL_PWREx_DisableBkUpReg() functions
  93. to enable and disable the backup domain regulator.
  94. (#) Call HAL_PWREx_EnableUSBReg(), HAL_PWREx_DisableUSBReg(),
  95. HAL_PWREx_EnableUSBVoltageDetector() and
  96. HAL_PWREx_DisableUSBVoltageDetector() functions to manage USB power
  97. regulation functionalities.
  98. (#) Call HAL_PWREx_EnableBatteryCharging() and
  99. HAL_PWREx_DisableBatteryCharging() functions to enable and disable the
  100. battery charging feature with the selected resistor.
  101. (#) Call HAL_PWREx_EnableAnalogBooster() and
  102. HAL_PWREx_DisableAnalogBooster() functions to enable and disable the
  103. AVD boost feature when the VDD supply voltage is below 2V7.
  104. (#) Call HAL_PWREx_EnableMonitoring() and HAL_PWREx_DisableMonitoring()
  105. functions to enable and disable the VBAT and Temperature monitoring.
  106. When VBAT and Temperature monitoring feature is enables, use
  107. HAL_PWREx_GetTemperatureLevel() and HAL_PWREx_GetVBATLevel() to get
  108. respectively the Temperature level and VBAT level.
  109. (#) Call HAL_PWREx_GetMMCVoltage() and HAL_PWREx_DisableMonitoring()
  110. function to get VDDMMC voltage level. This API is used only for
  111. STM32H7Axxx and STM32H7Bxxx lines
  112. (#) Call HAL_PWREx_ConfigAVD() after setting parameter to be configured
  113. (event mode and voltage threshold) in order to set up the Analog Voltage
  114. Detector then use HAL_PWREx_EnableAVD() and HAL_PWREx_DisableAVD()
  115. functions to start and stop the AVD detection.
  116. (+) AVD level could be one of the following values :
  117. (++) 1V7
  118. (++) 2V1
  119. (++) 2V5
  120. (++) 2V8
  121. (#) Call HAL_PWREx_PVD_AVD_IRQHandler() function to handle the PWR PVD and
  122. AVD interrupt request.
  123. @endverbatim
  124. */
  125. /* Includes ------------------------------------------------------------------*/
  126. #include "stm32h7xx_hal.h"
  127. /** @addtogroup STM32H7xx_HAL_Driver
  128. * @{
  129. */
  130. /** @defgroup PWREx PWREx
  131. * @brief PWR Extended HAL module driver
  132. * @{
  133. */
  134. #ifdef HAL_PWR_MODULE_ENABLED
  135. /* Private typedef -----------------------------------------------------------*/
  136. /* Private define ------------------------------------------------------------*/
  137. /** @addtogroup PWREx_Private_Constants
  138. * @{
  139. */
  140. /** @defgroup PWREx_AVD_Mode_Mask PWR Extended AVD Mode Mask
  141. * @{
  142. */
  143. #define AVD_MODE_IT (0x00010000U)
  144. #define AVD_MODE_EVT (0x00020000U)
  145. #define AVD_RISING_EDGE (0x00000001U)
  146. #define AVD_FALLING_EDGE (0x00000002U)
  147. #define AVD_RISING_FALLING_EDGE (0x00000003U)
  148. /**
  149. * @}
  150. */
  151. /** @defgroup PWREx_REG_SET_TIMEOUT PWR Extended Flag Setting Time Out Value
  152. * @{
  153. */
  154. #define PWR_FLAG_SETTING_DELAY (1000U)
  155. /**
  156. * @}
  157. */
  158. /** @defgroup PWREx_WakeUp_Pins_Offsets PWREx Wake-Up Pins masks and offsets
  159. * @{
  160. */
  161. /* Wake-Up Pins EXTI register mask */
  162. #if defined (EXTI_IMR2_IM57)
  163. #define PWR_EXTI_WAKEUP_PINS_MASK (EXTI_IMR2_IM55 | EXTI_IMR2_IM56 |\
  164. EXTI_IMR2_IM57 | EXTI_IMR2_IM58 |\
  165. EXTI_IMR2_IM59 | EXTI_IMR2_IM60)
  166. #else
  167. #define PWR_EXTI_WAKEUP_PINS_MASK (EXTI_IMR2_IM55 | EXTI_IMR2_IM56 |\
  168. EXTI_IMR2_IM58 | EXTI_IMR2_IM60)
  169. #endif /* defined (EXTI_IMR2_IM57) */
  170. /* Wake-Up Pins PWR Pin Pull shift offsets */
  171. #define PWR_WAKEUP_PINS_PULL_SHIFT_OFFSET (2U)
  172. /**
  173. * @}
  174. */
  175. /**
  176. * @}
  177. */
  178. /* Private macro -------------------------------------------------------------*/
  179. /* Private variables ---------------------------------------------------------*/
  180. /* Private function prototypes -----------------------------------------------*/
  181. /* Private functions ---------------------------------------------------------*/
  182. /* Exported types ------------------------------------------------------------*/
  183. /* Exported functions --------------------------------------------------------*/
  184. /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
  185. * @{
  186. */
  187. /** @defgroup PWREx_Exported_Functions_Group1 Power Supply Control Functions
  188. * @brief Power supply control functions
  189. *
  190. @verbatim
  191. ===============================================================================
  192. ##### Power supply control functions #####
  193. ===============================================================================
  194. [..]
  195. (#) When the system is powered on, the POR monitors VDD supply. Once VDD is
  196. above the POR threshold level, the voltage regulator is enabled in the
  197. default supply configuration:
  198. (+) The Voltage converter output level is set at 1V0 in accordance with
  199. the VOS3 level configured in PWR (D3/SRD) domain control register
  200. (PWR_D3CR/PWR_SRDCR).
  201. (+) The system is kept in reset mode as long as VCORE is not ok.
  202. (+) Once VCORE is ok, the system is taken out of reset and the HSI
  203. oscillator is enabled.
  204. (+) Once the oscillator is stable, the system is initialized: Flash memory
  205. and option bytes are loaded and the CPU starts in Run* mode.
  206. (+) The software shall then initialize the system including supply
  207. configuration programming using the HAL_PWREx_ConfigSupply().
  208. (+) Once the supply configuration has been configured, the
  209. HAL_PWREx_ConfigSupply() function checks the ACTVOSRDY bit in PWR
  210. control status register 1 (PWR_CSR1) to guarantee a valid voltage
  211. levels:
  212. (++) As long as ACTVOSRDY indicates that voltage levels are invalid, the
  213. system is in limited Run* mode, write accesses to the RAMs are not
  214. permitted and VOS shall not be changed.
  215. (++) Once ACTVOSRDY indicates that voltage levels are valid, the system
  216. is in normal Run mode, write accesses to RAMs are allowed and VOS
  217. can be changed.
  218. @endverbatim
  219. * @{
  220. */
  221. /**
  222. * @brief Configure the system Power Supply.
  223. * @param SupplySource : Specifies the Power Supply source to set after a
  224. * system startup.
  225. * This parameter can be one of the following values :
  226. * @arg PWR_DIRECT_SMPS_SUPPLY : The SMPS supplies the Vcore Power
  227. * Domains. The LDO is Bypassed.
  228. * @arg PWR_SMPS_1V8_SUPPLIES_LDO : The SMPS 1.8V output supplies
  229. * the LDO. The Vcore Power Domains
  230. * are supplied from the LDO.
  231. * @arg PWR_SMPS_2V5_SUPPLIES_LDO : The SMPS 2.5V output supplies
  232. * the LDO. The Vcore Power Domains
  233. * are supplied from the LDO.
  234. * @arg PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO : The SMPS 1.8V output
  235. * supplies external
  236. * circuits and the LDO.
  237. * The Vcore Power Domains
  238. * are supplied from the
  239. * LDO.
  240. * @arg PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO : The SMPS 2.5V output
  241. * supplies external
  242. * circuits and the LDO.
  243. * The Vcore Power Domains
  244. * are supplied from the
  245. * LDO.
  246. * @arg PWR_SMPS_1V8_SUPPLIES_EXT : The SMPS 1.8V output supplies
  247. * external circuits. The LDO is
  248. * Bypassed. The Vcore Power
  249. * Domains are supplied from
  250. * external source.
  251. * @arg PWR_SMPS_2V5_SUPPLIES_EXT : The SMPS 2.5V output supplies
  252. * external circuits. The LDO is
  253. * Bypassed. The Vcore Power
  254. * Domains are supplied from
  255. * external source.
  256. * @arg PWR_LDO_SUPPLY : The LDO regulator supplies the Vcore Power
  257. * Domains. The SMPS regulator is Bypassed.
  258. * @arg PWR_EXTERNAL_SOURCE_SUPPLY : The SMPS and the LDO are
  259. * Bypassed. The Vcore Power
  260. * Domains are supplied from
  261. * external source.
  262. * @note The PWR_LDO_SUPPLY and PWR_EXTERNAL_SOURCE_SUPPLY are used by all
  263. * H7 lines.
  264. * The PWR_DIRECT_SMPS_SUPPLY, PWR_SMPS_1V8_SUPPLIES_LDO,
  265. * PWR_SMPS_2V5_SUPPLIES_LDO, PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO,
  266. * PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO, PWR_SMPS_1V8_SUPPLIES_EXT and
  267. * PWR_SMPS_2V5_SUPPLIES_EXT are used only for lines that supports SMPS
  268. * regulator.
  269. * @retval HAL status.
  270. */
  271. HAL_StatusTypeDef HAL_PWREx_ConfigSupply (uint32_t SupplySource)
  272. {
  273. uint32_t tickstart;
  274. /* Check the parameters */
  275. assert_param (IS_PWR_SUPPLY (SupplySource));
  276. /* Check if supply source was configured */
  277. #if defined (PWR_FLAG_SCUEN)
  278. if (__HAL_PWR_GET_FLAG (PWR_FLAG_SCUEN) == 0U)
  279. #else
  280. if ((PWR->CR3 & (PWR_CR3_SMPSEN | PWR_CR3_LDOEN | PWR_CR3_BYPASS)) != (PWR_CR3_SMPSEN | PWR_CR3_LDOEN))
  281. #endif /* defined (PWR_FLAG_SCUEN) */
  282. {
  283. /* Check supply configuration */
  284. if ((PWR->CR3 & PWR_SUPPLY_CONFIG_MASK) != SupplySource)
  285. {
  286. /* Supply configuration update locked, can't apply a new supply config */
  287. return HAL_ERROR;
  288. }
  289. else
  290. {
  291. /* Supply configuration update locked, but new supply configuration
  292. matches with old supply configuration : nothing to do
  293. */
  294. return HAL_OK;
  295. }
  296. }
  297. /* Set the power supply configuration */
  298. MODIFY_REG (PWR->CR3, PWR_SUPPLY_CONFIG_MASK, SupplySource);
  299. /* Get tick */
  300. tickstart = HAL_GetTick ();
  301. /* Wait till voltage level flag is set */
  302. while (__HAL_PWR_GET_FLAG (PWR_FLAG_ACTVOSRDY) == 0U)
  303. {
  304. if ((HAL_GetTick () - tickstart) > PWR_FLAG_SETTING_DELAY)
  305. {
  306. return HAL_ERROR;
  307. }
  308. }
  309. #if defined (SMPS)
  310. /* When the SMPS supplies external circuits verify that SDEXTRDY flag is set */
  311. if ((SupplySource == PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO) ||
  312. (SupplySource == PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO) ||
  313. (SupplySource == PWR_SMPS_1V8_SUPPLIES_EXT) ||
  314. (SupplySource == PWR_SMPS_2V5_SUPPLIES_EXT))
  315. {
  316. /* Get the current tick number */
  317. tickstart = HAL_GetTick ();
  318. /* Wait till SMPS external supply ready flag is set */
  319. while (__HAL_PWR_GET_FLAG (PWR_FLAG_SMPSEXTRDY) == 0U)
  320. {
  321. if ((HAL_GetTick () - tickstart) > PWR_FLAG_SETTING_DELAY)
  322. {
  323. return HAL_ERROR;
  324. }
  325. }
  326. }
  327. #endif /* defined (SMPS) */
  328. return HAL_OK;
  329. }
  330. /**
  331. * @brief Get the power supply configuration.
  332. * @retval The supply configuration.
  333. */
  334. uint32_t HAL_PWREx_GetSupplyConfig (void)
  335. {
  336. return (PWR->CR3 & PWR_SUPPLY_CONFIG_MASK);
  337. }
  338. /**
  339. * @brief Configure the main internal regulator output voltage.
  340. * @param VoltageScaling : Specifies the regulator output voltage to achieve
  341. * a tradeoff between performance and power
  342. * consumption.
  343. * This parameter can be one of the following values :
  344. * @arg PWR_REGULATOR_VOLTAGE_SCALE0 : Regulator voltage output
  345. * Scale 0 mode.
  346. * @arg PWR_REGULATOR_VOLTAGE_SCALE1 : Regulator voltage output
  347. * range 1 mode.
  348. * @arg PWR_REGULATOR_VOLTAGE_SCALE2 : Regulator voltage output
  349. * range 2 mode.
  350. * @arg PWR_REGULATOR_VOLTAGE_SCALE3 : Regulator voltage output
  351. * range 3 mode.
  352. * @note For STM32H74x and STM32H75x lines, configuring Voltage Scale 0 is
  353. * only possible when Vcore is supplied from LDO (Low DropOut). The
  354. * SYSCFG Clock must be enabled through __HAL_RCC_SYSCFG_CLK_ENABLE()
  355. * macro before configuring Voltage Scale 0.
  356. * To enter low power mode , and if current regulator voltage is
  357. * Voltage Scale 0 then first switch to Voltage Scale 1 before entering
  358. * low power mode.
  359. * @retval HAL Status
  360. */
  361. HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling (uint32_t VoltageScaling)
  362. {
  363. uint32_t tickstart;
  364. /* Check the parameters */
  365. assert_param (IS_PWR_REGULATOR_VOLTAGE (VoltageScaling));
  366. /* Get the voltage scaling */
  367. if ((PWR->CSR1 & PWR_CSR1_ACTVOS) == VoltageScaling)
  368. {
  369. /* Old and new voltage scaling configuration match : nothing to do */
  370. return HAL_OK;
  371. }
  372. #if defined (PWR_SRDCR_VOS)
  373. /* Set the voltage range */
  374. MODIFY_REG (PWR->SRDCR, PWR_SRDCR_VOS, VoltageScaling);
  375. #else
  376. #if defined(SYSCFG_PWRCR_ODEN) /* STM32H74xxx and STM32H75xxx lines */
  377. if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE0)
  378. {
  379. if ((PWR->CR3 & PWR_CR3_LDOEN) == PWR_CR3_LDOEN)
  380. {
  381. /* Set the voltage range */
  382. MODIFY_REG (PWR->D3CR, PWR_D3CR_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
  383. /* Get tick */
  384. tickstart = HAL_GetTick ();
  385. /* Wait till voltage level flag is set */
  386. while (__HAL_PWR_GET_FLAG (PWR_FLAG_ACTVOSRDY) == 0U)
  387. {
  388. if ((HAL_GetTick () - tickstart) > PWR_FLAG_SETTING_DELAY)
  389. {
  390. return HAL_ERROR;
  391. }
  392. }
  393. /* Enable the PWR overdrive */
  394. SET_BIT (SYSCFG->PWRCR, SYSCFG_PWRCR_ODEN);
  395. }
  396. else
  397. {
  398. /* The voltage scale 0 is only possible when LDO regulator is enabled */
  399. return HAL_ERROR;
  400. }
  401. }
  402. else
  403. {
  404. if ((PWR->CSR1 & PWR_CSR1_ACTVOS) == PWR_REGULATOR_VOLTAGE_SCALE1)
  405. {
  406. if ((SYSCFG->PWRCR & SYSCFG_PWRCR_ODEN) != 0U)
  407. {
  408. /* Disable the PWR overdrive */
  409. CLEAR_BIT(SYSCFG->PWRCR, SYSCFG_PWRCR_ODEN);
  410. /* Get tick */
  411. tickstart = HAL_GetTick ();
  412. /* Wait till voltage level flag is set */
  413. while (__HAL_PWR_GET_FLAG (PWR_FLAG_ACTVOSRDY) == 0U)
  414. {
  415. if ((HAL_GetTick () - tickstart) > PWR_FLAG_SETTING_DELAY)
  416. {
  417. return HAL_ERROR;
  418. }
  419. }
  420. }
  421. }
  422. /* Set the voltage range */
  423. MODIFY_REG (PWR->D3CR, PWR_D3CR_VOS, VoltageScaling);
  424. }
  425. #else /* STM32H72xxx and STM32H73xxx lines */
  426. /* Set the voltage range */
  427. MODIFY_REG(PWR->D3CR, PWR_D3CR_VOS, VoltageScaling);
  428. #endif /* defined (SYSCFG_PWRCR_ODEN) */
  429. #endif /* defined (PWR_SRDCR_VOS) */
  430. /* Get tick */
  431. tickstart = HAL_GetTick ();
  432. /* Wait till voltage level flag is set */
  433. while (__HAL_PWR_GET_FLAG (PWR_FLAG_ACTVOSRDY) == 0U)
  434. {
  435. if ((HAL_GetTick() - tickstart) > PWR_FLAG_SETTING_DELAY)
  436. {
  437. return HAL_ERROR;
  438. }
  439. }
  440. return HAL_OK;
  441. }
  442. /**
  443. * @brief Get the main internal regulator output voltage. Reflecting the last
  444. * VOS value applied to the PMU.
  445. * @retval The current applied VOS selection.
  446. */
  447. uint32_t HAL_PWREx_GetVoltageRange (void)
  448. {
  449. /* Get the active voltage scaling */
  450. return (PWR->CSR1 & PWR_CSR1_ACTVOS);
  451. }
  452. /**
  453. * @brief Configure the main internal regulator output voltage in STOP mode.
  454. * @param VoltageScaling : Specifies the regulator output voltage when the
  455. * system enters Stop mode to achieve a tradeoff between performance
  456. * and power consumption.
  457. * This parameter can be one of the following values:
  458. * @arg PWR_REGULATOR_SVOS_SCALE3 : Regulator voltage output range
  459. * 3 mode.
  460. * @arg PWR_REGULATOR_SVOS_SCALE4 : Regulator voltage output range
  461. * 4 mode.
  462. * @arg PWR_REGULATOR_SVOS_SCALE5 : Regulator voltage output range
  463. * 5 mode.
  464. * @note The Stop mode voltage scaling for SVOS4 and SVOS5 sets the voltage
  465. * regulator in Low-power (LP) mode to further reduce power consumption.
  466. * When preselecting SVOS3, the use of the voltage regulator low-power
  467. * mode (LP) can be selected by LPDS register bit.
  468. * @note The selected SVOS4 and SVOS5 levels add an additional startup delay
  469. * when exiting from system Stop mode.
  470. * @retval HAL Status.
  471. */
  472. HAL_StatusTypeDef HAL_PWREx_ControlStopModeVoltageScaling (uint32_t VoltageScaling)
  473. {
  474. /* Check the parameters */
  475. assert_param (IS_PWR_STOP_MODE_REGULATOR_VOLTAGE (VoltageScaling));
  476. /* Return the stop mode voltage range */
  477. MODIFY_REG (PWR->CR1, PWR_CR1_SVOS, VoltageScaling);
  478. return HAL_OK;
  479. }
  480. /**
  481. * @brief Get the main internal regulator output voltage in STOP mode.
  482. * @retval The actual applied VOS selection.
  483. */
  484. uint32_t HAL_PWREx_GetStopModeVoltageRange (void)
  485. {
  486. /* Return the stop voltage scaling */
  487. return (PWR->CR1 & PWR_CR1_SVOS);
  488. }
  489. /**
  490. * @}
  491. */
  492. /** @defgroup PWREx_Exported_Functions_Group2 Low Power Control Functions
  493. * @brief Low power control functions
  494. *
  495. @verbatim
  496. ===============================================================================
  497. ##### Low power control functions #####
  498. ===============================================================================
  499. *** Domains Low Power modes configuration ***
  500. =============================================
  501. [..]
  502. This section provides the extended low power mode control APIs.
  503. The system presents 3 principles domains (D1, D2 and D3) that can be
  504. operated in low-power modes (DSTOP or DSTANDBY mode):
  505. (+) DSTOP mode to enters a domain to STOP mode:
  506. (++) D1 domain and/or D2 domain enters DSTOP mode only when the CPU
  507. subsystem is in CSTOP mode and has allocated peripheral in the
  508. domain.
  509. In DSTOP mode the domain bus matrix clock is stopped.
  510. (++) The system enters STOP mode using one of the following scenarios:
  511. (+++) D1 domain enters DSTANDBY mode (powered off) and D2, D3 domains
  512. enter DSTOP mode.
  513. (+++) D2 domain enters DSTANDBY mode (powered off) and D1, D3 domains
  514. enter DSTOP mode.
  515. (+++) D3 domain enters DSTANDBY mode (powered off) and D1, D2 domains
  516. enter DSTOP mode.
  517. (+++) D1 and D2 domains enter DSTANDBY mode (powered off) and D3 domain
  518. enters DSTOP mode.
  519. (+++) D1 and D3 domains enter DSTANDBY mode (powered off) and D2 domain
  520. enters DSTOP mode.
  521. (+++) D2 and D3 domains enter DSTANDBY mode (powered off) and D1 domain
  522. enters DSTOP mode.
  523. (+++) D1, D2 and D3 domains enter DSTOP mode.
  524. (++) When the system enters STOP mode, the clocks are stopped and the
  525. regulator is running in main or low power mode.
  526. (++) D3 domain can be kept in Run mode regardless of the CPU status when
  527. enter STOP mode by using HAL_PWREx_ConfigD3Domain(D3State) function.
  528. (+) DSTANDBY mode to enters a domain to STANDBY mode:
  529. (++) The DSTANDBY mode is entered when the PDDS_Dn bit in PWR CPU control
  530. register (PWR_CPUCR) for the Dn domain selects Standby mode.
  531. (++) The system enters STANDBY mode only when D1, D2 and D3 domains enter
  532. DSTANDBY mode. Consequently the VCORE supply regulator is powered
  533. off.
  534. *** DSTOP mode ***
  535. ==================
  536. [..]
  537. In DStop mode the domain bus matrix clock is stopped.
  538. The Flash memory can enter low-power Stop mode when it is enabled through
  539. FLPS in PWR_CR1 register. This allows a trade-off between domain DStop
  540. restart time and low power consumption.
  541. [..]
  542. In DStop mode domain peripherals using the LSI or LSE clock and
  543. peripherals having a kernel clock request are still able to operate.
  544. [..]
  545. Before entering DSTOP mode it is recommended to call SCB_CleanDCache
  546. function in order to clean the D-Cache and guarantee the data integrity
  547. for the SRAM memories.
  548. (+) Entry:
  549. The DSTOP mode is entered using the HAL_PWREx_EnterSTOPMode(Regulator,
  550. STOPEntry, Domain) function with:
  551. (++) Regulator:
  552. (+++) PWR_MAINREGULATOR_ON : Main regulator ON.
  553. (+++) PWR_LOWPOWERREGULATOR_ON : Low Power regulator ON.
  554. (++) STOPEntry:
  555. (+++) PWR_STOPENTRY_WFI : enter STOP mode with WFI instruction
  556. (+++) PWR_STOPENTRY_WFE : enter STOP mode with WFE instruction
  557. (++) Domain:
  558. (+++) PWR_D1_DOMAIN : Enters D1/CD domain to DSTOP mode.
  559. (+++) PWR_D2_DOMAIN : Enters D2 domain to DSTOP mode.
  560. (+++) PWR_D3_DOMAIN : Enters D3/SRD domain to DSTOP mode.
  561. (+) Exit:
  562. Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
  563. *** DSTANDBY mode ***
  564. =====================
  565. [..]
  566. In DStandby mode:
  567. (+) The domain bus matrix clock is stopped.
  568. (+) The domain is powered down and the domain RAM and register contents
  569. are lost.
  570. [..]
  571. Before entering DSTANDBY mode it is recommended to call SCB_CleanDCache
  572. function in order to clean the D-Cache and guarantee the data integrity
  573. for the SRAM memories.
  574. (+) Entry:
  575. The DSTANDBY mode is entered using the HAL_PWREx_EnterSTANDBYMode
  576. (Domain) function with:
  577. (++) Domain:
  578. (+++) PWR_D1_DOMAIN : Enters D1/CD domain to DSTANDBY mode.
  579. (+++) PWR_D2_DOMAIN : Enters D2 domain to DSTANDBY mode.
  580. (+++) PWR_D3_DOMAIN : Enters D3/SRD domain to DSTANDBY mode.
  581. (+) Exit:
  582. WKUP pin rising or falling edge, RTC alarm (Alarm A and Alarm B), RTC
  583. wakeup, tamper event, time stamp event, external reset in NRST pin,
  584. IWDG reset.
  585. *** Keep D3/SRD in RUN mode ***
  586. ===============================
  587. [..]
  588. D3/SRD domain can be kept in Run mode regardless of the CPU status when
  589. entering STOP mode by using HAL_PWREx_ConfigD3Domain(D3State) function
  590. with :
  591. (+) D3State:
  592. (++) PWR_D3_DOMAIN_STOP : D3/SDR domain follows the CPU sub-system
  593. mode.
  594. (++) PWR_D3_DOMAIN_RUN : D3/SRD domain remains in Run mode regardless
  595. of CPU subsystem mode.
  596. *** FLASH Power Down configuration ****
  597. =======================================
  598. [..]
  599. By setting the FLPS bit in the PWR_CR1 register using the
  600. HAL_PWREx_EnableFlashPowerDown() function, the Flash memory also enters
  601. power down mode when the device enters STOP mode. When the Flash memory is
  602. in power down mode, an additional startup delay is incurred when waking up
  603. from STOP mode.
  604. *** Wakeup Pins configuration ****
  605. ===================================
  606. [..]
  607. Wakeup pins allow the system to exit from Standby mode. The configuration
  608. of wakeup pins is done with the HAL_PWREx_EnableWakeUpPin(sPinParams)
  609. function with:
  610. (+) sPinParams: structure to enable and configure a wakeup pin:
  611. (++) WakeUpPin: Wakeup pin to be enabled.
  612. (++) PinPolarity: Wakeup pin polarity (rising or falling edge).
  613. (++) PinPull: Wakeup pin pull (no pull, pull-up or pull-down).
  614. [..]
  615. The wakeup pins are internally connected to the EXTI lines [55-60] to
  616. generate an interrupt if enabled. The EXTI lines configuration is done by
  617. the HAL_EXTI_Dx_EventInputConfig() functions defined in the stm32h7xxhal.c
  618. file.
  619. [..]
  620. When a wakeup pin event is received the HAL_PWREx_WAKEUP_PIN_IRQHandler is
  621. called and the appropriate flag is set in the PWR_WKUPFR register. Then in
  622. the HAL_PWREx_WAKEUP_PIN_IRQHandler function the wakeup pin flag will be
  623. cleared and the appropriate user callback will be called. The user can add
  624. his own code by customization of function pointer HAL_PWREx_WKUPx_Callback.
  625. @endverbatim
  626. * @{
  627. */
  628. #if defined (PWR_CPUCR_RETDS_CD)
  629. /**
  630. * @brief Enter the system to STOP mode with main domain in DSTOP2.
  631. * @note In STOP mode, the domain bus matrix clock is stalled.
  632. * @note In STOP mode, memories and registers are maintained and peripherals
  633. * in CPU domain are no longer operational.
  634. * @note All clocks in the VCORE domain are stopped, the PLL, the HSI and the
  635. * HSE oscillators are disabled. Only Peripherals that have wakeup
  636. * capability can switch on the HSI to receive a frame, and switch off
  637. * the HSI after receiving the frame if it is not a wakeup frame. In
  638. * this case the HSI clock is propagated only to the peripheral
  639. * requesting it.
  640. * @note When exiting STOP mode by issuing an interrupt or a wakeup event,
  641. * the HSI RC oscillator is selected as system clock if STOPWUCK bit in
  642. * RCC_CFGR register is set.
  643. * @param Regulator : Specifies the regulator state in STOP mode.
  644. * This parameter can be one of the following values:
  645. * @arg PWR_MAINREGULATOR_ON : STOP mode with regulator ON.
  646. * @arg PWR_LOWPOWERREGULATOR_ON : STOP mode with low power
  647. * regulator ON.
  648. * @param STOPEntry : Specifies if STOP mode in entered with WFI or WFE
  649. * intrinsic instruction.
  650. * This parameter can be one of the following values:
  651. * @arg PWR_STOPENTRY_WFI : Enter STOP mode with WFI instruction.
  652. * @arg PWR_STOPENTRY_WFE : Enter STOP mode with WFE instruction.
  653. * @retval None.
  654. */
  655. void HAL_PWREx_EnterSTOP2Mode (uint32_t Regulator, uint8_t STOPEntry)
  656. {
  657. /* Check the parameters */
  658. assert_param (IS_PWR_REGULATOR (Regulator));
  659. assert_param (IS_PWR_STOP_ENTRY (STOPEntry));
  660. /* Select the regulator state in Stop mode */
  661. MODIFY_REG (PWR->CR1, PWR_CR1_LPDS, Regulator);
  662. /* Go to DStop2 mode (deep retention) when CPU domain enters Deepsleep */
  663. SET_BIT (PWR->CPUCR, PWR_CPUCR_RETDS_CD);
  664. /* Keep DSTOP mode when SmartRun domain enters Deepsleep */
  665. CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_SRD);
  666. /* Set SLEEPDEEP bit of Cortex System Control Register */
  667. SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  668. /* Ensure that all instructions are done before entering STOP mode */
  669. __ISB ();
  670. __DSB ();
  671. /* Select Stop mode entry */
  672. if (STOPEntry == PWR_STOPENTRY_WFI)
  673. {
  674. /* Request Wait For Interrupt */
  675. __WFI ();
  676. }
  677. else
  678. {
  679. /* Request Wait For Event */
  680. __WFE ();
  681. }
  682. /* Clear SLEEPDEEP bit of Cortex-Mx in the System Control Register */
  683. CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  684. }
  685. #endif /* defined (PWR_CPUCR_RETDS_CD) */
  686. /**
  687. * @brief Enter a Domain to DSTOP mode.
  688. * @note This API gives flexibility to manage independently each domain STOP
  689. * mode. For dual core lines, this API should be executed with the
  690. * corresponding Cortex-Mx to enter domain to DSTOP mode. When it is
  691. * executed by all available Cortex-Mx, the system enter to STOP mode.
  692. * For single core lines, calling this API with domain parameter set to
  693. * PWR_D1_DOMAIN (D1/CD), the whole system will enter in STOP mode
  694. * independently of PWR_CPUCR_PDDS_Dx bits values if RUN_D3 bit in the
  695. * CPUCR_RUN_D3 is cleared.
  696. * @note In DStop mode the domain bus matrix clock is stopped.
  697. * @note The system D3/SRD domain enter Stop mode only when the CPU subsystem
  698. * is in CStop mode, the EXTI wakeup sources are inactive and at least
  699. * one PDDS_Dn bit in PWR CPU control register (PWR_CPUCR) for
  700. * any domain request Stop.
  701. * @note Before entering DSTOP mode it is recommended to call SCB_CleanDCache
  702. * function in order to clean the D-Cache and guarantee the data
  703. * integrity for the SRAM memories.
  704. * @note In System Stop mode, the domain peripherals that use the LSI or LSE
  705. * clock, and the peripherals that have a kernel clock request to
  706. * select HSI or CSI as source, are still able to operate.
  707. * @param Regulator : Specifies the regulator state in STOP mode.
  708. * This parameter can be one of the following values:
  709. * @arg PWR_MAINREGULATOR_ON : STOP mode with regulator ON.
  710. * @arg PWR_LOWPOWERREGULATOR_ON : STOP mode with low power
  711. * regulator ON.
  712. * @param STOPEntry : Specifies if STOP mode in entered with WFI or WFE
  713. * intrinsic instruction.
  714. * This parameter can be one of the following values:
  715. * @arg PWR_STOPENTRY_WFI : Enter STOP mode with WFI instruction.
  716. * @arg PWR_STOPENTRY_WFE : Enter STOP mode with WFE instruction.
  717. * @param Domain : Specifies the Domain to enter in DSTOP mode.
  718. * This parameter can be one of the following values:
  719. * @arg PWR_D1_DOMAIN : Enter D1/CD Domain to DSTOP mode.
  720. * @arg PWR_D2_DOMAIN : Enter D2 Domain to DSTOP mode.
  721. * @arg PWR_D3_DOMAIN : Enter D3/SRD Domain to DSTOP mode.
  722. * @retval None.
  723. */
  724. void HAL_PWREx_EnterSTOPMode (uint32_t Regulator, uint8_t STOPEntry, uint32_t Domain)
  725. {
  726. /* Check the parameters */
  727. assert_param (IS_PWR_REGULATOR (Regulator));
  728. assert_param (IS_PWR_STOP_ENTRY (STOPEntry));
  729. assert_param (IS_PWR_DOMAIN (Domain));
  730. /* Select the regulator state in Stop mode */
  731. MODIFY_REG (PWR->CR1, PWR_CR1_LPDS, Regulator);
  732. /* Select the domain Power Down DeepSleep */
  733. if (Domain == PWR_D1_DOMAIN)
  734. {
  735. #if defined (DUAL_CORE)
  736. /* Check current core */
  737. if (HAL_GetCurrentCPUID () != CM7_CPUID)
  738. {
  739. /*
  740. When the domain selected and the cortex-mx don't match, entering stop
  741. mode will not be performed
  742. */
  743. return;
  744. }
  745. #endif /* defined (DUAL_CORE) */
  746. /* Keep DSTOP mode when D1/CD domain enters Deepsleep */
  747. CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D1);
  748. /* Set SLEEPDEEP bit of Cortex System Control Register */
  749. SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  750. /* Ensure that all instructions are done before entering STOP mode */
  751. __DSB ();
  752. __ISB ();
  753. /* Select Stop mode entry */
  754. if (STOPEntry == PWR_STOPENTRY_WFI)
  755. {
  756. /* Request Wait For Interrupt */
  757. __WFI ();
  758. }
  759. else
  760. {
  761. /* Request Wait For Event */
  762. __WFE ();
  763. }
  764. /* Clear SLEEPDEEP bit of Cortex-Mx in the System Control Register */
  765. CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  766. }
  767. #if defined (PWR_CPUCR_PDDS_D2)
  768. else if (Domain == PWR_D2_DOMAIN)
  769. {
  770. #if defined (DUAL_CORE)
  771. /* Check current core */
  772. if (HAL_GetCurrentCPUID () != CM4_CPUID)
  773. {
  774. /*
  775. When the domain selected and the cortex-mx don't match, entering stop
  776. mode will not be performed
  777. */
  778. return;
  779. }
  780. /* Keep DSTOP mode when D2 domain enters Deepsleep */
  781. CLEAR_BIT (PWR->CPU2CR, PWR_CPU2CR_PDDS_D2);
  782. /* Set SLEEPDEEP bit of Cortex System Control Register */
  783. SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  784. /* Ensure that all instructions are done before entering STOP mode */
  785. __DSB ();
  786. __ISB ();
  787. /* Select Stop mode entry */
  788. if (STOPEntry == PWR_STOPENTRY_WFI)
  789. {
  790. /* Request Wait For Interrupt */
  791. __WFI ();
  792. }
  793. else
  794. {
  795. /* Request Wait For Event */
  796. __WFE ();
  797. }
  798. /* Clear SLEEPDEEP bit of Cortex-Mx in the System Control Register */
  799. CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  800. #else
  801. /* Keep DSTOP mode when D2 domain enters Deepsleep */
  802. CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D2);
  803. #endif /* defined (DUAL_CORE) */
  804. }
  805. #endif /* defined (PWR_CPUCR_PDDS_D2) */
  806. else
  807. {
  808. #if defined (DUAL_CORE)
  809. /* Check current core */
  810. if (HAL_GetCurrentCPUID () == CM7_CPUID)
  811. {
  812. /* Keep DSTOP mode when D3 domain enters Deepsleep */
  813. CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D3);
  814. }
  815. else
  816. {
  817. /* Keep DSTOP mode when D3 domain enters Deepsleep */
  818. CLEAR_BIT (PWR->CPU2CR, PWR_CPU2CR_PDDS_D3);
  819. }
  820. #else
  821. /* Keep DSTOP mode when D3/SRD domain enters Deepsleep */
  822. CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D3);
  823. #endif /* defined (DUAL_CORE) */
  824. }
  825. }
  826. /**
  827. * @brief Clear pending event.
  828. * @note This API clears the pending event in order to enter a given CPU
  829. * to CSLEEP or CSTOP. It should be called just before APIs performing
  830. * enter low power mode using Wait For Event request.
  831. * @note Cortex-M7 must be in CRUN mode when calling this API by Cortex-M4.
  832. * @retval None.
  833. */
  834. void HAL_PWREx_ClearPendingEvent (void)
  835. {
  836. #if defined (DUAL_CORE)
  837. /* Check the current Core */
  838. if (HAL_GetCurrentCPUID () == CM7_CPUID)
  839. {
  840. __WFE ();
  841. }
  842. else
  843. {
  844. __SEV ();
  845. __WFE ();
  846. }
  847. #else
  848. __WFE ();
  849. #endif /* defined (DUAL_CORE) */
  850. }
  851. /**
  852. * @brief Enter a Domain to DSTANDBY mode.
  853. * @note This API gives flexibility to manage independently each domain
  854. * STANDBY mode. For dual core lines, this API should be executed with
  855. * the corresponding Cortex-Mx to enter domain to DSTANDBY mode. When
  856. * it is executed by all available Cortex-Mx, the system enter STANDBY
  857. * mode.
  858. * For single core lines, calling this API with D1/SRD the selected
  859. * domain will enter the whole system in STOP if PWR_CPUCR_PDDS_D3 = 0
  860. * and enter the whole system in STANDBY if PWR_CPUCR_PDDS_D3 = 1.
  861. * @note The DStandby mode is entered when all PDDS_Dn bits in PWR_CPUCR for
  862. * the Dn domain select Standby mode. When the system enters Standby
  863. * mode, the voltage regulator is disabled.
  864. * @note When D2 or D3 domain is in DStandby mode and the CPU sets the
  865. * domain PDDS_Dn bit to select Stop mode, the domain remains in
  866. * DStandby mode. The domain will only exit DStandby when the CPU
  867. * allocates a peripheral in the domain.
  868. * @note The system D3/SRD domain enters Standby mode only when the D1 and D2
  869. * domain are in DStandby.
  870. * @note Before entering DSTANDBY mode it is recommended to call
  871. * SCB_CleanDCache function in order to clean the D-Cache and guarantee
  872. * the data integrity for the SRAM memories.
  873. * @param Domain : Specifies the Domain to enter to STANDBY mode.
  874. * This parameter can be one of the following values:
  875. * @arg PWR_D1_DOMAIN: Enter D1/CD Domain to DSTANDBY mode.
  876. * @arg PWR_D2_DOMAIN: Enter D2 Domain to DSTANDBY mode.
  877. * @arg PWR_D3_DOMAIN: Enter D3/SRD Domain to DSTANDBY mode.
  878. * @retval None
  879. */
  880. void HAL_PWREx_EnterSTANDBYMode (uint32_t Domain)
  881. {
  882. /* Check the parameters */
  883. assert_param (IS_PWR_DOMAIN (Domain));
  884. /* Select the domain Power Down DeepSleep */
  885. if (Domain == PWR_D1_DOMAIN)
  886. {
  887. #if defined (DUAL_CORE)
  888. /* Check current core */
  889. if (HAL_GetCurrentCPUID () != CM7_CPUID)
  890. {
  891. /*
  892. When the domain selected and the cortex-mx don't match, entering
  893. standby mode will not be performed
  894. */
  895. return;
  896. }
  897. #endif /* defined (DUAL_CORE) */
  898. /* Allow DSTANDBY mode when D1/CD domain enters Deepsleep */
  899. SET_BIT (PWR-> CPUCR, PWR_CPUCR_PDDS_D1);
  900. #if defined (DUAL_CORE)
  901. /* Allow DSTANDBY mode when D1/CD domain enters Deepsleep */
  902. SET_BIT (PWR-> CPU2CR, PWR_CPU2CR_PDDS_D1);
  903. #endif /*DUAL_CORE*/
  904. /* Set SLEEPDEEP bit of Cortex System Control Register */
  905. SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  906. /* This option is used to ensure that store operations are completed */
  907. #if defined (__CC_ARM)
  908. __force_stores ();
  909. #endif /* defined (__CC_ARM) */
  910. /* Request Wait For Interrupt */
  911. __WFI ();
  912. }
  913. #if defined (PWR_CPUCR_PDDS_D2)
  914. else if (Domain == PWR_D2_DOMAIN)
  915. {
  916. /* Allow DSTANDBY mode when D2 domain enters Deepsleep */
  917. SET_BIT (PWR-> CPUCR, PWR_CPUCR_PDDS_D2);
  918. #if defined (DUAL_CORE)
  919. /* Check current core */
  920. if (HAL_GetCurrentCPUID () != CM4_CPUID)
  921. {
  922. /*
  923. When the domain selected and the cortex-mx don't match, entering
  924. standby mode will not be performed
  925. */
  926. return;
  927. }
  928. /* Allow DSTANDBY mode when D2 domain enters Deepsleep */
  929. SET_BIT (PWR-> CPU2CR, PWR_CPU2CR_PDDS_D2);
  930. /* Set SLEEPDEEP bit of Cortex System Control Register */
  931. SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  932. /* This option is used to ensure that store operations are completed */
  933. #if defined (__CC_ARM)
  934. __force_stores ();
  935. #endif /* defined (__CC_ARM) */
  936. /* Request Wait For Interrupt */
  937. __WFI ();
  938. #endif /* defined (DUAL_CORE) */
  939. }
  940. #endif /* defined (PWR_CPUCR_PDDS_D2) */
  941. else
  942. {
  943. /* Allow DSTANDBY mode when D3/SRD domain enters Deepsleep */
  944. SET_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D3);
  945. #if defined (DUAL_CORE)
  946. /* Allow DSTANDBY mode when D3/SRD domain enters Deepsleep */
  947. SET_BIT (PWR->CPU2CR, PWR_CPU2CR_PDDS_D3);
  948. #endif /* defined (DUAL_CORE) */
  949. }
  950. }
  951. /**
  952. * @brief Configure the D3/SRD Domain state when the System in low power mode.
  953. * @param D3State : Specifies the D3/SRD state.
  954. * This parameter can be one of the following values :
  955. * @arg PWR_D3_DOMAIN_STOP : D3/SRD domain will follow the most deep
  956. * CPU sub-system low power mode.
  957. * @arg PWR_D3_DOMAIN_RUN : D3/SRD domain will stay in RUN mode
  958. * regardless of the CPU sub-system low
  959. * power mode.
  960. * @retval None
  961. */
  962. void HAL_PWREx_ConfigD3Domain (uint32_t D3State)
  963. {
  964. /* Check the parameter */
  965. assert_param (IS_D3_STATE (D3State));
  966. /* Keep D3/SRD in run mode */
  967. MODIFY_REG (PWR->CPUCR, PWR_CPUCR_RUN_D3, D3State);
  968. }
  969. #if defined (DUAL_CORE)
  970. /**
  971. * @brief Clear HOLD2F, HOLD1F, STOPF, SBF, SBF_D1, and SBF_D2 flags for a
  972. * given domain.
  973. * @param DomainFlags : Specifies the Domain flags to be cleared.
  974. * This parameter can be one of the following values:
  975. * @arg PWR_D1_DOMAIN_FLAGS : Clear D1 Domain flags.
  976. * @arg PWR_D2_DOMAIN_FLAGS : Clear D2 Domain flags.
  977. * @arg PWR_ALL_DOMAIN_FLAGS : Clear D1 and D2 Domain flags.
  978. * @retval None.
  979. */
  980. void HAL_PWREx_ClearDomainFlags (uint32_t DomainFlags)
  981. {
  982. /* Check the parameter */
  983. assert_param (IS_PWR_DOMAIN_FLAG (DomainFlags));
  984. /* D1 CPU flags */
  985. if (DomainFlags == PWR_D1_DOMAIN_FLAGS)
  986. {
  987. /* Clear D1 domain flags (HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2) */
  988. SET_BIT (PWR->CPUCR, PWR_CPUCR_CSSF);
  989. }
  990. /* D2 CPU flags */
  991. else if (DomainFlags == PWR_D2_DOMAIN_FLAGS)
  992. {
  993. /* Clear D2 domain flags (HOLD1F, STOPF, SBF, SBF_D1, and SBF_D2) */
  994. SET_BIT (PWR->CPU2CR, PWR_CPU2CR_CSSF);
  995. }
  996. else
  997. {
  998. /* Clear D1 domain flags (HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2) */
  999. SET_BIT (PWR->CPUCR, PWR_CPUCR_CSSF);
  1000. /* Clear D2 domain flags (HOLD1F, STOPF, SBF, SBF_D1, and SBF_D2) */
  1001. SET_BIT (PWR->CPU2CR, PWR_CPU2CR_CSSF);
  1002. }
  1003. }
  1004. /**
  1005. * @brief Hold the CPU and their domain peripherals when exiting STOP mode.
  1006. * @param CPU : Specifies the core to be held.
  1007. * This parameter can be one of the following values:
  1008. * @arg PWR_CORE_CPU1: Hold CPU1 and set CPU2 as master.
  1009. * @arg PWR_CORE_CPU2: Hold CPU2 and set CPU1 as master.
  1010. * @retval HAL status
  1011. */
  1012. HAL_StatusTypeDef HAL_PWREx_HoldCore (uint32_t CPU)
  1013. {
  1014. HAL_StatusTypeDef status = HAL_OK;
  1015. /* Check the parameters */
  1016. assert_param (IS_PWR_CORE (CPU));
  1017. /* Check CPU index */
  1018. if (CPU == PWR_CORE_CPU2)
  1019. {
  1020. /* If CPU1 is not held */
  1021. if ((PWR->CPU2CR & PWR_CPU2CR_HOLD1) != PWR_CPU2CR_HOLD1)
  1022. {
  1023. /* Set HOLD2 bit */
  1024. SET_BIT (PWR->CPUCR, PWR_CPUCR_HOLD2);
  1025. }
  1026. else
  1027. {
  1028. status = HAL_ERROR;
  1029. }
  1030. }
  1031. else
  1032. {
  1033. /* If CPU2 is not held */
  1034. if ((PWR->CPUCR & PWR_CPUCR_HOLD2) != PWR_CPUCR_HOLD2)
  1035. {
  1036. /* Set HOLD1 bit */
  1037. SET_BIT (PWR->CPU2CR, PWR_CPU2CR_HOLD1);
  1038. }
  1039. else
  1040. {
  1041. status = HAL_ERROR;
  1042. }
  1043. }
  1044. return status;
  1045. }
  1046. /**
  1047. * @brief Release the CPU and their domain peripherals after a wake-up from
  1048. * STOP mode.
  1049. * @param CPU: Specifies the core to be released.
  1050. * This parameter can be one of the following values:
  1051. * @arg PWR_CORE_CPU1: Release the CPU1 and their domain
  1052. * peripherals from holding.
  1053. * @arg PWR_CORE_CPU2: Release the CPU2 and their domain
  1054. * peripherals from holding.
  1055. * @retval None
  1056. */
  1057. void HAL_PWREx_ReleaseCore (uint32_t CPU)
  1058. {
  1059. /* Check the parameters */
  1060. assert_param (IS_PWR_CORE (CPU));
  1061. /* Check CPU index */
  1062. if (CPU == PWR_CORE_CPU2)
  1063. {
  1064. /* Reset HOLD2 bit */
  1065. CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_HOLD2);
  1066. }
  1067. else
  1068. {
  1069. /* Reset HOLD1 bit */
  1070. CLEAR_BIT (PWR->CPU2CR, PWR_CPU2CR_HOLD1);
  1071. }
  1072. }
  1073. #endif /* defined (DUAL_CORE) */
  1074. /**
  1075. * @brief Enable the Flash Power Down in Stop mode.
  1076. * @note When Flash Power Down is enabled the Flash memory enters low-power
  1077. * mode when D1/SRD domain is in DStop mode. This feature allows to
  1078. * obtain the best trade-off between low-power consumption and restart
  1079. * time when exiting from DStop mode.
  1080. * @retval None.
  1081. */
  1082. void HAL_PWREx_EnableFlashPowerDown (void)
  1083. {
  1084. /* Enable the Flash Power Down */
  1085. SET_BIT (PWR->CR1, PWR_CR1_FLPS);
  1086. }
  1087. /**
  1088. * @brief Disable the Flash Power Down in Stop mode.
  1089. * @note When Flash Power Down is disabled the Flash memory is kept on
  1090. * normal mode when D1/SRD domain is in DStop mode. This feature allows
  1091. * to obtain the best trade-off between low-power consumption and
  1092. * restart time when exiting from DStop mode.
  1093. * @retval None.
  1094. */
  1095. void HAL_PWREx_DisableFlashPowerDown (void)
  1096. {
  1097. /* Disable the Flash Power Down */
  1098. CLEAR_BIT (PWR->CR1, PWR_CR1_FLPS);
  1099. }
  1100. #if defined (PWR_CR1_SRDRAMSO)
  1101. /**
  1102. * @brief Enable memory block shut-off in DStop or DStop2 modes
  1103. * @note In DStop or DStop2 mode, the content of the memory blocks is
  1104. * maintained. Further power optimization can be obtained by switching
  1105. * off some memory blocks. This optimization implies loss of the memory
  1106. * content. The user can select which memory is discarded during STOP
  1107. * mode by means of xxSO bits.
  1108. * @param MemoryBlock : Specifies the memory block to shut-off during DStop or
  1109. * DStop2 mode.
  1110. * This parameter can be one of the following values:
  1111. * @arg PWR_SRD_AHB_MEMORY_BLOCK : SmartRun domain AHB memory.
  1112. * @arg PWR_USB_FDCAN_MEMORY_BLOCK : High-speed interfaces USB and
  1113. * FDCAN memories.
  1114. * @arg PWR_GFXMMU_JPEG_MEMORY_BLOCK : GFXMMU and JPEG memories.
  1115. * @arg PWR_TCM_ECM_MEMORY_BLOCK : Instruction TCM and ETM memories.
  1116. * @arg PWR_RAM1_AHB_MEMORY_BLOCK : AHB RAM1 memory.
  1117. * @arg PWR_RAM2_AHB_MEMORY_BLOCK : AHB RAM2 memory.
  1118. * @arg PWR_RAM1_AXI_MEMORY_BLOCK : AXI RAM1 memory.
  1119. * @arg PWR_RAM2_AXI_MEMORY_BLOCK : AXI RAM2 memory.
  1120. * @arg PWR_RAM3_AXI_MEMORY_BLOCK : AXI RAM3 memory.
  1121. * @retval None.
  1122. */
  1123. void HAL_PWREx_EnableMemoryShutOff (uint32_t MemoryBlock)
  1124. {
  1125. /* Check the parameter */
  1126. assert_param (IS_PWR_MEMORY_BLOCK (MemoryBlock));
  1127. /* Enable memory block shut-off */
  1128. SET_BIT (PWR->CR1, MemoryBlock);
  1129. }
  1130. /**
  1131. * @brief Disable memory block shut-off in DStop or DStop2 modes
  1132. * @param MemoryBlock : Specifies the memory block to keep content during
  1133. * DStop or DStop2 mode.
  1134. * This parameter can be one of the following values:
  1135. * @arg PWR_SRD_AHB_MEMORY_BLOCK : SmartRun domain AHB memory.
  1136. * @arg PWR_USB_FDCAN_MEMORY_BLOCK : High-speed interfaces USB and
  1137. * FDCAN memories.
  1138. * @arg PWR_GFXMMU_JPEG_MEMORY_BLOCK : GFXMMU and JPEG memories.
  1139. * @arg PWR_TCM_ECM_MEMORY_BLOCK : Instruction TCM and ETM memories.
  1140. * @arg PWR_RAM1_AHB_MEMORY_BLOCK : AHB RAM1 memory.
  1141. * @arg PWR_RAM2_AHB_MEMORY_BLOCK : AHB RAM2 memory.
  1142. * @arg PWR_RAM1_AXI_MEMORY_BLOCK : AXI RAM1 memory.
  1143. * @arg PWR_RAM2_AXI_MEMORY_BLOCK : AXI RAM2 memory.
  1144. * @arg PWR_RAM3_AXI_MEMORY_BLOCK : AXI RAM3 memory.
  1145. * @retval None.
  1146. */
  1147. void HAL_PWREx_DisableMemoryShutOff (uint32_t MemoryBlock)
  1148. {
  1149. /* Check the parameter */
  1150. assert_param (IS_PWR_MEMORY_BLOCK (MemoryBlock));
  1151. /* Disable memory block shut-off */
  1152. CLEAR_BIT (PWR->CR1, MemoryBlock);
  1153. }
  1154. #endif /* defined (PWR_CR1_SRDRAMSO) */
  1155. /**
  1156. * @brief Enable the Wake-up PINx functionality.
  1157. * @param sPinParams : Pointer to a PWREx_WakeupPinTypeDef structure that
  1158. * contains the configuration information for the wake-up
  1159. * Pin.
  1160. * @note For dual core devices, please ensure to configure the EXTI lines for
  1161. * the different Cortex-Mx. All combination are allowed: wake up only
  1162. * Cortex-M7, wake up only Cortex-M4 and wake up Cortex-M7 and
  1163. * Cortex-M4.
  1164. * @retval None.
  1165. */
  1166. void HAL_PWREx_EnableWakeUpPin (PWREx_WakeupPinTypeDef *sPinParams)
  1167. {
  1168. uint32_t pinConfig;
  1169. uint32_t regMask;
  1170. const uint32_t pullMask = PWR_WKUPEPR_WKUPPUPD1;
  1171. /* Check the parameters */
  1172. assert_param (IS_PWR_WAKEUP_PIN (sPinParams->WakeUpPin));
  1173. assert_param (IS_PWR_WAKEUP_PIN_POLARITY (sPinParams->PinPolarity));
  1174. assert_param (IS_PWR_WAKEUP_PIN_PULL (sPinParams->PinPull));
  1175. pinConfig = sPinParams->WakeUpPin | \
  1176. (sPinParams->PinPolarity << ((POSITION_VAL(sPinParams->WakeUpPin) + PWR_WKUPEPR_WKUPP1_Pos) & 0x1FU)) | \
  1177. (sPinParams->PinPull << (((POSITION_VAL(sPinParams->WakeUpPin) * PWR_WAKEUP_PINS_PULL_SHIFT_OFFSET) + PWR_WKUPEPR_WKUPPUPD1_Pos) & 0x1FU));
  1178. regMask = sPinParams->WakeUpPin | \
  1179. (PWR_WKUPEPR_WKUPP1 << (POSITION_VAL(sPinParams->WakeUpPin) & 0x1FU)) | \
  1180. (pullMask << ((POSITION_VAL(sPinParams->WakeUpPin) * PWR_WAKEUP_PINS_PULL_SHIFT_OFFSET) & 0x1FU));
  1181. /* Enable and Specify the Wake-Up pin polarity and the pull configuration
  1182. for the event detection (rising or falling edge) */
  1183. MODIFY_REG (PWR->WKUPEPR, regMask, pinConfig);
  1184. #ifndef DUAL_CORE
  1185. /* Configure the Wakeup Pin EXTI Line */
  1186. MODIFY_REG (EXTI->IMR2, PWR_EXTI_WAKEUP_PINS_MASK, (sPinParams->WakeUpPin << EXTI_IMR2_IM55_Pos));
  1187. #endif /* !DUAL_CORE */
  1188. }
  1189. /**
  1190. * @brief Disable the Wake-up PINx functionality.
  1191. * @param WakeUpPin : Specifies the Wake-Up pin to be disabled.
  1192. * This parameter can be one of the following values:
  1193. * @arg PWR_WAKEUP_PIN1 : Disable PA0 wake-up PIN.
  1194. * @arg PWR_WAKEUP_PIN2 : Disable PA2 wake-up PIN.
  1195. * @arg PWR_WAKEUP_PIN3 : Disable PI8 wake-up PIN.
  1196. * @arg PWR_WAKEUP_PIN4 : Disable PC13 wake-up PIN.
  1197. * @arg PWR_WAKEUP_PIN5 : Disable PI11 wake-up PIN.
  1198. * @arg PWR_WAKEUP_PIN6 : Disable PC1 wake-up PIN.
  1199. * @note The PWR_WAKEUP_PIN3 and PWR_WAKEUP_PIN5 are available only for
  1200. * devices that support GPIOI port.
  1201. * @retval None
  1202. */
  1203. void HAL_PWREx_DisableWakeUpPin (uint32_t WakeUpPin)
  1204. {
  1205. /* Check the parameter */
  1206. assert_param (IS_PWR_WAKEUP_PIN (WakeUpPin));
  1207. /* Disable the WakeUpPin */
  1208. CLEAR_BIT (PWR->WKUPEPR, WakeUpPin);
  1209. }
  1210. /**
  1211. * @brief Get the Wake-Up Pin pending flags.
  1212. * @param WakeUpFlag : Specifies the Wake-Up PIN flag to be checked.
  1213. * This parameter can be one of the following values:
  1214. * @arg PWR_WAKEUP_FLAG1 : Get wakeup event received from PA0.
  1215. * @arg PWR_WAKEUP_FLAG2 : Get wakeup event received from PA2.
  1216. * @arg PWR_WAKEUP_FLAG3 : Get wakeup event received from PI8.
  1217. * @arg PWR_WAKEUP_FLAG4 : Get wakeup event received from PC13.
  1218. * @arg PWR_WAKEUP_FLAG5 : Get wakeup event received from PI11.
  1219. * @arg PWR_WAKEUP_FLAG6 : Get wakeup event received from PC1.
  1220. * @arg PWR_WAKEUP_FLAG_ALL : Get Wakeup event received from all
  1221. * wake up pins.
  1222. * @note The PWR_WAKEUP_FLAG3 and PWR_WAKEUP_FLAG5 are available only for
  1223. * devices that support GPIOI port.
  1224. * @retval The Wake-Up pin flag.
  1225. */
  1226. uint32_t HAL_PWREx_GetWakeupFlag (uint32_t WakeUpFlag)
  1227. {
  1228. /* Check the parameters */
  1229. assert_param (IS_PWR_WAKEUP_FLAG (WakeUpFlag));
  1230. /* Return the wake up pin flag */
  1231. return (PWR->WKUPFR & WakeUpFlag);
  1232. }
  1233. /**
  1234. * @brief Clear the Wake-Up pin pending flag.
  1235. * @param WakeUpFlag: Specifies the Wake-Up PIN flag to clear.
  1236. * This parameter can be one of the following values:
  1237. * @arg PWR_WAKEUP_FLAG1 : Clear the wakeup event received from PA0.
  1238. * @arg PWR_WAKEUP_FLAG2 : Clear the wakeup event received from PA2.
  1239. * @arg PWR_WAKEUP_FLAG3 : Clear the wakeup event received from PI8.
  1240. * @arg PWR_WAKEUP_FLAG4 : Clear the wakeup event received from PC13.
  1241. * @arg PWR_WAKEUP_FLAG5 : Clear the wakeup event received from PI11.
  1242. * @arg PWR_WAKEUP_FLAG6 : Clear the wakeup event received from PC1.
  1243. * @arg PWR_WAKEUP_FLAG_ALL : Clear the wakeup events received from
  1244. * all wake up pins.
  1245. * @note The PWR_WAKEUP_FLAG3 and PWR_WAKEUP_FLAG5 are available only for
  1246. * devices that support GPIOI port.
  1247. * @retval HAL status.
  1248. */
  1249. HAL_StatusTypeDef HAL_PWREx_ClearWakeupFlag (uint32_t WakeUpFlag)
  1250. {
  1251. /* Check the parameter */
  1252. assert_param (IS_PWR_WAKEUP_FLAG (WakeUpFlag));
  1253. /* Clear the wake up event received from wake up pin x */
  1254. SET_BIT (PWR->WKUPCR, WakeUpFlag);
  1255. /* Check if the wake up event is well cleared */
  1256. if ((PWR->WKUPFR & WakeUpFlag) != 0U)
  1257. {
  1258. return HAL_ERROR;
  1259. }
  1260. return HAL_OK;
  1261. }
  1262. /**
  1263. * @brief This function handles the PWR WAKEUP PIN interrupt request.
  1264. * @note This API should be called under the WAKEUP_PIN_IRQHandler().
  1265. * @retval None.
  1266. */
  1267. void HAL_PWREx_WAKEUP_PIN_IRQHandler (void)
  1268. {
  1269. /* Wakeup pin EXTI line interrupt detected */
  1270. if (READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF1) != 0U)
  1271. {
  1272. /* Clear PWR WKUPF1 flag */
  1273. __HAL_PWR_CLEAR_WAKEUPFLAG (PWR_FLAG_WKUP1);
  1274. /* PWR WKUP1 interrupt user callback */
  1275. HAL_PWREx_WKUP1_Callback ();
  1276. }
  1277. else if (READ_BIT (PWR->WKUPFR, PWR_WKUPFR_WKUPF2) != 0U)
  1278. {
  1279. /* Clear PWR WKUPF2 flag */
  1280. __HAL_PWR_CLEAR_WAKEUPFLAG (PWR_FLAG_WKUP2);
  1281. /* PWR WKUP2 interrupt user callback */
  1282. HAL_PWREx_WKUP2_Callback ();
  1283. }
  1284. #if defined (PWR_WKUPFR_WKUPF3)
  1285. else if (READ_BIT (PWR->WKUPFR, PWR_WKUPFR_WKUPF3) != 0U)
  1286. {
  1287. /* Clear PWR WKUPF3 flag */
  1288. __HAL_PWR_CLEAR_WAKEUPFLAG (PWR_FLAG_WKUP3);
  1289. /* PWR WKUP3 interrupt user callback */
  1290. HAL_PWREx_WKUP3_Callback ();
  1291. }
  1292. #endif /* defined (PWR_WKUPFR_WKUPF3) */
  1293. else if (READ_BIT (PWR->WKUPFR, PWR_WKUPFR_WKUPF4) != 0U)
  1294. {
  1295. /* Clear PWR WKUPF4 flag */
  1296. __HAL_PWR_CLEAR_WAKEUPFLAG (PWR_FLAG_WKUP4);
  1297. /* PWR WKUP4 interrupt user callback */
  1298. HAL_PWREx_WKUP4_Callback ();
  1299. }
  1300. #if defined (PWR_WKUPFR_WKUPF5)
  1301. else if (READ_BIT (PWR->WKUPFR, PWR_WKUPFR_WKUPF5) != 0U)
  1302. {
  1303. /* Clear PWR WKUPF5 flag */
  1304. __HAL_PWR_CLEAR_WAKEUPFLAG (PWR_FLAG_WKUP5);
  1305. /* PWR WKUP5 interrupt user callback */
  1306. HAL_PWREx_WKUP5_Callback ();
  1307. }
  1308. #endif /* defined (PWR_WKUPFR_WKUPF5) */
  1309. else
  1310. {
  1311. /* Clear PWR WKUPF6 flag */
  1312. __HAL_PWR_CLEAR_WAKEUPFLAG (PWR_FLAG_WKUP6);
  1313. /* PWR WKUP6 interrupt user callback */
  1314. HAL_PWREx_WKUP6_Callback ();
  1315. }
  1316. }
  1317. /**
  1318. * @brief PWR WKUP1 interrupt callback.
  1319. * @retval None.
  1320. */
  1321. __weak void HAL_PWREx_WKUP1_Callback (void)
  1322. {
  1323. /* NOTE : This function should not be modified, when the callback is needed,
  1324. the HAL_PWREx_WKUP1Callback can be implemented in the user file
  1325. */
  1326. }
  1327. /**
  1328. * @brief PWR WKUP2 interrupt callback.
  1329. * @retval None.
  1330. */
  1331. __weak void HAL_PWREx_WKUP2_Callback (void)
  1332. {
  1333. /* NOTE : This function should not be modified, when the callback is needed,
  1334. the HAL_PWREx_WKUP2Callback can be implemented in the user file
  1335. */
  1336. }
  1337. #if defined (PWR_WKUPFR_WKUPF3)
  1338. /**
  1339. * @brief PWR WKUP3 interrupt callback.
  1340. * @retval None.
  1341. */
  1342. __weak void HAL_PWREx_WKUP3_Callback (void)
  1343. {
  1344. /* NOTE : This function should not be modified, when the callback is needed,
  1345. the HAL_PWREx_WKUP3Callback can be implemented in the user file
  1346. */
  1347. }
  1348. #endif /* defined (PWR_WKUPFR_WKUPF3) */
  1349. /**
  1350. * @brief PWR WKUP4 interrupt callback.
  1351. * @retval None.
  1352. */
  1353. __weak void HAL_PWREx_WKUP4_Callback (void)
  1354. {
  1355. /* NOTE : This function should not be modified, when the callback is needed,
  1356. the HAL_PWREx_WKUP4Callback can be implemented in the user file
  1357. */
  1358. }
  1359. #if defined (PWR_WKUPFR_WKUPF5)
  1360. /**
  1361. * @brief PWR WKUP5 interrupt callback.
  1362. * @retval None.
  1363. */
  1364. __weak void HAL_PWREx_WKUP5_Callback (void)
  1365. {
  1366. /* NOTE : This function should not be modified, when the callback is needed,
  1367. the HAL_PWREx_WKUP5Callback can be implemented in the user file
  1368. */
  1369. }
  1370. #endif /* defined (PWR_WKUPFR_WKUPF5) */
  1371. /**
  1372. * @brief PWR WKUP6 interrupt callback.
  1373. * @retval None.
  1374. */
  1375. __weak void HAL_PWREx_WKUP6_Callback (void)
  1376. {
  1377. /* NOTE : This function should not be modified, when the callback is needed,
  1378. the HAL_PWREx_WKUP6Callback can be implemented in the user file
  1379. */
  1380. }
  1381. /**
  1382. * @}
  1383. */
  1384. /** @defgroup PWREx_Exported_Functions_Group3 Peripherals control functions
  1385. * @brief Peripherals control functions
  1386. *
  1387. @verbatim
  1388. ===============================================================================
  1389. ##### Peripherals control functions #####
  1390. ===============================================================================
  1391. *** Main and Backup Regulators configuration ***
  1392. ================================================
  1393. [..]
  1394. (+) The backup domain includes 4 Kbytes of backup SRAM accessible only
  1395. from the CPU, and addressed in 32-bit, 16-bit or 8-bit mode. Its
  1396. content is retained even in Standby or VBAT mode when the low power
  1397. backup regulator is enabled. It can be considered as an internal
  1398. EEPROM when VBAT is always present. You can use the
  1399. HAL_PWREx_EnableBkUpReg() function to enable the low power backup
  1400. regulator.
  1401. (+) When the backup domain is supplied by VDD (analog switch connected to
  1402. VDD) the backup SRAM is powered from VDD which replaces the VBAT power
  1403. supply to save battery life.
  1404. (+) The backup SRAM is not mass erased by a tamper event. It is read
  1405. protected to prevent confidential data, such as cryptographic private
  1406. key, from being accessed. The backup SRAM can be erased only through
  1407. the Flash interface when a protection level change from level 1 to
  1408. level 0 is requested.
  1409. -@- Refer to the description of Read protection (RDP) in the Flash
  1410. programming manual.
  1411. (+) The main internal regulator can be configured to have a tradeoff
  1412. between performance and power consumption when the device does not
  1413. operate at the maximum frequency. This is done through
  1414. HAL_PWREx_ControlVoltageScaling(VOS) function which configure the VOS
  1415. bit in PWR_D3CR register.
  1416. (+) The main internal regulator can be configured to operate in Low Power
  1417. mode when the system enters STOP mode to further reduce power
  1418. consumption.
  1419. This is done through HAL_PWREx_ControlStopModeVoltageScaling(SVOS)
  1420. function which configure the SVOS bit in PWR_CR1 register.
  1421. The selected SVOS4 and SVOS5 levels add an additional startup delay
  1422. when exiting from system Stop mode.
  1423. -@- Refer to the product datasheets for more details.
  1424. *** USB Regulator configuration ***
  1425. ===================================
  1426. [..]
  1427. (+) The USB transceivers are supplied from a dedicated VDD33USB supply
  1428. that can be provided either by the integrated USB regulator, or by an
  1429. external USB supply.
  1430. (+) The USB regulator is enabled by HAL_PWREx_EnableUSBReg() function, the
  1431. VDD33USB is then provided from the USB regulator.
  1432. (+) When the USB regulator is enabled, the VDD33USB supply level detector
  1433. shall be enabled through HAL_PWREx_EnableUSBVoltageDetector()
  1434. function.
  1435. (+) The USB regulator is disabled through HAL_PWREx_DisableUSBReg()
  1436. function and VDD33USB can be provided from an external supply. In this
  1437. case VDD33USB and VDD50USB shall be connected together.
  1438. *** VBAT battery charging ***
  1439. =============================
  1440. [..]
  1441. (+) When VDD is present, the external battery connected to VBAT can be
  1442. charged through an internal resistance. VBAT charging can be performed
  1443. either through a 5 KOhm resistor or through a 1.5 KOhm resistor.
  1444. (+) VBAT charging is enabled by HAL_PWREx_EnableBatteryCharging
  1445. (ResistorValue) function with:
  1446. (++) ResistorValue:
  1447. (+++) PWR_BATTERY_CHARGING_RESISTOR_5: 5 KOhm resistor.
  1448. (+++) PWR_BATTERY_CHARGING_RESISTOR_1_5: 1.5 KOhm resistor.
  1449. (+) VBAT charging is disabled by HAL_PWREx_DisableBatteryCharging()
  1450. function.
  1451. @endverbatim
  1452. * @{
  1453. */
  1454. /**
  1455. * @brief Enable the Backup Regulator.
  1456. * @retval HAL status.
  1457. */
  1458. HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg (void)
  1459. {
  1460. uint32_t tickstart;
  1461. /* Enable the Backup regulator */
  1462. SET_BIT (PWR->CR2, PWR_CR2_BREN);
  1463. /* Get tick */
  1464. tickstart = HAL_GetTick ();
  1465. /* Wait till Backup regulator ready flag is set */
  1466. while (__HAL_PWR_GET_FLAG (PWR_FLAG_BRR) == 0U)
  1467. {
  1468. if ((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY)
  1469. {
  1470. return HAL_ERROR;
  1471. }
  1472. }
  1473. return HAL_OK;
  1474. }
  1475. /**
  1476. * @brief Disable the Backup Regulator.
  1477. * @retval HAL status.
  1478. */
  1479. HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg (void)
  1480. {
  1481. uint32_t tickstart;
  1482. /* Disable the Backup regulator */
  1483. CLEAR_BIT (PWR->CR2, PWR_CR2_BREN);
  1484. /* Get tick */
  1485. tickstart = HAL_GetTick ();
  1486. /* Wait till Backup regulator ready flag is reset */
  1487. while (__HAL_PWR_GET_FLAG (PWR_FLAG_BRR) != 0U)
  1488. {
  1489. if ((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY)
  1490. {
  1491. return HAL_ERROR;
  1492. }
  1493. }
  1494. return HAL_OK;
  1495. }
  1496. /**
  1497. * @brief Enable the USB Regulator.
  1498. * @retval HAL status.
  1499. */
  1500. HAL_StatusTypeDef HAL_PWREx_EnableUSBReg (void)
  1501. {
  1502. uint32_t tickstart;
  1503. /* Enable the USB regulator */
  1504. SET_BIT (PWR->CR3, PWR_CR3_USBREGEN);
  1505. /* Get tick */
  1506. tickstart = HAL_GetTick ();
  1507. /* Wait till the USB regulator ready flag is set */
  1508. while (__HAL_PWR_GET_FLAG (PWR_FLAG_USB33RDY) == 0U)
  1509. {
  1510. if ((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY)
  1511. {
  1512. return HAL_ERROR;
  1513. }
  1514. }
  1515. return HAL_OK;
  1516. }
  1517. /**
  1518. * @brief Disable the USB Regulator.
  1519. * @retval HAL status.
  1520. */
  1521. HAL_StatusTypeDef HAL_PWREx_DisableUSBReg (void)
  1522. {
  1523. uint32_t tickstart;
  1524. /* Disable the USB regulator */
  1525. CLEAR_BIT (PWR->CR3, PWR_CR3_USBREGEN);
  1526. /* Get tick */
  1527. tickstart = HAL_GetTick ();
  1528. /* Wait till the USB regulator ready flag is reset */
  1529. while(__HAL_PWR_GET_FLAG (PWR_FLAG_USB33RDY) != 0U)
  1530. {
  1531. if ((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY)
  1532. {
  1533. return HAL_ERROR;
  1534. }
  1535. }
  1536. return HAL_OK;
  1537. }
  1538. /**
  1539. * @brief Enable the USB voltage level detector.
  1540. * @retval None.
  1541. */
  1542. void HAL_PWREx_EnableUSBVoltageDetector (void)
  1543. {
  1544. /* Enable the USB voltage detector */
  1545. SET_BIT (PWR->CR3, PWR_CR3_USB33DEN);
  1546. }
  1547. /**
  1548. * @brief Disable the USB voltage level detector.
  1549. * @retval None.
  1550. */
  1551. void HAL_PWREx_DisableUSBVoltageDetector (void)
  1552. {
  1553. /* Disable the USB voltage detector */
  1554. CLEAR_BIT (PWR->CR3, PWR_CR3_USB33DEN);
  1555. }
  1556. /**
  1557. * @brief Enable the Battery charging.
  1558. * @note When VDD is present, charge the external battery through an internal
  1559. * resistor.
  1560. * @param ResistorValue : Specifies the charging resistor.
  1561. * This parameter can be one of the following values :
  1562. * @arg PWR_BATTERY_CHARGING_RESISTOR_5 : 5 KOhm resistor.
  1563. * @arg PWR_BATTERY_CHARGING_RESISTOR_1_5 : 1.5 KOhm resistor.
  1564. * @retval None.
  1565. */
  1566. void HAL_PWREx_EnableBatteryCharging (uint32_t ResistorValue)
  1567. {
  1568. /* Check the parameter */
  1569. assert_param (IS_PWR_BATTERY_RESISTOR_SELECT (ResistorValue));
  1570. /* Specify the charging resistor */
  1571. MODIFY_REG (PWR->CR3, PWR_CR3_VBRS, ResistorValue);
  1572. /* Enable the Battery charging */
  1573. SET_BIT (PWR->CR3, PWR_CR3_VBE);
  1574. }
  1575. /**
  1576. * @brief Disable the Battery charging.
  1577. * @retval None.
  1578. */
  1579. void HAL_PWREx_DisableBatteryCharging (void)
  1580. {
  1581. /* Disable the Battery charging */
  1582. CLEAR_BIT (PWR->CR3, PWR_CR3_VBE);
  1583. }
  1584. #if defined (PWR_CR1_BOOSTE)
  1585. /**
  1586. * @brief Enable the booster to guarantee the analog switch AC performance when
  1587. * the VDD supply voltage is below 2V7.
  1588. * @note The VDD supply voltage can be monitored through the PVD and the PLS
  1589. * field bits.
  1590. * @retval None.
  1591. */
  1592. void HAL_PWREx_EnableAnalogBooster (void)
  1593. {
  1594. /* Enable the Analog voltage */
  1595. SET_BIT (PWR->CR1, PWR_CR1_AVD_READY);
  1596. /* Enable VDDA booster */
  1597. SET_BIT (PWR->CR1, PWR_CR1_BOOSTE);
  1598. }
  1599. /**
  1600. * @brief Disable the analog booster.
  1601. * @retval None.
  1602. */
  1603. void HAL_PWREx_DisableAnalogBooster (void)
  1604. {
  1605. /* Disable VDDA booster */
  1606. CLEAR_BIT (PWR->CR1, PWR_CR1_BOOSTE);
  1607. /* Disable the Analog voltage */
  1608. CLEAR_BIT (PWR->CR1, PWR_CR1_AVD_READY);
  1609. }
  1610. #endif /* defined (PWR_CR1_BOOSTE) */
  1611. /**
  1612. * @}
  1613. */
  1614. /** @defgroup PWREx_Exported_Functions_Group4 Power Monitoring functions
  1615. * @brief Power Monitoring functions
  1616. *
  1617. @verbatim
  1618. ===============================================================================
  1619. ##### Power Monitoring functions #####
  1620. ===============================================================================
  1621. *** VBAT and Temperature supervision ***
  1622. ========================================
  1623. [..]
  1624. (+) The VBAT battery voltage supply can be monitored by comparing it with
  1625. two threshold levels: VBAThigh and VBATlow. VBATH flag and VBATL flags
  1626. in the PWR control register 2 (PWR_CR2), indicate if VBAT is higher or
  1627. lower than the threshold.
  1628. (+) The temperature can be monitored by comparing it with two threshold
  1629. levels, TEMPhigh and TEMPlow. TEMPH and TEMPL flags, in the PWR
  1630. control register 2 (PWR_CR2), indicate whether the device temperature
  1631. is higher or lower than the threshold.
  1632. (+) The VBAT and the temperature monitoring is enabled by
  1633. HAL_PWREx_EnableMonitoring() function and disabled by
  1634. HAL_PWREx_DisableMonitoring() function.
  1635. (+) The HAL_PWREx_GetVBATLevel() function returns the VBAT level which can
  1636. be : PWR_VBAT_BELOW_LOW_THRESHOLD or PWR_VBAT_ABOVE_HIGH_THRESHOLD or
  1637. PWR_VBAT_BETWEEN_HIGH_LOW_THRESHOLD.
  1638. (+) The HAL_PWREx_GetTemperatureLevel() function returns the Temperature
  1639. level which can be :
  1640. PWR_TEMP_BELOW_LOW_THRESHOLD or PWR_TEMP_ABOVE_HIGH_THRESHOLD or
  1641. PWR_TEMP_BETWEEN_HIGH_LOW_THRESHOLD.
  1642. *** AVD configuration ***
  1643. =========================
  1644. [..]
  1645. (+) The AVD is used to monitor the VDDA power supply by comparing it to a
  1646. threshold selected by the AVD Level (ALS[3:0] bits in the PWR_CR1
  1647. register).
  1648. (+) A AVDO flag is available to indicate if VDDA is higher or lower
  1649. than the AVD threshold. This event is internally connected to the EXTI
  1650. line 16 to generate an interrupt if enabled.
  1651. It is configurable through __HAL_PWR_AVD_EXTI_ENABLE_IT() macro.
  1652. (+) The AVD is stopped in System Standby mode.
  1653. @endverbatim
  1654. * @{
  1655. */
  1656. /**
  1657. * @brief Enable the VBAT and temperature monitoring.
  1658. * @retval HAL status.
  1659. */
  1660. void HAL_PWREx_EnableMonitoring (void)
  1661. {
  1662. /* Enable the VBAT and Temperature monitoring */
  1663. SET_BIT (PWR->CR2, PWR_CR2_MONEN);
  1664. }
  1665. /**
  1666. * @brief Disable the VBAT and temperature monitoring.
  1667. * @retval HAL status.
  1668. */
  1669. void HAL_PWREx_DisableMonitoring (void)
  1670. {
  1671. /* Disable the VBAT and Temperature monitoring */
  1672. CLEAR_BIT (PWR->CR2, PWR_CR2_MONEN);
  1673. }
  1674. /**
  1675. * @brief Indicate whether the junction temperature is between, above or below
  1676. * the thresholds.
  1677. * @retval Temperature level.
  1678. */
  1679. uint32_t HAL_PWREx_GetTemperatureLevel (void)
  1680. {
  1681. uint32_t tempLevel, regValue;
  1682. /* Read the temperature flags */
  1683. regValue = READ_BIT (PWR->CR2, (PWR_CR2_TEMPH | PWR_CR2_TEMPL));
  1684. /* Check if the temperature is below the threshold */
  1685. if (regValue == PWR_CR2_TEMPL)
  1686. {
  1687. tempLevel = PWR_TEMP_BELOW_LOW_THRESHOLD;
  1688. }
  1689. /* Check if the temperature is above the threshold */
  1690. else if (regValue == PWR_CR2_TEMPH)
  1691. {
  1692. tempLevel = PWR_TEMP_ABOVE_HIGH_THRESHOLD;
  1693. }
  1694. /* The temperature is between the thresholds */
  1695. else
  1696. {
  1697. tempLevel = PWR_TEMP_BETWEEN_HIGH_LOW_THRESHOLD;
  1698. }
  1699. return tempLevel;
  1700. }
  1701. /**
  1702. * @brief Indicate whether the Battery voltage level is between, above or below
  1703. * the thresholds.
  1704. * @retval VBAT level.
  1705. */
  1706. uint32_t HAL_PWREx_GetVBATLevel (void)
  1707. {
  1708. uint32_t VBATLevel, regValue;
  1709. /* Read the VBAT flags */
  1710. regValue = READ_BIT (PWR->CR2, (PWR_CR2_VBATH | PWR_CR2_VBATL));
  1711. /* Check if the VBAT is below the threshold */
  1712. if (regValue == PWR_CR2_VBATL)
  1713. {
  1714. VBATLevel = PWR_VBAT_BELOW_LOW_THRESHOLD;
  1715. }
  1716. /* Check if the VBAT is above the threshold */
  1717. else if (regValue == PWR_CR2_VBATH)
  1718. {
  1719. VBATLevel = PWR_VBAT_ABOVE_HIGH_THRESHOLD;
  1720. }
  1721. /* The VBAT is between the thresholds */
  1722. else
  1723. {
  1724. VBATLevel = PWR_VBAT_BETWEEN_HIGH_LOW_THRESHOLD;
  1725. }
  1726. return VBATLevel;
  1727. }
  1728. #if defined (PWR_CSR1_MMCVDO)
  1729. /**
  1730. * @brief Get the VDDMMC voltage level.
  1731. * @retval The VDDMMC voltage level.
  1732. */
  1733. PWREx_MMC_VoltageLevel HAL_PWREx_GetMMCVoltage (void)
  1734. {
  1735. PWREx_MMC_VoltageLevel mmc_voltage;
  1736. /* Check voltage detector output on VDDMMC value */
  1737. if ((PWR->CSR1 & PWR_CSR1_MMCVDO_Msk) == 0U)
  1738. {
  1739. mmc_voltage = PWR_MMC_VOLTAGE_BELOW_1V2;
  1740. }
  1741. else
  1742. {
  1743. mmc_voltage = PWR_MMC_VOLTAGE_EQUAL_ABOVE_1V2;
  1744. }
  1745. return mmc_voltage;
  1746. }
  1747. #endif /* defined (PWR_CSR1_MMCVDO) */
  1748. /**
  1749. * @brief Configure the event mode and the voltage threshold detected by the
  1750. * Analog Voltage Detector (AVD).
  1751. * @param sConfigAVD : Pointer to an PWREx_AVDTypeDef structure that contains
  1752. * the configuration information for the AVD.
  1753. * @note Refer to the electrical characteristics of your device datasheet for
  1754. * more details about the voltage threshold corresponding to each
  1755. * detection level.
  1756. * @note For dual core devices, please ensure to configure the EXTI lines for
  1757. * the different Cortex-Mx through PWR_Exported_Macro provided by this
  1758. * driver. All combination are allowed: wake up only Cortex-M7, wake up
  1759. * only Cortex-M4 and wake up Cortex-M7 and Cortex-M4.
  1760. * @retval None.
  1761. */
  1762. void HAL_PWREx_ConfigAVD (PWREx_AVDTypeDef *sConfigAVD)
  1763. {
  1764. /* Check the parameters */
  1765. assert_param (IS_PWR_AVD_LEVEL (sConfigAVD->AVDLevel));
  1766. assert_param (IS_PWR_AVD_MODE (sConfigAVD->Mode));
  1767. /* Set the ALS[18:17] bits according to AVDLevel value */
  1768. MODIFY_REG (PWR->CR1, PWR_CR1_ALS, sConfigAVD->AVDLevel);
  1769. /* Clear any previous config */
  1770. #if !defined (DUAL_CORE)
  1771. __HAL_PWR_AVD_EXTI_DISABLE_EVENT ();
  1772. __HAL_PWR_AVD_EXTI_DISABLE_IT ();
  1773. #endif /* !defined (DUAL_CORE) */
  1774. __HAL_PWR_AVD_EXTI_DISABLE_RISING_EDGE ();
  1775. __HAL_PWR_AVD_EXTI_DISABLE_FALLING_EDGE ();
  1776. #if !defined (DUAL_CORE)
  1777. /* Configure the interrupt mode */
  1778. if ((sConfigAVD->Mode & AVD_MODE_IT) == AVD_MODE_IT)
  1779. {
  1780. __HAL_PWR_AVD_EXTI_ENABLE_IT ();
  1781. }
  1782. /* Configure the event mode */
  1783. if ((sConfigAVD->Mode & AVD_MODE_EVT) == AVD_MODE_EVT)
  1784. {
  1785. __HAL_PWR_AVD_EXTI_ENABLE_EVENT ();
  1786. }
  1787. #endif /* !defined (DUAL_CORE) */
  1788. /* Rising edge configuration */
  1789. if ((sConfigAVD->Mode & AVD_RISING_EDGE) == AVD_RISING_EDGE)
  1790. {
  1791. __HAL_PWR_AVD_EXTI_ENABLE_RISING_EDGE ();
  1792. }
  1793. /* Falling edge configuration */
  1794. if ((sConfigAVD->Mode & AVD_FALLING_EDGE) == AVD_FALLING_EDGE)
  1795. {
  1796. __HAL_PWR_AVD_EXTI_ENABLE_FALLING_EDGE ();
  1797. }
  1798. }
  1799. /**
  1800. * @brief Enable the Analog Voltage Detector (AVD).
  1801. * @retval None.
  1802. */
  1803. void HAL_PWREx_EnableAVD (void)
  1804. {
  1805. /* Enable the Analog Voltage Detector */
  1806. SET_BIT (PWR->CR1, PWR_CR1_AVDEN);
  1807. }
  1808. /**
  1809. * @brief Disable the Analog Voltage Detector(AVD).
  1810. * @retval None.
  1811. */
  1812. void HAL_PWREx_DisableAVD (void)
  1813. {
  1814. /* Disable the Analog Voltage Detector */
  1815. CLEAR_BIT (PWR->CR1, PWR_CR1_AVDEN);
  1816. }
  1817. /**
  1818. * @brief This function handles the PWR PVD/AVD interrupt request.
  1819. * @note This API should be called under the PVD_AVD_IRQHandler().
  1820. * @retval None
  1821. */
  1822. void HAL_PWREx_PVD_AVD_IRQHandler (void)
  1823. {
  1824. /* Check if the Programmable Voltage Detector is enabled (PVD) */
  1825. if (READ_BIT (PWR->CR1, PWR_CR1_PVDEN) != 0U)
  1826. {
  1827. #if defined (DUAL_CORE)
  1828. if (HAL_GetCurrentCPUID () == CM7_CPUID)
  1829. #endif /* defined (DUAL_CORE) */
  1830. {
  1831. /* Check PWR D1/CD EXTI flag */
  1832. if (__HAL_PWR_PVD_EXTI_GET_FLAG () != 0U)
  1833. {
  1834. /* PWR PVD interrupt user callback */
  1835. HAL_PWR_PVDCallback ();
  1836. /* Clear PWR EXTI D1/CD pending bit */
  1837. __HAL_PWR_PVD_EXTI_CLEAR_FLAG ();
  1838. }
  1839. }
  1840. #if defined (DUAL_CORE)
  1841. else
  1842. {
  1843. /* Check PWR EXTI D2 flag */
  1844. if (__HAL_PWR_PVD_EXTID2_GET_FLAG () != 0U)
  1845. {
  1846. /* PWR PVD interrupt user callback */
  1847. HAL_PWR_PVDCallback ();
  1848. /* Clear PWR EXTI D2 pending bit */
  1849. __HAL_PWR_PVD_EXTID2_CLEAR_FLAG();
  1850. }
  1851. }
  1852. #endif /* defined (DUAL_CORE) */
  1853. }
  1854. /* Check if the Analog Voltage Detector is enabled (AVD) */
  1855. if (READ_BIT (PWR->CR1, PWR_CR1_AVDEN) != 0U)
  1856. {
  1857. #if defined (DUAL_CORE)
  1858. if (HAL_GetCurrentCPUID () == CM7_CPUID)
  1859. #endif /* defined (DUAL_CORE) */
  1860. {
  1861. /* Check PWR EXTI D1/CD flag */
  1862. if (__HAL_PWR_AVD_EXTI_GET_FLAG () != 0U)
  1863. {
  1864. /* PWR AVD interrupt user callback */
  1865. HAL_PWREx_AVDCallback ();
  1866. /* Clear PWR EXTI D1/CD pending bit */
  1867. __HAL_PWR_AVD_EXTI_CLEAR_FLAG ();
  1868. }
  1869. }
  1870. #if defined (DUAL_CORE)
  1871. else
  1872. {
  1873. /* Check PWR EXTI D2 flag */
  1874. if (__HAL_PWR_AVD_EXTID2_GET_FLAG () != 0U)
  1875. {
  1876. /* PWR AVD interrupt user callback */
  1877. HAL_PWREx_AVDCallback ();
  1878. /* Clear PWR EXTI D2 pending bit */
  1879. __HAL_PWR_AVD_EXTID2_CLEAR_FLAG ();
  1880. }
  1881. }
  1882. #endif /* defined (DUAL_CORE) */
  1883. }
  1884. }
  1885. /**
  1886. * @brief PWR AVD interrupt callback.
  1887. * @retval None.
  1888. */
  1889. __weak void HAL_PWREx_AVDCallback (void)
  1890. {
  1891. /* NOTE : This function should not be modified, when the callback is needed,
  1892. the HAL_PWR_AVDCallback can be implemented in the user file
  1893. */
  1894. }
  1895. /**
  1896. * @}
  1897. */
  1898. /**
  1899. * @}
  1900. */
  1901. #endif /* HAL_PWR_MODULE_ENABLED */
  1902. /**
  1903. * @}
  1904. */
  1905. /**
  1906. * @}
  1907. */