stm32f4xx_pwr.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_pwr.c
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  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. * Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.
  22. *
  23. * This software is licensed under terms that can be found in the LICENSE file
  24. * in the root directory of this software component.
  25. * If no LICENSE file comes with this software, it is provided AS-IS.
  26. *
  27. ******************************************************************************
  28. */
  29. /* Includes ------------------------------------------------------------------*/
  30. #include "stm32f4xx_pwr.h"
  31. #include "stm32f4xx_rcc.h"
  32. /** @addtogroup STM32F4xx_StdPeriph_Driver
  33. * @{
  34. */
  35. /** @defgroup PWR
  36. * @brief PWR driver modules
  37. * @{
  38. */
  39. /* Private typedef -----------------------------------------------------------*/
  40. /* Private define ------------------------------------------------------------*/
  41. /* --------- PWR registers bit address in the alias region ---------- */
  42. #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
  43. /* --- CR Register ---*/
  44. /* Alias word address of DBP bit */
  45. #define CR_OFFSET (PWR_OFFSET + 0x00)
  46. #define DBP_BitNumber 0x08
  47. #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
  48. /* Alias word address of PVDE bit */
  49. #define PVDE_BitNumber 0x04
  50. #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
  51. /* Alias word address of FPDS bit */
  52. #define FPDS_BitNumber 0x09
  53. #define CR_FPDS_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (FPDS_BitNumber * 4))
  54. /* Alias word address of PMODE bit */
  55. #define PMODE_BitNumber 0x0E
  56. #define CR_PMODE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PMODE_BitNumber * 4))
  57. /* Alias word address of ODEN bit */
  58. #define ODEN_BitNumber 0x10
  59. #define CR_ODEN_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (ODEN_BitNumber * 4))
  60. /* Alias word address of ODSWEN bit */
  61. #define ODSWEN_BitNumber 0x11
  62. #define CR_ODSWEN_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (ODSWEN_BitNumber * 4))
  63. #if defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx)
  64. /* Alias word address of MRUDS bit */
  65. #define MRUDS_BitNumber 0x0B
  66. #define CR_MRUDS_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (MRUDS_BitNumber * 4))
  67. /* Alias word address of LPUDS bit */
  68. #define LPUDS_BitNumber 0x0A
  69. #define CR_LPUDS_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (LPUDS_BitNumber * 4))
  70. #endif /* STM32F427_437xx || STM32F429_439xx || STM32F446xx */
  71. #if defined(STM32F401xx) || defined(STM32F410xx) || defined(STM32F411xE) || defined(STM32F412xG) || defined(STM32F413_423xx)
  72. /* Alias word address of MRLVDS bit */
  73. #define MRLVDS_BitNumber 0x0B
  74. #define CR_MRLVDS_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (MRLVDS_BitNumber * 4))
  75. /* Alias word address of LPLVDS bit */
  76. #define LPLVDS_BitNumber 0x0A
  77. #define CR_LPLVDS_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (LPLVDS_BitNumber * 4))
  78. #endif /* STM32F401xx || STM32F410xx || STM32F411xE || STM32F412xG || STM32F413_423xx */
  79. /* --- CSR Register ---*/
  80. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F410xx) || defined(STM32F411xE) || defined(STM32F469_479xx)
  81. /* Alias word address of EWUP bit */
  82. #define CSR_OFFSET (PWR_OFFSET + 0x04)
  83. #define EWUP_BitNumber 0x08
  84. #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
  85. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F410xx || STM32F411xE || STM32F469_479xx */
  86. #if defined(STM32F410xx) || defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)
  87. /* Alias word address of EWUP2 bit */
  88. #define CSR_OFFSET (PWR_OFFSET + 0x04)
  89. #define EWUP1_BitNumber 0x08
  90. #define CSR_EWUP1_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP1_BitNumber * 4))
  91. #define EWUP2_BitNumber 0x07
  92. #define CSR_EWUP2_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP2_BitNumber * 4))
  93. #if defined(STM32F410xx) || defined(STM32F412xG) || defined(STM32F413_423xx)
  94. #define EWUP3_BitNumber 0x06
  95. #define CSR_EWUP3_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP2_BitNumber * 4))
  96. #endif /* STM32F410xx || STM32F412xG || STM32F413_423xx */
  97. #endif /* STM32F410xx || STM32F412xG || STM32F413_423xx || STM32F446xx */
  98. /* Alias word address of BRE bit */
  99. #define BRE_BitNumber 0x09
  100. #define CSR_BRE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (BRE_BitNumber * 4))
  101. /* ------------------ PWR registers bit mask ------------------------ */
  102. /* CR register bit mask */
  103. #define CR_DS_MASK ((uint32_t)0xFFFFF3FC)
  104. #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
  105. #define CR_VOS_MASK ((uint32_t)0xFFFF3FFF)
  106. /* Private macro -------------------------------------------------------------*/
  107. /* Private variables ---------------------------------------------------------*/
  108. /* Private function prototypes -----------------------------------------------*/
  109. /* Private functions ---------------------------------------------------------*/
  110. /** @defgroup PWR_Private_Functions
  111. * @{
  112. */
  113. /** @defgroup PWR_Group1 Backup Domain Access function
  114. * @brief Backup Domain Access function
  115. *
  116. @verbatim
  117. ===============================================================================
  118. ##### Backup Domain Access function #####
  119. ===============================================================================
  120. [..]
  121. After reset, the backup domain (RTC registers, RTC backup data
  122. registers and backup SRAM) is protected against possible unwanted
  123. write accesses.
  124. To enable access to the RTC Domain and RTC registers, proceed as follows:
  125. (+) Enable the Power Controller (PWR) APB1 interface clock using the
  126. RCC_APB1PeriphClockCmd() function.
  127. (+) Enable access to RTC domain using the PWR_BackupAccessCmd() function.
  128. @endverbatim
  129. * @{
  130. */
  131. /**
  132. * @brief Deinitializes the PWR peripheral registers to their default reset values.
  133. * @param None
  134. * @retval None
  135. */
  136. void PWR_DeInit(void)
  137. {
  138. RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
  139. RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
  140. }
  141. /**
  142. * @brief Enables or disables access to the backup domain (RTC registers, RTC
  143. * backup data registers and backup SRAM).
  144. * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
  145. * Backup Domain Access should be kept enabled.
  146. * @param NewState: new state of the access to the backup domain.
  147. * This parameter can be: ENABLE or DISABLE.
  148. * @retval None
  149. */
  150. void PWR_BackupAccessCmd(FunctionalState NewState)
  151. {
  152. /* Check the parameters */
  153. assert_param(IS_FUNCTIONAL_STATE(NewState));
  154. *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
  155. }
  156. /**
  157. * @}
  158. */
  159. /** @defgroup PWR_Group2 PVD configuration functions
  160. * @brief PVD configuration functions
  161. *
  162. @verbatim
  163. ===============================================================================
  164. ##### PVD configuration functions #####
  165. ===============================================================================
  166. [..]
  167. (+) The PVD is used to monitor the VDD power supply by comparing it to a
  168. threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
  169. (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
  170. than the PVD threshold. This event is internally connected to the EXTI
  171. line16 and can generate an interrupt if enabled through the EXTI registers.
  172. (+) The PVD is stopped in Standby mode.
  173. @endverbatim
  174. * @{
  175. */
  176. /**
  177. * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
  178. * @param PWR_PVDLevel: specifies the PVD detection level
  179. * This parameter can be one of the following values:
  180. * @arg PWR_PVDLevel_0
  181. * @arg PWR_PVDLevel_1
  182. * @arg PWR_PVDLevel_2
  183. * @arg PWR_PVDLevel_3
  184. * @arg PWR_PVDLevel_4
  185. * @arg PWR_PVDLevel_5
  186. * @arg PWR_PVDLevel_6
  187. * @arg PWR_PVDLevel_7
  188. * @note Refer to the electrical characteristics of your device datasheet for
  189. * more details about the voltage threshold corresponding to each
  190. * detection level.
  191. * @retval None
  192. */
  193. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
  194. {
  195. uint32_t tmpreg = 0;
  196. /* Check the parameters */
  197. assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
  198. tmpreg = PWR->CR;
  199. /* Clear PLS[7:5] bits */
  200. tmpreg &= CR_PLS_MASK;
  201. /* Set PLS[7:5] bits according to PWR_PVDLevel value */
  202. tmpreg |= PWR_PVDLevel;
  203. /* Store the new value */
  204. PWR->CR = tmpreg;
  205. }
  206. /**
  207. * @brief Enables or disables the Power Voltage Detector(PVD).
  208. * @param NewState: new state of the PVD.
  209. * This parameter can be: ENABLE or DISABLE.
  210. * @retval None
  211. */
  212. void PWR_PVDCmd(FunctionalState NewState)
  213. {
  214. /* Check the parameters */
  215. assert_param(IS_FUNCTIONAL_STATE(NewState));
  216. *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
  217. }
  218. /**
  219. * @}
  220. */
  221. /** @defgroup PWR_Group3 WakeUp pin configuration functions
  222. * @brief WakeUp pin configuration functions
  223. *
  224. @verbatim
  225. ===============================================================================
  226. ##### WakeUp pin configuration functions #####
  227. ===============================================================================
  228. [..]
  229. (+) WakeUp pin is used to wakeup the system from Standby mode. This pin is
  230. forced in input pull down configuration and is active on rising edges.
  231. (+) There is one Wake-up pin: Wake-up Pin 1 on PA.00.
  232. (++) For STM32F446xx there are two Wake-Up pins: Pin1 on PA.00 and Pin2 on PC.13
  233. (++) For STM32F410xx/STM32F412xG/STM32F413_423xx there are three Wake-Up pins: Pin1 on PA.00, Pin2 on PC.00 and Pin3 on PC.01
  234. @endverbatim
  235. * @{
  236. */
  237. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F411xE)
  238. /**
  239. * @brief Enables or disables the WakeUp Pin functionality.
  240. * @param NewState: new state of the WakeUp Pin functionality.
  241. * This parameter can be: ENABLE or DISABLE.
  242. * @retval None
  243. */
  244. void PWR_WakeUpPinCmd(FunctionalState NewState)
  245. {
  246. /* Check the parameters */
  247. assert_param(IS_FUNCTIONAL_STATE(NewState));
  248. *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
  249. }
  250. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE */
  251. #if defined(STM32F410xx) || defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)
  252. /**
  253. * @brief Enables or disables the WakeUp Pin functionality.
  254. * @param PWR_WakeUpPinx: specifies the WakeUp Pin.
  255. * This parameter can be one of the following values:
  256. * @arg PWR_WakeUp_Pin1: WKUP1 pin is used for wakeup from Standby mode.
  257. * @arg PWR_WakeUp_Pin2: WKUP2 pin is used for wakeup from Standby mode.
  258. * @arg PWR_WakeUp_Pin3: WKUP3 pin is used for wakeup from Standby mode.(only for STM32F410xx, STM32F412xG and STM32F413_423xx Devices)
  259. * @param NewState: new state of the WakeUp Pin functionality.
  260. * This parameter can be: ENABLE or DISABLE.
  261. * @retval None
  262. */
  263. void PWR_WakeUpPinCmd(uint32_t PWR_WakeUpPinx, FunctionalState NewState)
  264. {
  265. /* Check the parameters */
  266. assert_param(IS_FUNCTIONAL_STATE(NewState));
  267. assert_param(IS_PWR_WAKEUP_PIN(NewState));
  268. if(PWR_WakeUpPinx == PWR_WakeUp_Pin1) /* PWR_WakeUp_Pin1 */
  269. {
  270. *(__IO uint32_t *) CSR_EWUP1_BB = (uint32_t)NewState;
  271. }
  272. #if defined(STM32F410xx)|| defined(STM32F412xG) || defined(STM32F413_423xx)
  273. else if(PWR_WakeUpPinx == PWR_WakeUp_Pin3) /* PWR_WakeUp_Pin3 */
  274. {
  275. *(__IO uint32_t *) CSR_EWUP3_BB = (uint32_t)NewState;
  276. }
  277. #endif /* STM32F410xx */
  278. else /* PWR_WakeUp_Pin2 */
  279. {
  280. *(__IO uint32_t *) CSR_EWUP2_BB = (uint32_t)NewState;
  281. }
  282. }
  283. #endif /* STM32F410xx || STM32F412xG || STM32F413_423xx || STM32F446xx */
  284. /**
  285. * @}
  286. */
  287. /** @defgroup PWR_Group4 Main and Backup Regulators configuration functions
  288. * @brief Main and Backup Regulators configuration functions
  289. *
  290. @verbatim
  291. ===============================================================================
  292. ##### Main and Backup Regulators configuration functions #####
  293. ===============================================================================
  294. [..]
  295. (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from
  296. the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is
  297. retained even in Standby or VBAT mode when the low power backup regulator
  298. is enabled. It can be considered as an internal EEPROM when VBAT is
  299. always present. You can use the PWR_BackupRegulatorCmd() function to
  300. enable the low power backup regulator and use the PWR_GetFlagStatus
  301. (PWR_FLAG_BRR) to check if it is ready or not.
  302. (+) When the backup domain is supplied by VDD (analog switch connected to VDD)
  303. the backup SRAM is powered from VDD which replaces the VBAT power supply to
  304. save battery life.
  305. (+) The backup SRAM is not mass erased by an tamper event. It is read
  306. protected to prevent confidential data, such as cryptographic private
  307. key, from being accessed. The backup SRAM can be erased only through
  308. the Flash interface when a protection level change from level 1 to
  309. level 0 is requested.
  310. -@- Refer to the description of Read protection (RDP) in the reference manual.
  311. (+) The main internal regulator can be configured to have a tradeoff between
  312. performance and power consumption when the device does not operate at
  313. the maximum frequency.
  314. (+) For STM32F405xx/407xx and STM32F415xx/417xx Devices, the regulator can be
  315. configured on the fly through PWR_MainRegulatorModeConfig() function which
  316. configure VOS bit in PWR_CR register:
  317. (++) When this bit is set (Regulator voltage output Scale 1 mode selected)
  318. the System frequency can go up to 168 MHz.
  319. (++) When this bit is reset (Regulator voltage output Scale 2 mode selected)
  320. the System frequency can go up to 144 MHz.
  321. (+) For STM32F42xxx/43xxx Devices, the regulator can be configured through
  322. PWR_MainRegulatorModeConfig() function which configure VOS[1:0] bits in
  323. PWR_CR register:
  324. which configure VOS[1:0] bits in PWR_CR register:
  325. (++) When VOS[1:0] = 11 (Regulator voltage output Scale 1 mode selected)
  326. the System frequency can go up to 168 MHz.
  327. (++) When VOS[1:0] = 10 (Regulator voltage output Scale 2 mode selected)
  328. the System frequency can go up to 144 MHz.
  329. (++) When VOS[1:0] = 01 (Regulator voltage output Scale 3 mode selected)
  330. the System frequency can go up to 120 MHz.
  331. (+) For STM32F42xxx/43xxx Devices, the scale can be modified only when the PLL
  332. is OFF and the HSI or HSE clock source is selected as system clock.
  333. The new value programmed is active only when the PLL is ON.
  334. When the PLL is OFF, the voltage scale 3 is automatically selected.
  335. Refer to the datasheets for more details.
  336. (+) For STM32F42xxx/43xxx Devices, in Run mode: the main regulator has
  337. 2 operating modes available:
  338. (++) Normal mode: The CPU and core logic operate at maximum frequency at a given
  339. voltage scaling (scale 1, scale 2 or scale 3)
  340. (++) Over-drive mode: This mode allows the CPU and the core logic to operate at a
  341. higher frequency than the normal mode for a given voltage scaling (scale 1,
  342. scale 2 or scale 3). This mode is enabled through PWR_OverDriveCmd() function and
  343. PWR_OverDriveSWCmd() function, to enter or exit from Over-drive mode please follow
  344. the sequence described in Reference manual.
  345. (+) For STM32F42xxx/43xxx Devices, in Stop mode: the main regulator or low power regulator
  346. supplies a low power voltage to the 1.2V domain, thus preserving the content of registers
  347. and internal SRAM. 2 operating modes are available:
  348. (++) Normal mode: the 1.2V domain is preserved in nominal leakage mode. This mode is only
  349. available when the main regulator or the low power regulator is used in Scale 3 or
  350. low voltage mode.
  351. (++) Under-drive mode: the 1.2V domain is preserved in reduced leakage mode. This mode is only
  352. available when the main regulator or the low power regulator is in low voltage mode.
  353. This mode is enabled through PWR_UnderDriveCmd() function.
  354. @endverbatim
  355. * @{
  356. */
  357. /**
  358. * @brief Enables or disables the Backup Regulator.
  359. * @param NewState: new state of the Backup Regulator.
  360. * This parameter can be: ENABLE or DISABLE.
  361. * @retval None
  362. */
  363. void PWR_BackupRegulatorCmd(FunctionalState NewState)
  364. {
  365. /* Check the parameters */
  366. assert_param(IS_FUNCTIONAL_STATE(NewState));
  367. *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)NewState;
  368. }
  369. /**
  370. * @brief Configures the main internal regulator output voltage.
  371. * @param PWR_Regulator_Voltage: specifies the regulator output voltage to achieve
  372. * a tradeoff between performance and power consumption when the device does
  373. * not operate at the maximum frequency (refer to the datasheets for more details).
  374. * This parameter can be one of the following values:
  375. * @arg PWR_Regulator_Voltage_Scale1: Regulator voltage output Scale 1 mode,
  376. * System frequency up to 168 MHz.
  377. * @arg PWR_Regulator_Voltage_Scale2: Regulator voltage output Scale 2 mode,
  378. * System frequency up to 144 MHz.
  379. * @arg PWR_Regulator_Voltage_Scale3: Regulator voltage output Scale 3 mode,
  380. * System frequency up to 120 MHz (only for STM32F42xxx/43xxx devices)
  381. * @retval None
  382. */
  383. void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage)
  384. {
  385. uint32_t tmpreg = 0;
  386. /* Check the parameters */
  387. assert_param(IS_PWR_REGULATOR_VOLTAGE(PWR_Regulator_Voltage));
  388. tmpreg = PWR->CR;
  389. /* Clear VOS[15:14] bits */
  390. tmpreg &= CR_VOS_MASK;
  391. /* Set VOS[15:14] bits according to PWR_Regulator_Voltage value */
  392. tmpreg |= PWR_Regulator_Voltage;
  393. /* Store the new value */
  394. PWR->CR = tmpreg;
  395. }
  396. /**
  397. * @brief Enables or disables the Over-Drive.
  398. *
  399. * @note This function can be used only for STM32F42xxx/STM3243xxx devices.
  400. * This mode allows the CPU and the core logic to operate at a higher frequency
  401. * than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).
  402. *
  403. * @note It is recommended to enter or exit Over-drive mode when the application is not running
  404. * critical tasks and when the system clock source is either HSI or HSE.
  405. * During the Over-drive switch activation, no peripheral clocks should be enabled.
  406. * The peripheral clocks must be enabled once the Over-drive mode is activated.
  407. *
  408. * @param NewState: new state of the Over Drive mode.
  409. * This parameter can be: ENABLE or DISABLE.
  410. * @retval None
  411. */
  412. void PWR_OverDriveCmd(FunctionalState NewState)
  413. {
  414. /* Check the parameters */
  415. assert_param(IS_FUNCTIONAL_STATE(NewState));
  416. /* Set/Reset the ODEN bit to enable/disable the Over Drive mode */
  417. *(__IO uint32_t *) CR_ODEN_BB = (uint32_t)NewState;
  418. }
  419. /**
  420. * @brief Enables or disables the Over-Drive switching.
  421. *
  422. * @note This function can be used only for STM32F42xxx/STM3243xxx devices.
  423. *
  424. * @param NewState: new state of the Over Drive switching mode.
  425. * This parameter can be: ENABLE or DISABLE.
  426. * @retval None
  427. */
  428. void PWR_OverDriveSWCmd(FunctionalState NewState)
  429. {
  430. /* Check the parameters */
  431. assert_param(IS_FUNCTIONAL_STATE(NewState));
  432. /* Set/Reset the ODSWEN bit to enable/disable the Over Drive switching mode */
  433. *(__IO uint32_t *) CR_ODSWEN_BB = (uint32_t)NewState;
  434. }
  435. /**
  436. * @brief Enables or disables the Under-Drive mode.
  437. *
  438. * @note This function can be used only for STM32F42xxx/STM3243xxx devices.
  439. * @note This mode is enabled only with STOP low power mode.
  440. * In this mode, the 1.2V domain is preserved in reduced leakage mode. This
  441. * mode is only available when the main regulator or the low power regulator
  442. * is in low voltage mode
  443. *
  444. * @note If the Under-drive mode was enabled, it is automatically disabled after
  445. * exiting Stop mode.
  446. * When the voltage regulator operates in Under-drive mode, an additional
  447. * startup delay is induced when waking up from Stop mode.
  448. *
  449. * @param NewState: new state of the Under Drive mode.
  450. * This parameter can be: ENABLE or DISABLE.
  451. * @retval None
  452. */
  453. void PWR_UnderDriveCmd(FunctionalState NewState)
  454. {
  455. /* Check the parameters */
  456. assert_param(IS_FUNCTIONAL_STATE(NewState));
  457. if (NewState != DISABLE)
  458. {
  459. /* Set the UDEN[1:0] bits to enable the Under Drive mode */
  460. PWR->CR |= (uint32_t)PWR_CR_UDEN;
  461. }
  462. else
  463. {
  464. /* Reset the UDEN[1:0] bits to disable the Under Drive mode */
  465. PWR->CR &= (uint32_t)(~PWR_CR_UDEN);
  466. }
  467. }
  468. #if defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx)
  469. /**
  470. * @brief Enables or disables the Main Regulator under drive mode.
  471. *
  472. * @note This mode is only available for STM32F427_437xx/STM32F429_439xx/STM32F446xx devices.
  473. *
  474. * @param NewState: new state of the Main Regulator Under Drive mode.
  475. * This parameter can be: ENABLE or DISABLE.
  476. * @retval None
  477. */
  478. void PWR_MainRegulatorUnderDriveCmd(FunctionalState NewState)
  479. {
  480. /* Check the parameters */
  481. assert_param(IS_FUNCTIONAL_STATE(NewState));
  482. if (NewState != DISABLE)
  483. {
  484. *(__IO uint32_t *) CR_MRUDS_BB = (uint32_t)ENABLE;
  485. }
  486. else
  487. {
  488. *(__IO uint32_t *) CR_MRUDS_BB = (uint32_t)DISABLE;
  489. }
  490. }
  491. /**
  492. * @brief Enables or disables the Low Power Regulator under drive mode.
  493. *
  494. * @note This mode is only available for STM32F427_437xx/STM32F429_439xx/STM32F446xx devices.
  495. *
  496. * @param NewState: new state of the Low Power Regulator Under Drive mode.
  497. * This parameter can be: ENABLE or DISABLE.
  498. * @retval None
  499. */
  500. void PWR_LowRegulatorUnderDriveCmd(FunctionalState NewState)
  501. {
  502. /* Check the parameters */
  503. assert_param(IS_FUNCTIONAL_STATE(NewState));
  504. if (NewState != DISABLE)
  505. {
  506. *(__IO uint32_t *) CR_LPUDS_BB = (uint32_t)ENABLE;
  507. }
  508. else
  509. {
  510. *(__IO uint32_t *) CR_LPUDS_BB = (uint32_t)DISABLE;
  511. }
  512. }
  513. #endif /* STM32F427_437xx || STM32F429_439xx || STM32F446xx */
  514. #if defined(STM32F401xx) || defined(STM32F410xx) || defined(STM32F411xE) || defined(STM32F412xG) || defined(STM32F413_423xx)
  515. /**
  516. * @brief Enables or disables the Main Regulator low voltage mode.
  517. *
  518. * @note This mode is only available for STM32F401xx/STM32F410xx/STM32F411xx/STM32F412xG/STM32F413_423xx devices.
  519. *
  520. * @param NewState: new state of the Main Regulator Low Voltage mode.
  521. * This parameter can be: ENABLE or DISABLE.
  522. * @retval None
  523. */
  524. void PWR_MainRegulatorLowVoltageCmd(FunctionalState NewState)
  525. {
  526. /* Check the parameters */
  527. assert_param(IS_FUNCTIONAL_STATE(NewState));
  528. if (NewState != DISABLE)
  529. {
  530. *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)ENABLE;
  531. }
  532. else
  533. {
  534. *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)DISABLE;
  535. }
  536. }
  537. /**
  538. * @brief Enables or disables the Low Power Regulator low voltage mode.
  539. *
  540. * @note This mode is only available for STM32F401xx/STM32F410xx/STM32F411xx/STM32F412xG/STM32F413_423xx devices.
  541. *
  542. * @param NewState: new state of the Low Power Regulator Low Voltage mode.
  543. * This parameter can be: ENABLE or DISABLE.
  544. * @retval None
  545. */
  546. void PWR_LowRegulatorLowVoltageCmd(FunctionalState NewState)
  547. {
  548. /* Check the parameters */
  549. assert_param(IS_FUNCTIONAL_STATE(NewState));
  550. if (NewState != DISABLE)
  551. {
  552. *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)ENABLE;
  553. }
  554. else
  555. {
  556. *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)DISABLE;
  557. }
  558. }
  559. #endif /* STM32F401xx || STM32F410xx || STM32F411xE || STM32F412xG || STM32F413_423xx */
  560. /**
  561. * @}
  562. */
  563. /** @defgroup PWR_Group5 FLASH Power Down configuration functions
  564. * @brief FLASH Power Down configuration functions
  565. *
  566. @verbatim
  567. ===============================================================================
  568. ##### FLASH Power Down configuration functions #####
  569. ===============================================================================
  570. [..]
  571. (+) By setting the FPDS bit in the PWR_CR register by using the
  572. PWR_FlashPowerDownCmd() function, the Flash memory also enters power
  573. down mode when the device enters Stop mode. When the Flash memory
  574. is in power down mode, an additional startup delay is incurred when
  575. waking up from Stop mode.
  576. @endverbatim
  577. * @{
  578. */
  579. /**
  580. * @brief Enables or disables the Flash Power Down in STOP mode.
  581. * @param NewState: new state of the Flash power mode.
  582. * This parameter can be: ENABLE or DISABLE.
  583. * @retval None
  584. */
  585. void PWR_FlashPowerDownCmd(FunctionalState NewState)
  586. {
  587. /* Check the parameters */
  588. assert_param(IS_FUNCTIONAL_STATE(NewState));
  589. *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)NewState;
  590. }
  591. /**
  592. * @}
  593. */
  594. /** @defgroup PWR_Group6 Low Power modes configuration functions
  595. * @brief Low Power modes configuration functions
  596. *
  597. @verbatim
  598. ===============================================================================
  599. ##### Low Power modes configuration functions #####
  600. ===============================================================================
  601. [..]
  602. The devices feature 3 low-power modes:
  603. (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running.
  604. (+) Stop mode: all clocks are stopped, regulator running, regulator
  605. in low power mode
  606. (+) Standby mode: 1.2V domain powered off.
  607. *** Sleep mode ***
  608. ==================
  609. [..]
  610. (+) Entry:
  611. (++) The Sleep mode is entered by using the __WFI() or __WFE() functions.
  612. (+) Exit:
  613. (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
  614. controller (NVIC) can wake up the device from Sleep mode.
  615. *** Stop mode ***
  616. =================
  617. [..]
  618. In Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI,
  619. and the HSE RC oscillators are disabled. Internal SRAM and register contents
  620. are preserved.
  621. The voltage regulator can be configured either in normal or low-power mode.
  622. To minimize the consumption In Stop mode, FLASH can be powered off before
  623. entering the Stop mode. It can be switched on again by software after exiting
  624. the Stop mode using the PWR_FlashPowerDownCmd() function.
  625. (+) Entry:
  626. (++) The Stop mode is entered using the PWR_EnterSTOPMode(PWR_MainRegulator_ON)
  627. function with:
  628. (+++) Main regulator ON.
  629. (+++) Low Power regulator ON.
  630. (+) Exit:
  631. (++) Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
  632. *** Standby mode ***
  633. ====================
  634. [..]
  635. The Standby mode allows to achieve the lowest power consumption. It is based
  636. on the Cortex-M4 deepsleep mode, with the voltage regulator disabled.
  637. The 1.2V domain is consequently powered off. The PLL, the HSI oscillator and
  638. the HSE oscillator are also switched off. SRAM and register contents are lost
  639. except for the RTC registers, RTC backup registers, backup SRAM and Standby
  640. circuitry.
  641. The voltage regulator is OFF.
  642. (+) Entry:
  643. (++) The Standby mode is entered using the PWR_EnterSTANDBYMode() function.
  644. (+) Exit:
  645. (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
  646. tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
  647. *** Auto-wakeup (AWU) from low-power mode ***
  648. =============================================
  649. [..]
  650. The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
  651. Wakeup event, a tamper event, a time-stamp event, or a comparator event,
  652. without depending on an external interrupt (Auto-wakeup mode).
  653. (#) RTC auto-wakeup (AWU) from the Stop mode
  654. (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to:
  655. (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt
  656. or Event modes) using the EXTI_Init() function.
  657. (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
  658. (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
  659. and RTC_AlarmCmd() functions.
  660. (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
  661. is necessary to:
  662. (+++) Configure the EXTI Line 21 to be sensitive to rising edges (Interrupt
  663. or Event modes) using the EXTI_Init() function.
  664. (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
  665. function
  666. (+++) Configure the RTC to detect the tamper or time stamp event using the
  667. RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
  668. functions.
  669. (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to:
  670. (+++) Configure the EXTI Line 22 to be sensitive to rising edges (Interrupt
  671. or Event modes) using the EXTI_Init() function.
  672. (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
  673. (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
  674. RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
  675. (#) RTC auto-wakeup (AWU) from the Standby mode
  676. (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to:
  677. (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
  678. (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
  679. and RTC_AlarmCmd() functions.
  680. (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it
  681. is necessary to:
  682. (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
  683. function
  684. (+++) Configure the RTC to detect the tamper or time stamp event using the
  685. RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
  686. functions.
  687. (++) To wake up from the Standby mode with an RTC WakeUp event, it is necessary to:
  688. (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
  689. (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
  690. RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
  691. @endverbatim
  692. * @{
  693. */
  694. /**
  695. * @brief Enters STOP mode.
  696. *
  697. * @note In Stop mode, all I/O pins keep the same state as in Run mode.
  698. * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
  699. * the HSI RC oscillator is selected as system clock.
  700. * @note When the voltage regulator operates in low power mode, an additional
  701. * startup delay is incurred when waking up from Stop mode.
  702. * By keeping the internal regulator ON during Stop mode, the consumption
  703. * is higher although the startup time is reduced.
  704. *
  705. * @param PWR_Regulator: specifies the regulator state in STOP mode.
  706. * This parameter can be one of the following values:
  707. * @arg PWR_MainRegulator_ON: STOP mode with regulator ON
  708. * @arg PWR_LowPowerRegulator_ON: STOP mode with low power regulator ON
  709. * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
  710. * This parameter can be one of the following values:
  711. * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
  712. * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
  713. * @retval None
  714. */
  715. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
  716. {
  717. uint32_t tmpreg = 0;
  718. /* Check the parameters */
  719. assert_param(IS_PWR_REGULATOR(PWR_Regulator));
  720. assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
  721. /* Select the regulator state in STOP mode ---------------------------------*/
  722. tmpreg = PWR->CR;
  723. /* Clear PDDS and LPDS bits */
  724. tmpreg &= CR_DS_MASK;
  725. /* Set LPDS, MRLVDS and LPLVDS bits according to PWR_Regulator value */
  726. tmpreg |= PWR_Regulator;
  727. /* Store the new value */
  728. PWR->CR = tmpreg;
  729. /* Set SLEEPDEEP bit of Cortex System Control Register */
  730. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  731. /* Select STOP mode entry --------------------------------------------------*/
  732. if(PWR_STOPEntry == PWR_STOPEntry_WFI)
  733. {
  734. /* Request Wait For Interrupt */
  735. __WFI();
  736. }
  737. else
  738. {
  739. /* Request Wait For Event */
  740. __WFE();
  741. }
  742. /* Reset SLEEPDEEP bit of Cortex System Control Register */
  743. SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
  744. }
  745. /**
  746. * @brief Enters in Under-Drive STOP mode.
  747. *
  748. * @note This mode is only available for STM32F42xxx/STM3243xxx devices.
  749. *
  750. * @note This mode can be selected only when the Under-Drive is already active
  751. *
  752. * @note In Stop mode, all I/O pins keep the same state as in Run mode.
  753. * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
  754. * the HSI RC oscillator is selected as system clock.
  755. * @note When the voltage regulator operates in low power mode, an additional
  756. * startup delay is incurred when waking up from Stop mode.
  757. * By keeping the internal regulator ON during Stop mode, the consumption
  758. * is higher although the startup time is reduced.
  759. *
  760. * @param PWR_Regulator: specifies the regulator state in STOP mode.
  761. * This parameter can be one of the following values:
  762. * @arg PWR_MainRegulator_UnderDrive_ON: Main Regulator in under-drive mode
  763. * and Flash memory in power-down when the device is in Stop under-drive mode
  764. * @arg PWR_LowPowerRegulator_UnderDrive_ON: Low Power Regulator in under-drive mode
  765. * and Flash memory in power-down when the device is in Stop under-drive mode
  766. * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
  767. * This parameter can be one of the following values:
  768. * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
  769. * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
  770. * @retval None
  771. */
  772. void PWR_EnterUnderDriveSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
  773. {
  774. uint32_t tmpreg = 0;
  775. /* Check the parameters */
  776. assert_param(IS_PWR_REGULATOR_UNDERDRIVE(PWR_Regulator));
  777. assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
  778. /* Select the regulator state in STOP mode ---------------------------------*/
  779. tmpreg = PWR->CR;
  780. /* Clear PDDS and LPDS bits */
  781. tmpreg &= CR_DS_MASK;
  782. /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
  783. tmpreg |= PWR_Regulator;
  784. /* Store the new value */
  785. PWR->CR = tmpreg;
  786. /* Set SLEEPDEEP bit of Cortex System Control Register */
  787. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  788. /* Select STOP mode entry --------------------------------------------------*/
  789. if(PWR_STOPEntry == PWR_STOPEntry_WFI)
  790. {
  791. /* Request Wait For Interrupt */
  792. __WFI();
  793. }
  794. else
  795. {
  796. /* Request Wait For Event */
  797. __WFE();
  798. }
  799. /* Reset SLEEPDEEP bit of Cortex System Control Register */
  800. SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
  801. }
  802. /**
  803. * @brief Enters STANDBY mode.
  804. * @note In Standby mode, all I/O pins are high impedance except for:
  805. * - Reset pad (still available)
  806. * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC
  807. * Alarm out, or RTC clock calibration out.
  808. * - RTC_AF2 pin (PI8) if configured for tamper or time-stamp.
  809. * - WKUP pin 1 (PA0) if enabled.
  810. * @note The Wakeup flag (WUF) need to be cleared at application level before to call this function
  811. * @param None
  812. * @retval None
  813. */
  814. void PWR_EnterSTANDBYMode(void)
  815. {
  816. /* Select STANDBY mode */
  817. PWR->CR |= PWR_CR_PDDS;
  818. /* Set SLEEPDEEP bit of Cortex System Control Register */
  819. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  820. /* This option is used to ensure that store operations are completed */
  821. #if defined ( __CC_ARM )
  822. __force_stores();
  823. #endif
  824. /* Request Wait For Interrupt */
  825. __WFI();
  826. }
  827. /**
  828. * @}
  829. */
  830. /** @defgroup PWR_Group7 Flags management functions
  831. * @brief Flags management functions
  832. *
  833. @verbatim
  834. ===============================================================================
  835. ##### Flags management functions #####
  836. ===============================================================================
  837. @endverbatim
  838. * @{
  839. */
  840. /**
  841. * @brief Checks whether the specified PWR flag is set or not.
  842. * @param PWR_FLAG: specifies the flag to check.
  843. * This parameter can be one of the following values:
  844. * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
  845. * was received from the WKUP pin or from the RTC alarm (Alarm A
  846. * or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
  847. * An additional wakeup event is detected if the WKUP pin is enabled
  848. * (by setting the EWUP bit) when the WKUP pin level is already high.
  849. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
  850. * resumed from StandBy mode.
  851. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
  852. * by the PWR_PVDCmd() function. The PVD is stopped by Standby mode
  853. * For this reason, this bit is equal to 0 after Standby or reset
  854. * until the PVDE bit is set.
  855. * @arg PWR_FLAG_BRR: Backup regulator ready flag. This bit is not reset
  856. * when the device wakes up from Standby mode or by a system reset
  857. * or power reset.
  858. * @arg PWR_FLAG_VOSRDY: This flag indicates that the Regulator voltage
  859. * scaling output selection is ready.
  860. * @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode
  861. * is ready (STM32F42xxx/43xxx devices)
  862. * @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode
  863. * switching is ready (STM32F42xxx/43xxx devices)
  864. * @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode
  865. * is enabled in Stop mode (STM32F42xxx/43xxx devices)
  866. * @retval The new state of PWR_FLAG (SET or RESET).
  867. */
  868. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
  869. {
  870. FlagStatus bitstatus = RESET;
  871. /* Check the parameters */
  872. assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
  873. if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
  874. {
  875. bitstatus = SET;
  876. }
  877. else
  878. {
  879. bitstatus = RESET;
  880. }
  881. /* Return the flag status */
  882. return bitstatus;
  883. }
  884. /**
  885. * @brief Clears the PWR's pending flags.
  886. * @param PWR_FLAG: specifies the flag to clear.
  887. * This parameter can be one of the following values:
  888. * @arg PWR_FLAG_WU: Wake Up flag
  889. * @arg PWR_FLAG_SB: StandBy flag
  890. * @arg PWR_FLAG_UDRDY: Under-drive ready flag (STM32F42xxx/43xxx devices)
  891. * @retval None
  892. */
  893. void PWR_ClearFlag(uint32_t PWR_FLAG)
  894. {
  895. /* Check the parameters */
  896. assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
  897. #if defined (STM32F427_437xx) || defined (STM32F429_439xx)
  898. if (PWR_FLAG != PWR_FLAG_UDRDY)
  899. {
  900. PWR->CR |= PWR_FLAG << 2;
  901. }
  902. else
  903. {
  904. PWR->CSR |= PWR_FLAG_UDRDY;
  905. }
  906. #endif /* STM32F427_437xx || STM32F429_439xx */
  907. #if defined (STM32F40_41xxx) || defined (STM32F401xx) || defined (STM32F410xx) || defined (STM32F411xE) || defined(STM32F412xG) || defined(STM32F413_423xx)
  908. PWR->CR |= PWR_FLAG << 2;
  909. #endif /* STM32F40_41xxx || STM32F401xx || STM32F410xx || STM32F411xE || STM32F412xG || STM32F413_423xx */
  910. }
  911. /**
  912. * @}
  913. */
  914. /**
  915. * @}
  916. */
  917. /**
  918. * @}
  919. */
  920. /**
  921. * @}
  922. */