stm32f1xx_hal_pwr.c 22 KB

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