stm32f4xx_pwr.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_pwr.c
  4. * @author MCD Application Team
  5. * @version V1.0.2
  6. * @date 05-March-2012
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the Power Controller (PWR) peripheral:
  9. * - Backup Domain Access
  10. * - PVD configuration
  11. * - WakeUp pin configuration
  12. * - Main and Backup Regulators configuration
  13. * - FLASH Power Down configuration
  14. * - Low Power modes configuration
  15. * - Flags management
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  21. *
  22. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  23. * You may not use this file except in compliance with the License.
  24. * You may obtain a copy of the License at:
  25. *
  26. * http://www.st.com/software_license_agreement_liberty_v2
  27. *
  28. * Unless required by applicable law or agreed to in writing, software
  29. * distributed under the License is distributed on an "AS IS" BASIS,
  30. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  31. * See the License for the specific language governing permissions and
  32. * limitations under the License.
  33. *
  34. ******************************************************************************
  35. */
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32f4xx_pwr.h"
  38. #include "stm32f4xx_rcc.h"
  39. /** @addtogroup STM32F4xx_StdPeriph_Driver
  40. * @{
  41. */
  42. /** @defgroup PWR
  43. * @brief PWR driver modules
  44. * @{
  45. */
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* Private define ------------------------------------------------------------*/
  48. /* --------- PWR registers bit address in the alias region ---------- */
  49. #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
  50. /* --- CR Register ---*/
  51. /* Alias word address of DBP bit */
  52. #define CR_OFFSET (PWR_OFFSET + 0x00)
  53. #define DBP_BitNumber 0x08
  54. #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
  55. /* Alias word address of PVDE bit */
  56. #define PVDE_BitNumber 0x04
  57. #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
  58. /* Alias word address of FPDS bit */
  59. #define FPDS_BitNumber 0x09
  60. #define CR_FPDS_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (FPDS_BitNumber * 4))
  61. /* Alias word address of PMODE bit */
  62. #define PMODE_BitNumber 0x0E
  63. #define CR_PMODE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PMODE_BitNumber * 4))
  64. /* --- CSR Register ---*/
  65. /* Alias word address of EWUP bit */
  66. #define CSR_OFFSET (PWR_OFFSET + 0x04)
  67. #define EWUP_BitNumber 0x08
  68. #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
  69. /* Alias word address of BRE bit */
  70. #define BRE_BitNumber 0x09
  71. #define CSR_BRE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (BRE_BitNumber * 4))
  72. /* ------------------ PWR registers bit mask ------------------------ */
  73. /* CR register bit mask */
  74. #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
  75. #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
  76. /* Private macro -------------------------------------------------------------*/
  77. /* Private variables ---------------------------------------------------------*/
  78. /* Private function prototypes -----------------------------------------------*/
  79. /* Private functions ---------------------------------------------------------*/
  80. /** @defgroup PWR_Private_Functions
  81. * @{
  82. */
  83. /** @defgroup PWR_Group1 Backup Domain Access function
  84. * @brief Backup Domain Access function
  85. *
  86. @verbatim
  87. ===============================================================================
  88. Backup Domain Access function
  89. ===============================================================================
  90. After reset, the backup domain (RTC registers, RTC backup data
  91. registers and backup SRAM) is protected against possible unwanted
  92. write accesses.
  93. To enable access to the RTC Domain and RTC registers, proceed as follows:
  94. - Enable the Power Controller (PWR) APB1 interface clock using the
  95. RCC_APB1PeriphClockCmd() function.
  96. - Enable access to RTC domain using the PWR_BackupAccessCmd() function.
  97. @endverbatim
  98. * @{
  99. */
  100. /**
  101. * @brief Deinitializes the PWR peripheral registers to their default reset values.
  102. * @param None
  103. * @retval None
  104. */
  105. void PWR_DeInit(void)
  106. {
  107. RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
  108. RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
  109. }
  110. /**
  111. * @brief Enables or disables access to the backup domain (RTC registers, RTC
  112. * backup data registers and backup SRAM).
  113. * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
  114. * Backup Domain Access should be kept enabled.
  115. * @param NewState: new state of the access to the backup domain.
  116. * This parameter can be: ENABLE or DISABLE.
  117. * @retval None
  118. */
  119. void PWR_BackupAccessCmd(FunctionalState NewState)
  120. {
  121. /* Check the parameters */
  122. assert_param(IS_FUNCTIONAL_STATE(NewState));
  123. *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
  124. }
  125. /**
  126. * @}
  127. */
  128. /** @defgroup PWR_Group2 PVD configuration functions
  129. * @brief PVD configuration functions
  130. *
  131. @verbatim
  132. ===============================================================================
  133. PVD configuration functions
  134. ===============================================================================
  135. - The PVD is used to monitor the VDD power supply by comparing it to a threshold
  136. selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
  137. - A PVDO flag is available to indicate if VDD/VDDA is higher or lower than the
  138. PVD threshold. This event is internally connected to the EXTI line16
  139. and can generate an interrupt if enabled through the EXTI registers.
  140. - The PVD is stopped in Standby mode.
  141. @endverbatim
  142. * @{
  143. */
  144. /**
  145. * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
  146. * @param PWR_PVDLevel: specifies the PVD detection level
  147. * This parameter can be one of the following values:
  148. * @arg PWR_PVDLevel_0
  149. * @arg PWR_PVDLevel_1
  150. * @arg PWR_PVDLevel_2
  151. * @arg PWR_PVDLevel_3
  152. * @arg PWR_PVDLevel_4
  153. * @arg PWR_PVDLevel_5
  154. * @arg PWR_PVDLevel_6
  155. * @arg PWR_PVDLevel_7
  156. * @note Refer to the electrical characteristics of your device datasheet for
  157. * more details about the voltage threshold corresponding to each
  158. * detection level.
  159. * @retval None
  160. */
  161. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
  162. {
  163. uint32_t tmpreg = 0;
  164. /* Check the parameters */
  165. assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
  166. tmpreg = PWR->CR;
  167. /* Clear PLS[7:5] bits */
  168. tmpreg &= CR_PLS_MASK;
  169. /* Set PLS[7:5] bits according to PWR_PVDLevel value */
  170. tmpreg |= PWR_PVDLevel;
  171. /* Store the new value */
  172. PWR->CR = tmpreg;
  173. }
  174. /**
  175. * @brief Enables or disables the Power Voltage Detector(PVD).
  176. * @param NewState: new state of the PVD.
  177. * This parameter can be: ENABLE or DISABLE.
  178. * @retval None
  179. */
  180. void PWR_PVDCmd(FunctionalState NewState)
  181. {
  182. /* Check the parameters */
  183. assert_param(IS_FUNCTIONAL_STATE(NewState));
  184. *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
  185. }
  186. /**
  187. * @}
  188. */
  189. /** @defgroup PWR_Group3 WakeUp pin configuration functions
  190. * @brief WakeUp pin configuration functions
  191. *
  192. @verbatim
  193. ===============================================================================
  194. WakeUp pin configuration functions
  195. ===============================================================================
  196. - WakeUp pin is used to wakeup the system from Standby mode. This pin is
  197. forced in input pull down configuration and is active on rising edges.
  198. - There is only one WakeUp pin: WakeUp Pin 1 on PA.00.
  199. @endverbatim
  200. * @{
  201. */
  202. /**
  203. * @brief Enables or disables the WakeUp Pin functionality.
  204. * @param NewState: new state of the WakeUp Pin functionality.
  205. * This parameter can be: ENABLE or DISABLE.
  206. * @retval None
  207. */
  208. void PWR_WakeUpPinCmd(FunctionalState NewState)
  209. {
  210. /* Check the parameters */
  211. assert_param(IS_FUNCTIONAL_STATE(NewState));
  212. *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
  213. }
  214. /**
  215. * @}
  216. */
  217. /** @defgroup PWR_Group4 Main and Backup Regulators configuration functions
  218. * @brief Main and Backup Regulators configuration functions
  219. *
  220. @verbatim
  221. ===============================================================================
  222. Main and Backup Regulators configuration functions
  223. ===============================================================================
  224. - The backup domain includes 4 Kbytes of backup SRAM accessible only from the
  225. CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is retained
  226. even in Standby or VBAT mode when the low power backup regulator is enabled.
  227. It can be considered as an internal EEPROM when VBAT is always present.
  228. You can use the PWR_BackupRegulatorCmd() function to enable the low power
  229. backup regulator and use the PWR_GetFlagStatus(PWR_FLAG_BRR) to check if it is
  230. ready or not.
  231. - When the backup domain is supplied by VDD (analog switch connected to VDD)
  232. the backup SRAM is powered from VDD which replaces the VBAT power supply to
  233. save battery life.
  234. - The backup SRAM is not mass erased by an tamper event. It is read protected
  235. to prevent confidential data, such as cryptographic private key, from being
  236. accessed. The backup SRAM can be erased only through the Flash interface when
  237. a protection level change from level 1 to level 0 is requested.
  238. Refer to the description of Read protection (RDP) in the Flash programming manual.
  239. - The main internal regulator can be configured to have a tradeoff between performance
  240. and power consumption when the device does not operate at the maximum frequency.
  241. This is done through PWR_MainRegulatorModeConfig() function which configure VOS bit
  242. in PWR_CR register:
  243. - When this bit is set (Regulator voltage output Scale 1 mode selected) the System
  244. frequency can go up to 168 MHz.
  245. - When this bit is reset (Regulator voltage output Scale 2 mode selected) the System
  246. frequency can go up to 144 MHz.
  247. Refer to the datasheets for more details.
  248. @endverbatim
  249. * @{
  250. */
  251. /**
  252. * @brief Enables or disables the Backup Regulator.
  253. * @param NewState: new state of the Backup Regulator.
  254. * This parameter can be: ENABLE or DISABLE.
  255. * @retval None
  256. */
  257. void PWR_BackupRegulatorCmd(FunctionalState NewState)
  258. {
  259. /* Check the parameters */
  260. assert_param(IS_FUNCTIONAL_STATE(NewState));
  261. *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)NewState;
  262. }
  263. /**
  264. * @brief Configures the main internal regulator output voltage.
  265. * @param PWR_Regulator_Voltage: specifies the regulator output voltage to achieve
  266. * a tradeoff between performance and power consumption when the device does
  267. * not operate at the maximum frequency (refer to the datasheets for more details).
  268. * This parameter can be one of the following values:
  269. * @arg PWR_Regulator_Voltage_Scale1: Regulator voltage output Scale 1 mode,
  270. * System frequency up to 168 MHz.
  271. * @arg PWR_Regulator_Voltage_Scale2: Regulator voltage output Scale 2 mode,
  272. * System frequency up to 144 MHz.
  273. * @retval None
  274. */
  275. void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage)
  276. {
  277. /* Check the parameters */
  278. assert_param(IS_PWR_REGULATOR_VOLTAGE(PWR_Regulator_Voltage));
  279. if (PWR_Regulator_Voltage == PWR_Regulator_Voltage_Scale2)
  280. {
  281. PWR->CR &= ~PWR_Regulator_Voltage_Scale1;
  282. }
  283. else
  284. {
  285. PWR->CR |= PWR_Regulator_Voltage_Scale1;
  286. }
  287. }
  288. /**
  289. * @}
  290. */
  291. /** @defgroup PWR_Group5 FLASH Power Down configuration functions
  292. * @brief FLASH Power Down configuration functions
  293. *
  294. @verbatim
  295. ===============================================================================
  296. FLASH Power Down configuration functions
  297. ===============================================================================
  298. - By setting the FPDS bit in the PWR_CR register by using the PWR_FlashPowerDownCmd()
  299. function, the Flash memory also enters power down mode when the device enters
  300. Stop mode. When the Flash memory is in power down mode, an additional startup
  301. delay is incurred when waking up from Stop mode.
  302. @endverbatim
  303. * @{
  304. */
  305. /**
  306. * @brief Enables or disables the Flash Power Down in STOP mode.
  307. * @param NewState: new state of the Flash power mode.
  308. * This parameter can be: ENABLE or DISABLE.
  309. * @retval None
  310. */
  311. void PWR_FlashPowerDownCmd(FunctionalState NewState)
  312. {
  313. /* Check the parameters */
  314. assert_param(IS_FUNCTIONAL_STATE(NewState));
  315. *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)NewState;
  316. }
  317. /**
  318. * @}
  319. */
  320. /** @defgroup PWR_Group6 Low Power modes configuration functions
  321. * @brief Low Power modes configuration functions
  322. *
  323. @verbatim
  324. ===============================================================================
  325. Low Power modes configuration functions
  326. ===============================================================================
  327. The devices feature 3 low-power modes:
  328. - Sleep mode: Cortex-M4 core stopped, peripherals kept running.
  329. - Stop mode: all clocks are stopped, regulator running, regulator in low power mode
  330. - Standby mode: 1.2V domain powered off.
  331. Sleep mode
  332. ===========
  333. - Entry:
  334. - The Sleep mode is entered by using the __WFI() or __WFE() functions.
  335. - Exit:
  336. - Any peripheral interrupt acknowledged by the nested vectored interrupt
  337. controller (NVIC) can wake up the device from Sleep mode.
  338. Stop mode
  339. ==========
  340. In Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI,
  341. and the HSE RC oscillators are disabled. Internal SRAM and register contents
  342. are preserved.
  343. The voltage regulator can be configured either in normal or low-power mode.
  344. To minimize the consumption In Stop mode, FLASH can be powered off before
  345. entering the Stop mode. It can be switched on again by software after exiting
  346. the Stop mode using the PWR_FlashPowerDownCmd() function.
  347. - Entry:
  348. - The Stop mode is entered using the PWR_EnterSTOPMode(PWR_Regulator_LowPower,)
  349. function with regulator in LowPower or with Regulator ON.
  350. - Exit:
  351. - Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
  352. Standby mode
  353. ============
  354. The Standby mode allows to achieve the lowest power consumption. It is based
  355. on the Cortex-M4 deepsleep mode, with the voltage regulator disabled.
  356. The 1.2V domain is consequently powered off. The PLL, the HSI oscillator and
  357. the HSE oscillator are also switched off. SRAM and register contents are lost
  358. except for the RTC registers, RTC backup registers, backup SRAM and Standby
  359. circuitry.
  360. The voltage regulator is OFF.
  361. - Entry:
  362. - The Standby mode is entered using the PWR_EnterSTANDBYMode() function.
  363. - Exit:
  364. - WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
  365. tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
  366. Auto-wakeup (AWU) from low-power mode
  367. =====================================
  368. The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
  369. Wakeup event, a tamper event, a time-stamp event, or a comparator event,
  370. without depending on an external interrupt (Auto-wakeup mode).
  371. - RTC auto-wakeup (AWU) from the Stop mode
  372. ----------------------------------------
  373. - To wake up from the Stop mode with an RTC alarm event, it is necessary to:
  374. - Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt
  375. or Event modes) using the EXTI_Init() function.
  376. - Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
  377. - Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
  378. and RTC_AlarmCmd() functions.
  379. - To wake up from the Stop mode with an RTC Tamper or time stamp event, it
  380. is necessary to:
  381. - Configure the EXTI Line 21 to be sensitive to rising edges (Interrupt
  382. or Event modes) using the EXTI_Init() function.
  383. - Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
  384. function
  385. - Configure the RTC to detect the tamper or time stamp event using the
  386. RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
  387. functions.
  388. - To wake up from the Stop mode with an RTC WakeUp event, it is necessary to:
  389. - Configure the EXTI Line 22 to be sensitive to rising edges (Interrupt
  390. or Event modes) using the EXTI_Init() function.
  391. - Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
  392. - Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
  393. RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
  394. - RTC auto-wakeup (AWU) from the Standby mode
  395. -------------------------------------------
  396. - To wake up from the Standby mode with an RTC alarm event, it is necessary to:
  397. - Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
  398. - Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
  399. and RTC_AlarmCmd() functions.
  400. - To wake up from the Standby mode with an RTC Tamper or time stamp event, it
  401. is necessary to:
  402. - Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
  403. function
  404. - Configure the RTC to detect the tamper or time stamp event using the
  405. RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
  406. functions.
  407. - To wake up from the Standby mode with an RTC WakeUp event, it is necessary to:
  408. - Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
  409. - Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
  410. RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
  411. @endverbatim
  412. * @{
  413. */
  414. /**
  415. * @brief Enters STOP mode.
  416. *
  417. * @note In Stop mode, all I/O pins keep the same state as in Run mode.
  418. * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
  419. * the HSI RC oscillator is selected as system clock.
  420. * @note When the voltage regulator operates in low power mode, an additional
  421. * startup delay is incurred when waking up from Stop mode.
  422. * By keeping the internal regulator ON during Stop mode, the consumption
  423. * is higher although the startup time is reduced.
  424. *
  425. * @param PWR_Regulator: specifies the regulator state in STOP mode.
  426. * This parameter can be one of the following values:
  427. * @arg PWR_Regulator_ON: STOP mode with regulator ON
  428. * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
  429. * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
  430. * This parameter can be one of the following values:
  431. * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
  432. * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
  433. * @retval None
  434. */
  435. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
  436. {
  437. uint32_t tmpreg = 0;
  438. /* Check the parameters */
  439. assert_param(IS_PWR_REGULATOR(PWR_Regulator));
  440. assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
  441. /* Select the regulator state in STOP mode ---------------------------------*/
  442. tmpreg = PWR->CR;
  443. /* Clear PDDS and LPDSR bits */
  444. tmpreg &= CR_DS_MASK;
  445. /* Set LPDSR bit according to PWR_Regulator value */
  446. tmpreg |= PWR_Regulator;
  447. /* Store the new value */
  448. PWR->CR = tmpreg;
  449. /* Set SLEEPDEEP bit of Cortex System Control Register */
  450. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  451. /* Select STOP mode entry --------------------------------------------------*/
  452. if(PWR_STOPEntry == PWR_STOPEntry_WFI)
  453. {
  454. /* Request Wait For Interrupt */
  455. __WFI();
  456. }
  457. else
  458. {
  459. /* Request Wait For Event */
  460. __WFE();
  461. }
  462. /* Reset SLEEPDEEP bit of Cortex System Control Register */
  463. SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
  464. }
  465. /**
  466. * @brief Enters STANDBY mode.
  467. * @note In Standby mode, all I/O pins are high impedance except for:
  468. * - Reset pad (still available)
  469. * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC
  470. * Alarm out, or RTC clock calibration out.
  471. * - RTC_AF2 pin (PI8) if configured for tamper or time-stamp.
  472. * - WKUP pin 1 (PA0) if enabled.
  473. * @param None
  474. * @retval None
  475. */
  476. void PWR_EnterSTANDBYMode(void)
  477. {
  478. /* Clear Wakeup flag */
  479. PWR->CR |= PWR_CR_CWUF;
  480. /* Select STANDBY mode */
  481. PWR->CR |= PWR_CR_PDDS;
  482. /* Set SLEEPDEEP bit of Cortex System Control Register */
  483. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  484. /* This option is used to ensure that store operations are completed */
  485. #if defined ( __CC_ARM )
  486. __force_stores();
  487. #endif
  488. /* Request Wait For Interrupt */
  489. __WFI();
  490. }
  491. /**
  492. * @}
  493. */
  494. /** @defgroup PWR_Group7 Flags management functions
  495. * @brief Flags management functions
  496. *
  497. @verbatim
  498. ===============================================================================
  499. Flags management functions
  500. ===============================================================================
  501. @endverbatim
  502. * @{
  503. */
  504. /**
  505. * @brief Checks whether the specified PWR flag is set or not.
  506. * @param PWR_FLAG: specifies the flag to check.
  507. * This parameter can be one of the following values:
  508. * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
  509. * was received from the WKUP pin or from the RTC alarm (Alarm A
  510. * or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
  511. * An additional wakeup event is detected if the WKUP pin is enabled
  512. * (by setting the EWUP bit) when the WKUP pin level is already high.
  513. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
  514. * resumed from StandBy mode.
  515. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
  516. * by the PWR_PVDCmd() function. The PVD is stopped by Standby mode
  517. * For this reason, this bit is equal to 0 after Standby or reset
  518. * until the PVDE bit is set.
  519. * @arg PWR_FLAG_BRR: Backup regulator ready flag. This bit is not reset
  520. * when the device wakes up from Standby mode or by a system reset
  521. * or power reset.
  522. * @arg PWR_FLAG_VOSRDY: This flag indicates that the Regulator voltage
  523. * scaling output selection is ready.
  524. * @retval The new state of PWR_FLAG (SET or RESET).
  525. */
  526. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
  527. {
  528. FlagStatus bitstatus = RESET;
  529. /* Check the parameters */
  530. assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
  531. if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
  532. {
  533. bitstatus = SET;
  534. }
  535. else
  536. {
  537. bitstatus = RESET;
  538. }
  539. /* Return the flag status */
  540. return bitstatus;
  541. }
  542. /**
  543. * @brief Clears the PWR's pending flags.
  544. * @param PWR_FLAG: specifies the flag to clear.
  545. * This parameter can be one of the following values:
  546. * @arg PWR_FLAG_WU: Wake Up flag
  547. * @arg PWR_FLAG_SB: StandBy flag
  548. * @retval None
  549. */
  550. void PWR_ClearFlag(uint32_t PWR_FLAG)
  551. {
  552. /* Check the parameters */
  553. assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
  554. PWR->CR |= PWR_FLAG << 2;
  555. }
  556. /**
  557. * @}
  558. */
  559. /**
  560. * @}
  561. */
  562. /**
  563. * @}
  564. */
  565. /**
  566. * @}
  567. */
  568. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/