stm32h7xx_hal_pwr.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_pwr.c
  4. * @author MCD Application Team
  5. * @brief PWR HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Power Controller (PWR) peripheral:
  8. * + Initialization and de-initialization functions.
  9. * + Peripheral Control functions.
  10. * + Interrupt Handling functions.
  11. ******************************************************************************
  12. * @attention
  13. *
  14. * Copyright (c) 2017 STMicroelectronics.
  15. * All rights reserved.
  16. *
  17. * This software is licensed under terms that can be found in the LICENSE file
  18. * in the root directory of this software component.
  19. * If no LICENSE file comes with this software, it is provided AS-IS.
  20. *
  21. ******************************************************************************
  22. @verbatim
  23. ==============================================================================
  24. ##### PWR peripheral overview #####
  25. ==============================================================================
  26. [..]
  27. (#) The Power control (PWR) provides an overview of the supply architecture
  28. for the different power domains and of the supply configuration
  29. controller.
  30. In the H7 family, the number of power domains is different between
  31. device lines. This difference is due to characteristics of each device.
  32. (#) Domain architecture overview for the different H7 lines:
  33. (+) Dual core lines are STM32H745, STM32H747, STM32H755 and STM32H757.
  34. These devices have 3 power domains (D1, D2 and D3).
  35. The domain D1 contains a CPU (Cortex-M7), a Flash memory and some
  36. peripherals. The D2 domain contains peripherals and a CPU
  37. (Cortex-M4). The D3 domain contains the system control, I/O logic
  38. and low-power peripherals.
  39. (+) STM32H72x, STM32H73x, STM32H742, STM32H743, STM32H750 and STM32H753
  40. devices have 3 power domains (D1, D2 and D3).
  41. The domain D1 contains a CPU (Cortex-M7), a Flash memory and some
  42. peripherals. The D2 domain contains peripherals. The D3 domains
  43. contains the system control, I/O logic and low-power peripherals.
  44. (+) STM32H7Axxx and STM32H7Bxxx devices have 2 power domains (CD and SRD).
  45. The core domain (CD) contains a CPU (Cortex-M7), a Flash
  46. memory and peripherals. The SmartRun domain contains the system
  47. control, I/O logic and low-power peripherals.
  48. (#) Every entity have low power mode as described below :
  49. (#) The CPU low power modes are :
  50. (+) CPU CRUN.
  51. (+) CPU CSLEEP.
  52. (+) CPU CSTOP.
  53. (#) The domain low power modes are :
  54. (+) DRUN.
  55. (+) DSTOP.
  56. (+) DSTANDBY.
  57. (#) The SYSTEM low power modes are :
  58. (+) RUN* : The Run* mode is entered after a POR reset and a wakeup from
  59. Standby. In Run* mode, the performance is limited and the
  60. system supply configuration shall be programmed. The system
  61. enters Run mode only when the ACTVOSRDY bit in PWR control
  62. status register 1 (PWR_CSR1) is set to 1.
  63. (+) RUN.
  64. (+) STOP.
  65. (+) STANDBY.
  66. ==============================================================================
  67. ##### How to use this driver #####
  68. ==============================================================================
  69. [..]
  70. (#) Power management peripheral is active by default at startup level in
  71. STM32h7xx lines.
  72. (#) Call HAL_PWR_EnableBkUpAccess() and HAL_PWR_DisableBkUpAccess() functions
  73. to enable/disable access to the backup domain (RTC registers, RTC backup
  74. data registers and backup SRAM).
  75. (#) Call HAL_PWR_ConfigPVD() after setting parameters to be configured (event
  76. mode and voltage threshold) in order to set up the Power Voltage Detector,
  77. then use HAL_PWR_EnablePVD() and HAL_PWR_DisablePVD() functions to start
  78. and stop the PVD detection.
  79. (+) PVD level could be one of the following values :
  80. (++) 1V95
  81. (++) 2V1
  82. (++) 2V25
  83. (++) 2V4
  84. (++) 2V55
  85. (++) 2V7
  86. (++) 2V85
  87. (++) External voltage level
  88. (#) Call HAL_PWR_EnableWakeUpPin() and HAL_PWR_DisableWakeUpPin() functions
  89. with the right parameter to configure the wake up pin polarity (Low or
  90. High) and to enable and disable it.
  91. (#) Call HAL_PWR_EnterSLEEPMode() function to enter the current Core in SLEEP
  92. mode. Wake-up from SLEEP mode could be following to an event or an
  93. interrupt according to low power mode intrinsic request called (__WFI()
  94. or __WFE()).
  95. Please ensure to clear all CPU pending events by calling
  96. HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx
  97. in SLEEP mode with __WFE() entry.
  98. (#) Call HAL_PWR_EnterSTOPMode() function to enter the whole system to Stop 0
  99. mode for single core devices. For dual core devices, this API will enter
  100. the domain (containing Cortex-Mx that executing this function) in DSTOP
  101. mode. According to the used parameter, user could select the regulator to
  102. be kept actif in low power mode and wake-up event type.
  103. Please ensure to clear all CPU pending events by calling
  104. HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx
  105. in CSTOP mode with __WFE() entry.
  106. (#) Call HAL_PWR_EnterSTANDBYMode() function to enter the whole system in
  107. STANDBY mode for single core devices. For dual core devices, this API
  108. will enter the domain (containing Cortex-Mx that executing this function)
  109. in DSTANDBY mode.
  110. (#) Call HAL_PWR_EnableSleepOnExit() and HAL_PWR_DisableSleepOnExit() APIs to
  111. enable and disable the Cortex-Mx re-entring in SLEEP mode after an
  112. interruption handling is over.
  113. (#) Call HAL_PWR_EnableSEVOnPend() and HAL_PWR_DisableSEVOnPend() functions
  114. to configure the Cortex-Mx to wake-up after any pending event / interrupt
  115. even if it's disabled or has insufficient priority to cause exception
  116. entry.
  117. (#) Call HAL_PWR_PVD_IRQHandler() function to handle the PWR PVD interrupt
  118. request.
  119. *** PWR HAL driver macros list ***
  120. =============================================
  121. [..]
  122. Below the list of most used macros in PWR HAL driver.
  123. (+) __HAL_PWR_VOLTAGESCALING_CONFIG() : Configure the main internal
  124. regulator output voltage.
  125. (+) __HAL_PWR_GET_FLAG() : Get the PWR pending flags.
  126. (+) __HAL_PWR_CLEAR_FLAG() : Clear the PWR pending flags.
  127. @endverbatim
  128. */
  129. /* Includes ------------------------------------------------------------------*/
  130. #include "stm32h7xx_hal.h"
  131. /** @addtogroup STM32H7xx_HAL_Driver
  132. * @{
  133. */
  134. /** @defgroup PWR PWR
  135. * @brief PWR HAL module driver
  136. * @{
  137. */
  138. #ifdef HAL_PWR_MODULE_ENABLED
  139. /* Private typedef -----------------------------------------------------------*/
  140. /* Private define ------------------------------------------------------------*/
  141. /** @addtogroup PWR_Private_Constants PWR Private Constants
  142. * @{
  143. */
  144. /** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask
  145. * @{
  146. */
  147. #if !defined (DUAL_CORE)
  148. #define PVD_MODE_IT (0x00010000U)
  149. #define PVD_MODE_EVT (0x00020000U)
  150. #endif /* !defined (DUAL_CORE) */
  151. #define PVD_RISING_EDGE (0x00000001U)
  152. #define PVD_FALLING_EDGE (0x00000002U)
  153. #define PVD_RISING_FALLING_EDGE (0x00000003U)
  154. /**
  155. * @}
  156. */
  157. /**
  158. * @}
  159. */
  160. /* Private macro -------------------------------------------------------------*/
  161. /* Private variables ---------------------------------------------------------*/
  162. /* Private function prototypes -----------------------------------------------*/
  163. /* Private functions ---------------------------------------------------------*/
  164. /** @defgroup PWR_Exported_Functions PWR Exported Functions
  165. * @{
  166. */
  167. /** @defgroup PWR_Exported_Functions_Group1 Initialization and De-Initialization Functions
  168. * @brief Initialization and De-Initialization functions
  169. *
  170. @verbatim
  171. ===============================================================================
  172. ##### Initialization and De-Initialization Functions #####
  173. ===============================================================================
  174. [..]
  175. This section provides functions allowing to deinitialize power peripheral.
  176. [..]
  177. After system reset, the backup domain (RTC registers, RTC backup data
  178. registers and backup SRAM) is protected against possible unwanted write
  179. accesses.
  180. The HAL_PWR_EnableBkUpAccess() function enables the access to the backup
  181. domain.
  182. The HAL_PWR_DisableBkUpAccess() function disables the access to the backup
  183. domain.
  184. @endverbatim
  185. * @{
  186. */
  187. /**
  188. * @brief Deinitialize the HAL PWR peripheral registers to their default reset
  189. * values.
  190. * @note This functionality is not available in this product.
  191. * The prototype is kept just to maintain compatibility with other
  192. * products.
  193. * @retval None.
  194. */
  195. void HAL_PWR_DeInit (void)
  196. {
  197. }
  198. /**
  199. * @brief Enable access to the backup domain (RTC registers, RTC backup data
  200. * registers and backup SRAM).
  201. * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
  202. * Backup Domain Access should be kept enabled.
  203. * @retval None.
  204. */
  205. void HAL_PWR_EnableBkUpAccess (void)
  206. {
  207. /* Enable access to RTC and backup registers */
  208. SET_BIT (PWR->CR1, PWR_CR1_DBP);
  209. }
  210. /**
  211. * @brief Disable access to the backup domain (RTC registers, RTC backup data
  212. * registers and backup SRAM).
  213. * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
  214. * Backup Domain Access should be kept enabled.
  215. * @retval None.
  216. */
  217. void HAL_PWR_DisableBkUpAccess (void)
  218. {
  219. /* Disable access to RTC and backup registers */
  220. CLEAR_BIT (PWR->CR1, PWR_CR1_DBP);
  221. }
  222. /**
  223. * @}
  224. */
  225. /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control Functions
  226. * @brief Power Control functions
  227. *
  228. @verbatim
  229. ===============================================================================
  230. ##### Peripheral Control Functions #####
  231. ===============================================================================
  232. [..]
  233. This section provides functions allowing to control power peripheral.
  234. *** PVD configuration ***
  235. =========================
  236. [..]
  237. (+) The PVD is used to monitor the VDD power supply by comparing it to a
  238. threshold selected by the PVD Level (PLS[7:0] bits in the PWR_CR1
  239. register).
  240. (+) A PVDO flag is available to indicate if VDD is higher or lower
  241. than the PVD threshold. This event is internally connected to the EXTI
  242. line 16 to generate an interrupt if enabled.
  243. It is configurable through __HAL_PWR_PVD_EXTI_ENABLE_IT() macro.
  244. (+) The PVD is stopped in STANDBY mode.
  245. *** Wake-up pin configuration ***
  246. =================================
  247. [..]
  248. (+) Wake-up pin is used to wake up the system from STANDBY mode.
  249. The pin pull is configurable through the WKUPEPR register to be in
  250. No-pull, Pull-up and Pull-down.
  251. The pin polarity is configurable through the WKUPEPR register to be
  252. active on rising or falling edges.
  253. (+) There are up to six Wake-up pin in the STM32H7 devices family.
  254. *** Low Power modes configuration ***
  255. =====================================
  256. [..]
  257. The device present 3 principles low-power modes features:
  258. (+) SLEEP mode : Cortex-Mx is stopped and all PWR domains are remaining
  259. active (Powered and Clocked).
  260. (+) STOP mode : Cortex-Mx is stopped, clocks are stopped and the
  261. regulator is running. The Main regulator or the LP
  262. regulator could be selected.
  263. (+) STANDBY mode : All PWR domains enter DSTANDBY mode and the VCORE
  264. supply regulator is powered off.
  265. *** SLEEP mode ***
  266. ==================
  267. [..]
  268. (+) Entry:
  269. The SLEEP mode is entered by using the HAL_PWR_EnterSLEEPMode(Regulator,
  270. SLEEPEntry) function.
  271. (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction.
  272. (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction.
  273. -@@- The Regulator parameter is not used for the STM32H7 family
  274. and is kept as parameter just to maintain compatibility with the
  275. lower power families (STM32L).
  276. (+) Exit:
  277. Any peripheral interrupt acknowledged by the nested vectored interrupt
  278. controller (NVIC) can wake up the device from SLEEP mode.
  279. *** STOP mode ***
  280. =================
  281. [..]
  282. In system STOP mode, all clocks in the 1.2V domain are stopped, the PLL,
  283. the HSI, and the HSE RC oscillators are disabled. Internal SRAM and
  284. register contents are preserved.
  285. The voltage regulator can be configured either in normal or low-power mode.
  286. To minimize the consumption in STOP mode, FLASH can be powered off before
  287. entering the STOP mode using the HAL_PWREx_EnableFlashPowerDown() function.
  288. It can be switched on again by software after exiting the STOP mode using
  289. the HAL_PWREx_DisableFlashPowerDown() function.
  290. (+) Entry:
  291. The STOP mode is entered using the HAL_PWR_EnterSTOPMode(Regulator,
  292. STOPEntry) function with:
  293. (++) Regulator:
  294. (+++) PWR_MAINREGULATOR_ON: Main regulator ON.
  295. (+++) PWR_LOWPOWERREGULATOR_ON: Low Power regulator ON.
  296. (++) STOPEntry:
  297. (+++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction.
  298. (+++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction.
  299. (+) Exit:
  300. Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
  301. *** STANDBY mode ***
  302. ====================
  303. [..]
  304. (+)
  305. The system STANDBY mode allows to achieve the lowest power consumption.
  306. It is based on the Cortex-Mx deep SLEEP mode, with the voltage regulator
  307. disabled. The system is consequently powered off. The PLL, the HSI
  308. oscillator and the HSE oscillator are also switched off. SRAM and register
  309. contents are lost except for the RTC registers, RTC backup registers,
  310. backup SRAM and standby circuitry.
  311. [..]
  312. The voltage regulator is OFF.
  313. (++) Entry:
  314. (+++) The STANDBY mode is entered using the HAL_PWR_EnterSTANDBYMode()
  315. function.
  316. (++) Exit:
  317. (+++) WKUP pin rising or falling edge, RTC alarm (Alarm A and Alarm B),
  318. RTC wakeup, tamper event, time stamp event, external reset in NRST
  319. pin, IWDG reset.
  320. *** Auto-wakeup (AWU) from low-power mode ***
  321. =============================================
  322. [..]
  323. (+) The MCU can be woken up from low-power mode by an RTC Alarm event, an
  324. RTC Wakeup event, a tamper event or a time-stamp event, without
  325. depending on an external interrupt (Auto-wakeup mode).
  326. (+) RTC auto-wakeup (AWU) from the STOP and STANDBY modes
  327. (++) To wake up from the STOP mode with an RTC alarm event, it is
  328. necessary to configure the RTC to generate the RTC alarm using the
  329. HAL_RTC_SetAlarm_IT() function.
  330. (++) To wake up from the STOP mode with an RTC Tamper or time stamp event,
  331. it is necessary to configure the RTC to detect the tamper or time
  332. stamp event using the HAL_RTCEx_SetTimeStamp_IT() or
  333. HAL_RTCEx_SetTamper_IT() functions.
  334. (++) To wake up from the STOP mode with an RTC WakeUp event, it is
  335. necessary to configure the RTC to generate the RTC WakeUp event
  336. using the HAL_RTCEx_SetWakeUpTimer_IT() function.
  337. @endverbatim
  338. * @{
  339. */
  340. /**
  341. * @brief Configure the event mode and the voltage threshold detected by the
  342. * Programmable Voltage Detector(PVD).
  343. * @param sConfigPVD : Pointer to an PWR_PVDTypeDef structure that contains
  344. * the configuration information for the PVD.
  345. * @note Refer to the electrical characteristics of your device datasheet for
  346. * more details about the voltage threshold corresponding to each
  347. * detection level.
  348. * @note For dual core devices, please ensure to configure the EXTI lines for
  349. * the different Cortex-Mx through PWR_Exported_Macro provided by this
  350. * driver. All combination are allowed: wake up only Cortex-M7, wake up
  351. * only Cortex-M4 or wake up Cortex-M7 and Cortex-M4.
  352. * @retval None.
  353. */
  354. void HAL_PWR_ConfigPVD (PWR_PVDTypeDef *sConfigPVD)
  355. {
  356. /* Check the PVD configuration parameter */
  357. if (sConfigPVD == NULL)
  358. {
  359. return;
  360. }
  361. /* Check the parameters */
  362. assert_param (IS_PWR_PVD_LEVEL (sConfigPVD->PVDLevel));
  363. assert_param (IS_PWR_PVD_MODE (sConfigPVD->Mode));
  364. /* Set PLS[7:5] bits according to PVDLevel value */
  365. MODIFY_REG (PWR->CR1, PWR_CR1_PLS, sConfigPVD->PVDLevel);
  366. /* Clear previous config */
  367. #if !defined (DUAL_CORE)
  368. __HAL_PWR_PVD_EXTI_DISABLE_EVENT ();
  369. __HAL_PWR_PVD_EXTI_DISABLE_IT ();
  370. #endif /* !defined (DUAL_CORE) */
  371. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE ();
  372. __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE ();
  373. #if !defined (DUAL_CORE)
  374. /* Interrupt mode configuration */
  375. if ((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
  376. {
  377. __HAL_PWR_PVD_EXTI_ENABLE_IT ();
  378. }
  379. /* Event mode configuration */
  380. if ((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
  381. {
  382. __HAL_PWR_PVD_EXTI_ENABLE_EVENT ();
  383. }
  384. #endif /* !defined (DUAL_CORE) */
  385. /* Rising edge configuration */
  386. if ((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
  387. {
  388. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE ();
  389. }
  390. /* Falling edge configuration */
  391. if ((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
  392. {
  393. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE ();
  394. }
  395. }
  396. /**
  397. * @brief Enable the Programmable Voltage Detector (PVD).
  398. * @retval None.
  399. */
  400. void HAL_PWR_EnablePVD (void)
  401. {
  402. /* Enable the power voltage detector */
  403. SET_BIT (PWR->CR1, PWR_CR1_PVDEN);
  404. }
  405. /**
  406. * @brief Disable the Programmable Voltage Detector (PVD).
  407. * @retval None.
  408. */
  409. void HAL_PWR_DisablePVD (void)
  410. {
  411. /* Disable the power voltage detector */
  412. CLEAR_BIT (PWR->CR1, PWR_CR1_PVDEN);
  413. }
  414. /**
  415. * @brief Enable the WakeUp PINx functionality.
  416. * @param WakeUpPinPolarity : Specifies which Wake-Up pin to enable.
  417. * This parameter can be one of the following legacy values, which
  418. * sets the default (rising edge):
  419. * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3,
  420. * PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6.
  421. * or one of the following values where the user can explicitly states
  422. * the enabled pin and the chosen polarity:
  423. * @arg PWR_WAKEUP_PIN1_HIGH, PWR_WAKEUP_PIN1_LOW,
  424. * PWR_WAKEUP_PIN2_HIGH, PWR_WAKEUP_PIN2_LOW,
  425. * PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW,
  426. * PWR_WAKEUP_PIN4_HIGH, PWR_WAKEUP_PIN4_LOW,
  427. * PWR_WAKEUP_PIN5_HIGH, PWR_WAKEUP_PIN5_LOW,
  428. * PWR_WAKEUP_PIN6_HIGH, PWR_WAKEUP_PIN6_LOW.
  429. * @note PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent.
  430. * @note The PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, PWR_WAKEUP_PIN5_HIGH
  431. * and PWR_WAKEUP_PIN5_LOW are available only for devices that includes
  432. * GPIOI port.
  433. * @retval None.
  434. */
  435. void HAL_PWR_EnableWakeUpPin (uint32_t WakeUpPinPolarity)
  436. {
  437. /* Check the parameters */
  438. assert_param (IS_PWR_WAKEUP_PIN (WakeUpPinPolarity));
  439. /*
  440. Enable and Specify the Wake-Up pin polarity and the pull configuration
  441. for the event detection (rising or falling edge).
  442. */
  443. MODIFY_REG (PWR->WKUPEPR, PWR_EWUP_MASK, WakeUpPinPolarity);
  444. }
  445. /**
  446. * @brief Disable the WakeUp PINx functionality.
  447. * @param WakeUpPinx : Specifies the Power Wake-Up pin to disable.
  448. * This parameter can be one of the following values:
  449. * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3,
  450. * PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6,
  451. * PWR_WAKEUP_PIN1_HIGH, PWR_WAKEUP_PIN1_LOW,
  452. * PWR_WAKEUP_PIN2_HIGH, PWR_WAKEUP_PIN2_LOW,
  453. * PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW,
  454. * PWR_WAKEUP_PIN4_HIGH, PWR_WAKEUP_PIN4_LOW,
  455. * PWR_WAKEUP_PIN5_HIGH, PWR_WAKEUP_PIN5_LOW,
  456. * PWR_WAKEUP_PIN6_HIGH, PWR_WAKEUP_PIN6_LOW.
  457. * @note The PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, PWR_WAKEUP_PIN5_HIGH
  458. * and PWR_WAKEUP_PIN5_LOW are available only for devices that includes
  459. * GPIOI port.
  460. * @retval None.
  461. */
  462. void HAL_PWR_DisableWakeUpPin (uint32_t WakeUpPinx)
  463. {
  464. /* Check the parameters */
  465. assert_param (IS_PWR_WAKEUP_PIN (WakeUpPinx));
  466. /* Disable the wake up pin selected */
  467. CLEAR_BIT (PWR->WKUPEPR, (PWR_WKUPEPR_WKUPEN & WakeUpPinx));
  468. }
  469. /**
  470. * @brief Enter the current core in SLEEP mode (CSLEEP).
  471. * @param Regulator : Specifies the regulator state in SLEEP mode.
  472. * This parameter can be one of the following values:
  473. * @arg PWR_MAINREGULATOR_ON : SLEEP mode with regulator ON.
  474. * @arg PWR_LOWPOWERREGULATOR_ON : SLEEP mode with low power
  475. * regulator ON.
  476. * @note This parameter is not used for the STM32H7 family and is kept as
  477. * parameter just to maintain compatibility with the lower power
  478. * families.
  479. * @param SLEEPEntry : Specifies if SLEEP mode is entered with WFI or WFE
  480. * intrinsic instruction.
  481. * This parameter can be one of the following values:
  482. * @arg PWR_SLEEPENTRY_WFI : enter SLEEP mode with WFI instruction.
  483. * @arg PWR_SLEEPENTRY_WFE : enter SLEEP mode with WFE instruction.
  484. * @note Ensure to clear pending events before calling this API through
  485. * HAL_PWREx_ClearPendingEvent() when the SLEEP entry is WFE.
  486. * @retval None.
  487. */
  488. void HAL_PWR_EnterSLEEPMode (uint32_t Regulator, uint8_t SLEEPEntry)
  489. {
  490. /* Check the parameters */
  491. assert_param (IS_PWR_REGULATOR (Regulator));
  492. assert_param (IS_PWR_SLEEP_ENTRY (SLEEPEntry));
  493. /* Clear SLEEPDEEP bit of Cortex System Control Register */
  494. CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  495. /* Select SLEEP mode entry */
  496. if (SLEEPEntry == PWR_SLEEPENTRY_WFI)
  497. {
  498. /* Request Wait For Interrupt */
  499. __WFI ();
  500. }
  501. else
  502. {
  503. /* Request Wait For Event */
  504. __WFE ();
  505. }
  506. }
  507. /**
  508. * @brief Enter STOP mode.
  509. * @note For single core devices, this API will enter the system in STOP mode
  510. * with all domains in DSTOP, if RUN_D3/RUN_SRD bit in CPUCR register is
  511. * cleared.
  512. * For dual core devices, this API will enter the domain (containing
  513. * Cortex-Mx that executing this function) in DSTOP mode. If all
  514. * Cortex-Mx domains are in DSTOP and RUN_D3 bit in CPUCR register is
  515. * cleared, all the system will enter in STOP mode.
  516. * @param Regulator : Specifies the regulator state in STOP mode.
  517. * This parameter can be one of the following values:
  518. * @arg PWR_MAINREGULATOR_ON : STOP mode with regulator ON.
  519. * @arg PWR_LOWPOWERREGULATOR_ON : STOP mode with low power
  520. * regulator ON.
  521. * @param STOPEntry : Specifies if STOP mode in entered with WFI or WFE
  522. * intrinsic instruction.
  523. * This parameter can be one of the following values:
  524. * @arg PWR_STOPENTRY_WFI : Enter STOP mode with WFI instruction.
  525. * @arg PWR_STOPENTRY_WFE : Enter STOP mode with WFE instruction.
  526. * @note In System STOP mode, all I/O pins keep the same state as in Run mode.
  527. * @note When exiting System STOP mode by issuing an interrupt or a wakeup
  528. * event, the HSI RC oscillator is selected as default system wakeup
  529. * clock.
  530. * @note In System STOP mode, when the voltage regulator operates in low
  531. * power mode, an additional startup delay is incurred when the system
  532. * is waking up. By keeping the internal regulator ON during STOP mode,
  533. * the consumption is higher although the startup time is reduced.
  534. * @retval None.
  535. */
  536. void HAL_PWR_EnterSTOPMode (uint32_t Regulator, uint8_t STOPEntry)
  537. {
  538. /* Check the parameters */
  539. assert_param (IS_PWR_REGULATOR (Regulator));
  540. assert_param (IS_PWR_STOP_ENTRY (STOPEntry));
  541. /* Select the regulator state in STOP mode */
  542. MODIFY_REG (PWR->CR1, PWR_CR1_LPDS, Regulator);
  543. /* Configure the PWR mode for the different Domains */
  544. #if defined (DUAL_CORE)
  545. /* Check CPU ID */
  546. if (HAL_GetCurrentCPUID () == CM7_CPUID)
  547. {
  548. /* Keep DSTOP mode when Cortex-M7 enters DEEP-SLEEP */
  549. CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
  550. }
  551. else
  552. {
  553. /* Keep DSTOP mode when Cortex-M4 enters DEEP-SLEEP */
  554. CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D2 | PWR_CPUCR_PDDS_D3));
  555. }
  556. #else /* Single core devices */
  557. /* Keep DSTOP mode when Cortex-M7 enter in DEEP-SLEEP */
  558. CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
  559. #if defined (PWR_CPUCR_PDDS_D2)
  560. /* Keep DSTOP mode when Cortex-M7 enter in DEEP-SLEEP */
  561. CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D2);
  562. #endif /* PWR_CPUCR_PDDS_D2 */
  563. #endif /* defined (DUAL_CORE) */
  564. /* Set SLEEPDEEP bit of Cortex System Control Register */
  565. SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  566. /* Ensure that all instructions are done before entering STOP mode */
  567. __DSB ();
  568. __ISB ();
  569. /* Select STOP mode entry */
  570. if (STOPEntry == PWR_STOPENTRY_WFI)
  571. {
  572. /* Request Wait For Interrupt */
  573. __WFI ();
  574. }
  575. else
  576. {
  577. /* Request Wait For Event */
  578. __WFE ();
  579. }
  580. /* Clear SLEEPDEEP bit of Cortex-Mx in the System Control Register */
  581. CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  582. }
  583. /**
  584. * @brief Enter STANDBY mode.
  585. * @note For single core devices, this API will enter the system in STANDBY
  586. * mode with all domains in DSTANDBY, if RUN_D3/RUN_SRD bit in CPUCR
  587. * register is cleared.
  588. * For dual core devices, this API will enter the domain (containing
  589. * Cortex-Mx that executing this function) in DSTANDBY mode. If all
  590. * Cortex-Mx domains are in DSTANDBY and RUN_D3 bit in CPUCR register
  591. * is cleared, all the system will enter in STANDBY mode.
  592. * @note The system enters Standby mode only when all domains are in DSTANDBY.
  593. * @note When the System exit STANDBY mode by issuing an interrupt or a
  594. * wakeup event, the HSI RC oscillator is selected as system clock.
  595. * @note It is recommended to disable all regulators before entring STANDBY
  596. * mode for power consumption saving purpose.
  597. * @retval None.
  598. */
  599. void HAL_PWR_EnterSTANDBYMode (void)
  600. {
  601. /* Configure the PWR mode for the different Domains */
  602. #if defined (DUAL_CORE)
  603. /* Check CPU ID */
  604. if (HAL_GetCurrentCPUID () == CM7_CPUID)
  605. {
  606. /* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */
  607. SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
  608. SET_BIT (PWR->CPU2CR, (PWR_CPU2CR_PDDS_D1 | PWR_CPU2CR_PDDS_D3));
  609. }
  610. else
  611. {
  612. /* Enter DSTANDBY mode when Cortex-M4 enters DEEP-SLEEP */
  613. SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D2 | PWR_CPUCR_PDDS_D3));
  614. SET_BIT (PWR->CPU2CR, (PWR_CPU2CR_PDDS_D2 | PWR_CPU2CR_PDDS_D3));
  615. }
  616. #else /* Single core devices */
  617. /* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */
  618. SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3));
  619. #if defined (PWR_CPUCR_PDDS_D2)
  620. /* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */
  621. SET_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D2);
  622. #endif /* PWR_CPUCR_PDDS_D2 */
  623. #endif /* defined (DUAL_CORE) */
  624. /* Set SLEEPDEEP bit of Cortex System Control Register */
  625. SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  626. /* Ensure that all instructions are done before entering STOP mode */
  627. __DSB ();
  628. __ISB ();
  629. /* This option is used to ensure that store operations are completed */
  630. #if defined (__CC_ARM)
  631. __force_stores();
  632. #endif /* defined (__CC_ARM) */
  633. /* Request Wait For Interrupt */
  634. __WFI ();
  635. }
  636. /**
  637. * @brief Indicate Sleep-On-Exit feature when returning from Handler mode to
  638. * Thread mode.
  639. * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the
  640. * processor re-enters SLEEP mode when an interruption handling is over.
  641. * Setting this bit is useful when the processor is expected to run
  642. * only on interruptions handling.
  643. * @retval None.
  644. */
  645. void HAL_PWR_EnableSleepOnExit (void)
  646. {
  647. /* Set SLEEPONEXIT bit of Cortex-Mx System Control Register */
  648. SET_BIT (SCB->SCR, SCB_SCR_SLEEPONEXIT_Msk);
  649. }
  650. /**
  651. * @brief Disable Sleep-On-Exit feature when returning from Handler mode to
  652. * Thread mode.
  653. * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the
  654. * processor re-enters SLEEP mode when an interruption handling is over.
  655. * @retval None
  656. */
  657. void HAL_PWR_DisableSleepOnExit (void)
  658. {
  659. /* Clear SLEEPONEXIT bit of Cortex-Mx System Control Register */
  660. CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPONEXIT_Msk);
  661. }
  662. /**
  663. * @brief Enable CORTEX SEVONPEND feature.
  664. * @note Sets SEVONPEND bit of SCR register. When this bit is set, any
  665. * pending event / interrupt even if it's disabled or has insufficient
  666. * priority to cause exception entry wakes up the Cortex-Mx.
  667. * @retval None.
  668. */
  669. void HAL_PWR_EnableSEVOnPend (void)
  670. {
  671. /* Set SEVONPEND bit of Cortex-Mx System Control Register */
  672. SET_BIT (SCB->SCR, SCB_SCR_SEVONPEND_Msk);
  673. }
  674. /**
  675. * @brief Disable CORTEX SEVONPEND feature.
  676. * @note Resets SEVONPEND bit of SCR register. When this bit is reset, only
  677. * enabled pending causes exception entry wakes up the Cortex-Mx.
  678. * @retval None.
  679. */
  680. void HAL_PWR_DisableSEVOnPend (void)
  681. {
  682. /* Clear SEVONPEND bit of Cortex System Control Register */
  683. CLEAR_BIT (SCB->SCR, SCB_SCR_SEVONPEND_Msk);
  684. }
  685. /**
  686. * @}
  687. */
  688. /** @defgroup PWR_Exported_Functions_Group3 Interrupt Handling Functions
  689. * @brief Interrupt Handling functions
  690. *
  691. @verbatim
  692. ===============================================================================
  693. ##### Interrupt Handling Functions #####
  694. ===============================================================================
  695. [..]
  696. This section provides functions allowing to handle the PVD pending
  697. interrupts.
  698. @endverbatim
  699. * @{
  700. */
  701. /**
  702. * @brief This function handles the PWR PVD interrupt request.
  703. * @note This API should be called under the PVD_AVD_IRQHandler().
  704. * @retval None.
  705. */
  706. void HAL_PWR_PVD_IRQHandler (void)
  707. {
  708. #if defined (DUAL_CORE)
  709. /* Check Cortex-Mx ID */
  710. if (HAL_GetCurrentCPUID () == CM7_CPUID)
  711. {
  712. /* Check PWR EXTI D1 flag */
  713. if(__HAL_PWR_PVD_EXTI_GET_FLAG () != 0U)
  714. {
  715. /* Clear PWR EXTI D1 pending bit */
  716. __HAL_PWR_PVD_EXTI_CLEAR_FLAG ();
  717. /* PWR PVD interrupt user callback */
  718. HAL_PWR_PVDCallback ();
  719. }
  720. }
  721. else
  722. {
  723. /* Check PWR EXTI D2 flag */
  724. if (__HAL_PWR_PVD_EXTID2_GET_FLAG () != 0U)
  725. {
  726. /* Clear PWR EXTI D2 pending bit */
  727. __HAL_PWR_PVD_EXTID2_CLEAR_FLAG ();
  728. /* PWR PVD interrupt user callback */
  729. HAL_PWR_PVDCallback ();
  730. }
  731. }
  732. #else /* Single core devices */
  733. /* PVD EXTI line interrupt detected */
  734. if (__HAL_PWR_PVD_EXTI_GET_FLAG () != 0U)
  735. {
  736. /* Clear PWR EXTI pending bit */
  737. __HAL_PWR_PVD_EXTI_CLEAR_FLAG ();
  738. /* PWR PVD interrupt user callback */
  739. HAL_PWR_PVDCallback ();
  740. }
  741. #endif /* defined (DUAL_CORE) */
  742. }
  743. /**
  744. * @brief PWR PVD interrupt callback.
  745. * @retval None.
  746. */
  747. __weak void HAL_PWR_PVDCallback (void)
  748. {
  749. /* NOTE : This function should not be modified, when the callback is needed,
  750. the HAL_PWR_PVDCallback can be implemented in the user file
  751. */
  752. }
  753. /**
  754. * @}
  755. */
  756. /**
  757. * @}
  758. */
  759. #endif /* HAL_PWR_MODULE_ENABLED */
  760. /**
  761. * @}
  762. */
  763. /**
  764. * @}
  765. */