stm32f4xx_pwr.c 25 KB

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