stm32h7xx_hal_pwr.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_pwr.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 21-April-2017
  7. * @brief PWR HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the Power Controller (PWR) peripheral:
  10. * + Initialization and de-initialization functions
  11. * + Peripheral Control functions
  12. *
  13. ******************************************************************************
  14. * @attention
  15. *
  16. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  17. *
  18. * Redistribution and use in source and binary forms, with or without modification,
  19. * are permitted provided that the following conditions are met:
  20. * 1. Redistributions of source code must retain the above copyright notice,
  21. * this list of conditions and the following disclaimer.
  22. * 2. Redistributions in binary form must reproduce the above copyright notice,
  23. * this list of conditions and the following disclaimer in the documentation
  24. * and/or other materials provided with the distribution.
  25. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  26. * may be used to endorse or promote products derived from this software
  27. * without specific prior written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  33. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  35. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  36. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  37. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. ******************************************************************************
  41. */
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "stm32h7xx_hal.h"
  44. /** @addtogroup STM32H7xx_HAL_Driver
  45. * @{
  46. */
  47. /** @defgroup PWR PWR
  48. * @brief PWR HAL module driver
  49. * @{
  50. */
  51. #ifdef HAL_PWR_MODULE_ENABLED
  52. /* Private typedef -----------------------------------------------------------*/
  53. /* Private define ------------------------------------------------------------*/
  54. /** @addtogroup PWR_Private_Constants PWR Private Constants
  55. * @{
  56. */
  57. /** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask
  58. * @{
  59. */
  60. #define PVD_MODE_IT ((uint32_t)0x00010000U)
  61. #define PVD_MODE_EVT ((uint32_t)0x00020000U)
  62. #define PVD_RISING_EDGE ((uint32_t)0x00000001U)
  63. #define PVD_FALLING_EDGE ((uint32_t)0x00000002U)
  64. #define PVD_RISING_FALLING_EDGE ((uint32_t)0x00000003U)
  65. /**
  66. * @}
  67. */
  68. /**
  69. * @}
  70. */
  71. /* Private macro -------------------------------------------------------------*/
  72. /* Private variables ---------------------------------------------------------*/
  73. /* Private function prototypes -----------------------------------------------*/
  74. /* Private functions ---------------------------------------------------------*/
  75. /** @defgroup PWR_Exported_Functions PWR Exported Functions
  76. * @{
  77. */
  78. /** @defgroup PWR_Exported_Functions_Group1 Initialization and De-Initialization functions
  79. * @brief Initialization and De-Initialization functions
  80. *
  81. @verbatim
  82. ===============================================================================
  83. ##### Initialization and De-Initialization functions #####
  84. ===============================================================================
  85. [..]
  86. After reset, the backup domain (RTC registers, RTC backup data
  87. registers and backup SRAM) is protected against possible unwanted
  88. write accesses.
  89. To enable access to the RTC Domain and RTC registers, proceed as follows:
  90. (+) Enable the Power Controller (PWR) APB1 interface clock using the
  91. __HAL_RCC_PWR_CLK_ENABLE() macro.
  92. (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
  93. @endverbatim
  94. * @{
  95. */
  96. /**
  97. * @brief Deinitialize the HAL PWR peripheral registers to their default reset values.
  98. * @note This functionality is not available in this product.
  99. * The prototype is kept just to maintain compatibility with other products.
  100. * @retval None
  101. */
  102. void HAL_PWR_DeInit(void)
  103. {
  104. }
  105. /**
  106. * @brief Enable access to the backup domain (RTC registers, RTC
  107. * backup data registers and backup SRAM).
  108. * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
  109. * Backup Domain Access should be kept enabled.
  110. * @retval None
  111. */
  112. void HAL_PWR_EnableBkUpAccess(void)
  113. {
  114. /* Enable access to RTC and backup registers */
  115. SET_BIT(PWR->CR1, PWR_CR1_DBP);
  116. }
  117. /**
  118. * @brief Disable access to the backup domain (RTC registers, RTC
  119. * backup data registers and backup SRAM).
  120. * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
  121. * Backup Domain Access should be kept enabled.
  122. * @retval None
  123. */
  124. void HAL_PWR_DisableBkUpAccess(void)
  125. {
  126. /* Disable access to RTC and backup registers */
  127. CLEAR_BIT(PWR->CR1, PWR_CR1_DBP);
  128. }
  129. /**
  130. * @}
  131. */
  132. /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions
  133. * @brief Low Power modes configuration functions
  134. *
  135. @verbatim
  136. ===============================================================================
  137. ##### Peripheral Control functions #####
  138. ===============================================================================
  139. *** PVD configuration ***
  140. =========================
  141. [..]
  142. (+) The PVD is used to monitor the VDD power supply by comparing it to a
  143. threshold selected by the PVD Level (PLS[7:0] bits in the PWR_CR1 register).
  144. (+) A PVDO flag is available to indicate if VDD is higher or lower
  145. than the PVD threshold. This event is internally connected to the EXTI
  146. line 16 to generate an interrupt if enabled.
  147. It is configurable through __HAL_PWR_PVD_EXTI_ENABLE_IT() macro.
  148. (+) The PVD is stopped in Standby mode.
  149. *** Wake-up pin configuration ***
  150. ================================
  151. [..]
  152. (+) Wake-up pin is used to wake up the system from Standby mode.
  153. The pin pull is configurable through the WKUPEPR register to be in No pull-up, Pull-up and Pull-down.
  154. The pin polarity is configurable through the WKUPEPR register to be active on rising or falling edges.
  155. (+) There are up to six Wake-up pin in the STM32H7 devices family.
  156. *** Low Power modes configuration ***
  157. =====================================
  158. [..]
  159. The device present 3 principles low-power modes features:
  160. (+) SLEEP mode: Cortex-M7 core stopped and D1, D2 and D3 peripherals kept running.
  161. (+) STOP mode: all clocks are stoppedand the regulator running in main or low power mode.
  162. (+) STANDBY mode: D1, D2 and D3 domains enter DSTANDBY mode and the VCORE supply
  163. regulator is powered off.
  164. *** SLEEP mode ***
  165. ==================
  166. [..]
  167. (+) Entry:
  168. The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(Regulator, SLEEPEntry)
  169. function.
  170. (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
  171. (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
  172. -@@- The Regulator parameter is not used for the STM32H7 family
  173. and is kept as parameter just to maintain compatibility with the
  174. lower power families (STM32L).
  175. (+) Exit:
  176. Any peripheral interrupt acknowledged by the nested vectored interrupt
  177. controller (NVIC) can wake up the device from Sleep mode.
  178. *** STOP mode ***
  179. =================
  180. [..]
  181. In system Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI,
  182. and the HSE RC oscillators are disabled. Internal SRAM and register contents
  183. are preserved.
  184. The voltage regulator can be configured either in normal or low-power mode.
  185. To minimize the consumption In Stop mode, FLASH can be powered off before
  186. entering the Stop mode using the HAL_PWREx_EnableFlashPowerDown() function.
  187. It can be switched on again by software after exiting the Stop mode using
  188. the HAL_PWREx_DisableFlashPowerDown() function.
  189. (+) Entry:
  190. The Stop mode is entered using the HAL_PWR_EnterSTOPMode(Regulator, STOPEntry)
  191. function with:
  192. (++) Regulator:
  193. (+++) PWR_MAINREGULATOR_ON: Main regulator ON.
  194. (+++) PWR_LOWPOWERREGULATOR_ON: Low Power regulator ON.
  195. (++) STOPEntry:
  196. (+++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction
  197. (+++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction
  198. (+) Exit:
  199. Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
  200. *** STANDBY mode ***
  201. ====================
  202. [..]
  203. (+)
  204. The system Standby mode allows to achieve the lowest power consumption. It is based
  205. on the Cortex-M7 deep sleep mode, with the voltage regulator disabled.
  206. The system is consequently powered off. The PLL, the HSI oscillator and
  207. the HSE oscillator are also switched off. SRAM and register contents are lost
  208. except for the RTC registers, RTC backup registers, backup SRAM and Standby
  209. circuitry.
  210. [..]
  211. The voltage regulator is OFF.
  212. (++) Entry:
  213. (+++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function.
  214. (++) Exit:
  215. (+++) WKUP pin rising or falling edge, RTC alarm (Alarm A and Alarm B), RTC
  216. wakeup, tamper event, time stamp event, external reset in NRST pin, IWDG reset.
  217. *** Auto-wakeup (AWU) from low-power mode ***
  218. =============================================
  219. [..]
  220. (+) The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
  221. Wakeup event, a tamper event or a time-stamp event, without depending on
  222. an external interrupt (Auto-wakeup mode).
  223. (+) RTC auto-wakeup (AWU) from the STOP and STANDBY modes
  224. (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to
  225. configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.
  226. (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
  227. is necessary to configure the RTC to detect the tamper or time stamp event using the
  228. HAL_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_SetTamper_IT() functions.
  229. (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to
  230. configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer_IT() function.
  231. @endverbatim
  232. * @{
  233. */
  234. /**
  235. * @brief Configure the voltage threshold detected by the Power Voltage Detector(PVD).
  236. * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration
  237. * information for the PVD.
  238. * @note Refer to the electrical characteristics of your device datasheet for
  239. * more details about the voltage threshold corresponding to each
  240. * detection level.
  241. * @retval None
  242. */
  243. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
  244. {
  245. /* Check the parameters */
  246. assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
  247. assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
  248. /* Set PLS[7:5] bits according to PVDLevel value */
  249. MODIFY_REG(PWR->CR1, PWR_CR1_PLS, sConfigPVD->PVDLevel);
  250. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  251. __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
  252. __HAL_PWR_PVD_EXTI_DISABLE_IT();
  253. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
  254. __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
  255. /* Configure interrupt mode */
  256. if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
  257. {
  258. __HAL_PWR_PVD_EXTI_ENABLE_IT();
  259. }
  260. /* Configure event mode */
  261. if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
  262. {
  263. __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
  264. }
  265. /* Configure the edge */
  266. if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
  267. {
  268. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
  269. }
  270. if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
  271. {
  272. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
  273. }
  274. }
  275. /**
  276. * @brief Enable the Power Voltage Detector(PVD).
  277. * @retval None
  278. */
  279. void HAL_PWR_EnablePVD(void)
  280. {
  281. /* Enable the power voltage detector */
  282. SET_BIT(PWR->CR1, PWR_CR1_PVDEN);
  283. }
  284. /**
  285. * @brief Disable the Power Voltage Detector(PVD).
  286. * @retval None
  287. */
  288. void HAL_PWR_DisablePVD(void)
  289. {
  290. /* Disable the power voltage detector */
  291. CLEAR_BIT(PWR->CR1, PWR_CR1_PVDEN);
  292. }
  293. /**
  294. * @brief Enable the WakeUp PINx functionality.
  295. * @param WakeUpPinPolarity: Specifies which Wake-Up pin to enable.
  296. * This parameter can be one of the following legacy values, which sets the default:
  297. * polarity detection on high level (rising edge):
  298. * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4,
  299. * PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6 or one of the following values where
  300. * the user can explicitly states the enabled pin and the chosen polarity.
  301. * @arg PWR_WAKEUP_PIN1_HIGH or PWR_WAKEUP_PIN1_LOW
  302. * @arg PWR_WAKEUP_PIN2_HIGH or PWR_WAKEUP_PIN2_LOW
  303. * @arg PWR_WAKEUP_PIN3_HIGH or PWR_WAKEUP_PIN3_LOW
  304. * @arg PWR_WAKEUP_PIN4_HIGH or PWR_WAKEUP_PIN4_LOW
  305. * @arg PWR_WAKEUP_PIN5_HIGH or PWR_WAKEUP_PIN5_LOW
  306. * @arg PWR_WAKEUP_PIN6_HIGH or PWR_WAKEUP_PIN6_LOW
  307. * @note PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent.
  308. * @retval None
  309. */
  310. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)
  311. {
  312. assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity));
  313. /* Enable and Specify the Wake-Up pin polarity and the pull configuration
  314. for the event detection (rising or falling edge) */
  315. MODIFY_REG(PWR->WKUPEPR, PWR_EWUP_MASK, WakeUpPinPolarity);
  316. }
  317. /**
  318. * @brief Disable the WakeUp PINx functionality.
  319. * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.
  320. * This parameter can be one of the following values:
  321. * @arg PWR_WAKEUP_PIN1
  322. * @arg PWR_WAKEUP_PIN2
  323. * @arg PWR_WAKEUP_PIN3
  324. * @arg PWR_WAKEUP_PIN4
  325. * @arg PWR_WAKEUP_PIN5
  326. * @arg PWR_WAKEUP_PIN6
  327. * @retval None
  328. */
  329. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
  330. {
  331. assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
  332. CLEAR_BIT(PWR->WKUPEPR, WakeUpPinx);
  333. }
  334. /**
  335. * @brief Enter CM7 core to Sleep mode.
  336. * @param Regulator: Specifies the regulator state in SLEEP mode.
  337. * This parameter can be one of the following values:
  338. * @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON
  339. * @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON
  340. * @note This parameter is not used for the STM32H7 family and is kept as parameter
  341. * just to maintain compatibility with the lower power families.
  342. * @param SLEEPEntry: Specifies if SLEEP mode in entered with WFI or WFE instruction.
  343. * This parameter can be one of the following values:
  344. * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
  345. * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
  346. * @retval None
  347. */
  348. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
  349. {
  350. /* Check the parameters */
  351. assert_param(IS_PWR_REGULATOR(Regulator));
  352. assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
  353. /* Clear SLEEPDEEP bit of Cortex System Control Register */
  354. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  355. /* Select SLEEP mode entry */
  356. if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
  357. {
  358. /* Request Wait For Interrupt */
  359. __WFI();
  360. }
  361. else
  362. {
  363. /* Request Wait For Event */
  364. __SEV();
  365. __WFE();
  366. __WFE();
  367. }
  368. }
  369. /**
  370. * @brief Enter the system to STOP mode.
  371. * @note In System Stop mode, all I/O pins keep the same state as in Run mode.
  372. * @note When exiting System Stop mode by issuing an interrupt or a wakeup event,
  373. * the HSI RC oscillator is selected as default system wakeup clock.
  374. * @note In System STOP mode, when the voltage regulator operates in low power mode,
  375. * an additional startup delay is incurred when the system is waking up.
  376. * By keeping the internal regulator ON during Stop mode, the consumption
  377. * is higher although the startup time is reduced.
  378. * @param Regulator: Specifies the regulator state in Stop mode.
  379. * This parameter can be one of the following values:
  380. * @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
  381. * @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
  382. * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.
  383. * This parameter can be one of the following values:
  384. * @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction
  385. * @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
  386. * @retval None
  387. */
  388. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
  389. {
  390. uint32_t tmpreg = 0;
  391. /* Check the parameters */
  392. assert_param(IS_PWR_REGULATOR(Regulator));
  393. assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
  394. /* Select the regulator state in Stop mode */
  395. tmpreg = PWR->CR1;
  396. /* Clear PDDS and LPDS bits */
  397. tmpreg &= (uint32_t)~(PWR_CR1_LPDS);
  398. /* Set LPDS bit according to Regulator value */
  399. tmpreg |= Regulator;
  400. /* Store the new value */
  401. PWR->CR1 = tmpreg;
  402. /* Keep DSTOP mode when D1 domain enters Deepsleep */
  403. CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D1);
  404. /* Keep DSTOP mode when D2 domain enters Deepsleep */
  405. CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D2);
  406. /* Keep DSTOP mode when D3 domain enters Deepsleep */
  407. CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D3);
  408. /* Set SLEEPDEEP bit of Cortex System Control Register */
  409. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  410. /* Ensure that all instructions done before entering STOP mode */
  411. __DSB();
  412. __ISB();
  413. /* Select Stop mode entry */
  414. if(STOPEntry == PWR_STOPENTRY_WFI)
  415. {
  416. /* Request Wait For Interrupt */
  417. __WFI();
  418. }
  419. else
  420. {
  421. /* Request Wait For Event */
  422. __SEV();
  423. __WFE();
  424. __WFE();
  425. }
  426. /* Reset SLEEPDEEP bit of Cortex System Control Register */
  427. SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
  428. }
  429. /**
  430. * @brief Enter the system to STANDBY mode.
  431. * @note The system enters Standby mode only when the D1, D2 and D3 domains are in DStandby.
  432. * @note When the System exit STANDBY mode by issuing an interrupt or a wakeup event,
  433. * the HSI RC oscillator is selected as system clock.
  434. * @retval None.
  435. */
  436. void HAL_PWR_EnterSTANDBYMode(void)
  437. {
  438. /* Keep DSTANDBY mode when D1 domain enters Deepsleep */
  439. SET_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D1);
  440. /* Keep DSTANDBY mode when D2 domain enters Deepsleep */
  441. SET_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D2);
  442. /* Keep DSTANDBY mode when D3 domain enters Deepsleep */
  443. SET_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D3);
  444. /* Set SLEEPDEEP bit of Cortex System Control Register */
  445. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  446. /* This option is used to ensure that store operations are completed */
  447. #if defined ( __CC_ARM)
  448. __force_stores();
  449. #endif
  450. /* Request Wait For Interrupt */
  451. __WFI();
  452. }
  453. /**
  454. * @brief Indicate Sleep-On-Exit when returning from Handler mode to Thread mode.
  455. * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor
  456. * re-enters SLEEP mode when an interruption handling is over.
  457. * Setting this bit is useful when the processor is expected to run only on
  458. * interruptions handling.
  459. * @retval None
  460. */
  461. void HAL_PWR_EnableSleepOnExit(void)
  462. {
  463. /* Set SLEEPONEXIT bit of Cortex System Control Register */
  464. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
  465. }
  466. /**
  467. * @brief Disable Sleep-On-Exit feature when returning from Handler mode to Thread mode.
  468. * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor
  469. * re-enters SLEEP mode when an interruption handling is over.
  470. * @retval None
  471. */
  472. void HAL_PWR_DisableSleepOnExit(void)
  473. {
  474. /* Clear SLEEPONEXIT bit of Cortex System Control Register */
  475. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
  476. }
  477. /**
  478. * @brief Enable CORTEX SEVONPEND bit.
  479. * @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes
  480. * WFE to wake up when an interrupt moves from inactive to pended.
  481. * @retval None
  482. */
  483. void HAL_PWR_EnableSEVOnPend(void)
  484. {
  485. /* Set SEVONPEND bit of Cortex System Control Register */
  486. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
  487. }
  488. /**
  489. * @brief Disable CORTEX SEVONPEND bit.
  490. * @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes
  491. * WFE to wake up when an interrupt moves from inactive to pended.
  492. * @retval None
  493. */
  494. void HAL_PWR_DisableSEVOnPend(void)
  495. {
  496. /* Clear SEVONPEND bit of Cortex System Control Register */
  497. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
  498. }
  499. /**
  500. * @brief This function handles the PWR PVD interrupt request.
  501. * @note This API should be called under the PVD_IRQHandler().
  502. * @retval None
  503. */
  504. void HAL_PWR_PVD_IRQHandler(void)
  505. {
  506. /* PVD EXTI line interrupt detected */
  507. if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
  508. {
  509. /* PWR PVD interrupt user callback */
  510. HAL_PWR_PVDCallback();
  511. /* Clear PWR EXTI pending bit */
  512. __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
  513. }
  514. }
  515. /**
  516. * @brief PWR PVD interrupt callback
  517. * @retval None
  518. */
  519. __weak void HAL_PWR_PVDCallback(void)
  520. {
  521. /* NOTE : This function Should not be modified, when the callback is needed,
  522. the HAL_PWR_PVDCallback could be implemented in the user file
  523. */
  524. }
  525. /**
  526. * @}
  527. */
  528. /**
  529. * @}
  530. */
  531. #endif /* HAL_PWR_MODULE_ENABLED */
  532. /**
  533. * @}
  534. */
  535. /**
  536. * @}
  537. */
  538. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/