You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

869 lines
31 KiB

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