system_stm32h7xx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /**
  2. ******************************************************************************
  3. * @file system_stm32h7xx.c
  4. * @author MCD Application Team
  5. * @brief CMSIS Cortex-Mx Device Peripheral Access Layer System Source File.
  6. *
  7. * This file provides two functions and one global variable to be called from
  8. * user application:
  9. * - ExitRun0Mode(): Specifies the Power Supply source. This function is
  10. * called at startup just after reset and before the call
  11. * of SystemInit(). This call is made inside
  12. * the "startup_stm32h7xx.s" file.
  13. *
  14. * - SystemInit(): This function is called at startup just after reset and
  15. * before branch to main program. This call is made inside
  16. * the "startup_stm32h7xx.s" file.
  17. *
  18. * - SystemCoreClock variable: Contains the core clock, it can be used
  19. * by the user application to setup the SysTick
  20. * timer or configure other parameters.
  21. *
  22. * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
  23. * be called whenever the core clock is changed
  24. * during program execution.
  25. *
  26. *
  27. ******************************************************************************
  28. * @attention
  29. *
  30. * Copyright (c) 2017 STMicroelectronics.
  31. * All rights reserved.
  32. *
  33. * This software is licensed under terms that can be found in the LICENSE file
  34. * in the root directory of this software component.
  35. * If no LICENSE file comes with this software, it is provided AS-IS.
  36. *
  37. ******************************************************************************
  38. */
  39. /** @addtogroup CMSIS
  40. * @{
  41. */
  42. /** @addtogroup stm32h7xx_system
  43. * @{
  44. */
  45. /** @addtogroup STM32H7xx_System_Private_Includes
  46. * @{
  47. */
  48. #include "stm32h7xx.h"
  49. #include <math.h>
  50. #if !defined (HSE_VALUE)
  51. #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
  52. #endif /* HSE_VALUE */
  53. #if !defined (CSI_VALUE)
  54. #define CSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
  55. #endif /* CSI_VALUE */
  56. #if !defined (HSI_VALUE)
  57. #define HSI_VALUE ((uint32_t)64000000) /*!< Value of the Internal oscillator in Hz*/
  58. #endif /* HSI_VALUE */
  59. /**
  60. * @}
  61. */
  62. /** @addtogroup STM32H7xx_System_Private_TypesDefinitions
  63. * @{
  64. */
  65. /**
  66. * @}
  67. */
  68. /** @addtogroup STM32H7xx_System_Private_Defines
  69. * @{
  70. */
  71. /************************* Miscellaneous Configuration ************************/
  72. /*!< Uncomment the following line if you need to use initialized data in D2 domain SRAM (AHB SRAM) */
  73. /* #define DATA_IN_D2_SRAM */
  74. /* Note: Following vector table addresses must be defined in line with linker
  75. configuration. */
  76. /*!< Uncomment the following line if you need to relocate the vector table
  77. anywhere in FLASH BANK1 or AXI SRAM, else the vector table is kept at the automatic
  78. remap of boot address selected */
  79. /* #define USER_VECT_TAB_ADDRESS */
  80. #if defined(USER_VECT_TAB_ADDRESS)
  81. #if defined(DUAL_CORE) && defined(CORE_CM4)
  82. /*!< Uncomment the following line if you need to relocate your vector Table
  83. in D2 AXI SRAM else user remap will be done in FLASH BANK2. */
  84. /* #define VECT_TAB_SRAM */
  85. #if defined(VECT_TAB_SRAM)
  86. #define VECT_TAB_BASE_ADDRESS D2_AXISRAM_BASE /*!< Vector Table base address field.
  87. This value must be a multiple of 0x400. */
  88. #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
  89. This value must be a multiple of 0x400. */
  90. #else
  91. #define VECT_TAB_BASE_ADDRESS FLASH_BANK2_BASE /*!< Vector Table base address field.
  92. This value must be a multiple of 0x400. */
  93. #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
  94. This value must be a multiple of 0x400. */
  95. #endif /* VECT_TAB_SRAM */
  96. #else
  97. /*!< Uncomment the following line if you need to relocate your vector Table
  98. in D1 AXI SRAM else user remap will be done in FLASH BANK1. */
  99. /* #define VECT_TAB_SRAM */
  100. #if defined(VECT_TAB_SRAM)
  101. #define VECT_TAB_BASE_ADDRESS D1_AXISRAM_BASE /*!< Vector Table base address field.
  102. This value must be a multiple of 0x400. */
  103. #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
  104. This value must be a multiple of 0x400. */
  105. #else
  106. #define VECT_TAB_BASE_ADDRESS FLASH_BANK1_BASE /*!< Vector Table base address field.
  107. This value must be a multiple of 0x400. */
  108. #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
  109. This value must be a multiple of 0x400. */
  110. #endif /* VECT_TAB_SRAM */
  111. #endif /* DUAL_CORE && CORE_CM4 */
  112. #endif /* USER_VECT_TAB_ADDRESS */
  113. /******************************************************************************/
  114. /**
  115. * @}
  116. */
  117. /** @addtogroup STM32H7xx_System_Private_Macros
  118. * @{
  119. */
  120. /**
  121. * @}
  122. */
  123. /** @addtogroup STM32H7xx_System_Private_Variables
  124. * @{
  125. */
  126. /* This variable is updated in three ways:
  127. 1) by calling CMSIS function SystemCoreClockUpdate()
  128. 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
  129. 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
  130. Note: If you use this function to configure the system clock; then there
  131. is no need to call the 2 first functions listed above, since SystemCoreClock
  132. variable is updated automatically.
  133. */
  134. uint32_t SystemCoreClock = 64000000;
  135. uint32_t SystemD2Clock = 64000000;
  136. const uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
  137. /**
  138. * @}
  139. */
  140. /** @addtogroup STM32H7xx_System_Private_FunctionPrototypes
  141. * @{
  142. */
  143. /**
  144. * @}
  145. */
  146. /** @addtogroup STM32H7xx_System_Private_Functions
  147. * @{
  148. */
  149. /**
  150. * @brief Setup the microcontroller system
  151. * Initialize the FPU setting and vector table location
  152. * configuration.
  153. * @param None
  154. * @retval None
  155. */
  156. void SystemInit (void)
  157. {
  158. #if defined (DATA_IN_D2_SRAM)
  159. __IO uint32_t tmpreg;
  160. #endif /* DATA_IN_D2_SRAM */
  161. /* FPU settings ------------------------------------------------------------*/
  162. #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  163. SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */
  164. #endif
  165. /* Reset the RCC clock configuration to the default reset state ------------*/
  166. /* Increasing the CPU frequency */
  167. if(FLASH_LATENCY_DEFAULT > (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)))
  168. {
  169. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  170. MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
  171. }
  172. /* Set HSION bit */
  173. RCC->CR |= RCC_CR_HSION;
  174. /* Reset CFGR register */
  175. RCC->CFGR = 0x00000000;
  176. /* Reset HSEON, HSECSSON, CSION, HSI48ON, CSIKERON, PLL1ON, PLL2ON and PLL3ON bits */
  177. RCC->CR &= 0xEAF6ED7FU;
  178. /* Decreasing the number of wait states because of lower CPU frequency */
  179. if(FLASH_LATENCY_DEFAULT < (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)))
  180. {
  181. /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
  182. MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
  183. }
  184. #if defined(D3_SRAM_BASE)
  185. /* Reset D1CFGR register */
  186. RCC->D1CFGR = 0x00000000;
  187. /* Reset D2CFGR register */
  188. RCC->D2CFGR = 0x00000000;
  189. /* Reset D3CFGR register */
  190. RCC->D3CFGR = 0x00000000;
  191. #else
  192. /* Reset CDCFGR1 register */
  193. RCC->CDCFGR1 = 0x00000000;
  194. /* Reset CDCFGR2 register */
  195. RCC->CDCFGR2 = 0x00000000;
  196. /* Reset SRDCFGR register */
  197. RCC->SRDCFGR = 0x00000000;
  198. #endif
  199. /* Reset PLLCKSELR register */
  200. RCC->PLLCKSELR = 0x02020200;
  201. /* Reset PLLCFGR register */
  202. RCC->PLLCFGR = 0x01FF0000;
  203. /* Reset PLL1DIVR register */
  204. RCC->PLL1DIVR = 0x01010280;
  205. /* Reset PLL1FRACR register */
  206. RCC->PLL1FRACR = 0x00000000;
  207. /* Reset PLL2DIVR register */
  208. RCC->PLL2DIVR = 0x01010280;
  209. /* Reset PLL2FRACR register */
  210. RCC->PLL2FRACR = 0x00000000;
  211. /* Reset PLL3DIVR register */
  212. RCC->PLL3DIVR = 0x01010280;
  213. /* Reset PLL3FRACR register */
  214. RCC->PLL3FRACR = 0x00000000;
  215. /* Reset HSEBYP bit */
  216. RCC->CR &= 0xFFFBFFFFU;
  217. /* Disable all interrupts */
  218. RCC->CIER = 0x00000000;
  219. #if (STM32H7_DEV_ID == 0x450UL)
  220. /* dual core CM7 or single core line */
  221. if((DBGMCU->IDCODE & 0xFFFF0000U) < 0x20000000U)
  222. {
  223. /* if stm32h7 revY*/
  224. /* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
  225. *((__IO uint32_t*)0x51008108) = 0x000000001U;
  226. }
  227. #endif /* STM32H7_DEV_ID */
  228. #if defined(DATA_IN_D2_SRAM)
  229. /* in case of initialized data in D2 SRAM (AHB SRAM), enable the D2 SRAM clock (AHB SRAM clock) */
  230. #if defined(RCC_AHB2ENR_D2SRAM3EN)
  231. RCC->AHB2ENR |= (RCC_AHB2ENR_D2SRAM1EN | RCC_AHB2ENR_D2SRAM2EN | RCC_AHB2ENR_D2SRAM3EN);
  232. #elif defined(RCC_AHB2ENR_D2SRAM2EN)
  233. RCC->AHB2ENR |= (RCC_AHB2ENR_D2SRAM1EN | RCC_AHB2ENR_D2SRAM2EN);
  234. #else
  235. RCC->AHB2ENR |= (RCC_AHB2ENR_AHBSRAM1EN | RCC_AHB2ENR_AHBSRAM2EN);
  236. #endif /* RCC_AHB2ENR_D2SRAM3EN */
  237. tmpreg = RCC->AHB2ENR;
  238. (void) tmpreg;
  239. #endif /* DATA_IN_D2_SRAM */
  240. #if defined(DUAL_CORE) && defined(CORE_CM4)
  241. /* Configure the Vector Table location add offset address for cortex-M4 ------------------*/
  242. #if defined(USER_VECT_TAB_ADDRESS)
  243. SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal D2 AXI-RAM or in Internal FLASH */
  244. #endif /* USER_VECT_TAB_ADDRESS */
  245. #else
  246. if(READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN) == 0U)
  247. {
  248. /* Enable the FMC interface clock */
  249. SET_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
  250. /*
  251. * Disable the FMC bank1 (enabled after reset).
  252. * This, prevents CPU speculation access on this bank which blocks the use of FMC during
  253. * 24us. During this time the others FMC master (such as LTDC) cannot use it!
  254. */
  255. FMC_Bank1_R->BTCR[0] = 0x000030D2;
  256. /* Disable the FMC interface clock */
  257. CLEAR_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
  258. }
  259. /* Configure the Vector Table location -------------------------------------*/
  260. #if defined(USER_VECT_TAB_ADDRESS)
  261. SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal D1 AXI-RAM or in Internal FLASH */
  262. #endif /* USER_VECT_TAB_ADDRESS */
  263. #endif /*DUAL_CORE && CORE_CM4*/
  264. }
  265. /**
  266. * @brief Update SystemCoreClock variable according to Clock Register Values.
  267. * The SystemCoreClock variable contains the core clock , it can
  268. * be used by the user application to setup the SysTick timer or configure
  269. * other parameters.
  270. *
  271. * @note Each time the core clock changes, this function must be called
  272. * to update SystemCoreClock variable value. Otherwise, any configuration
  273. * based on this variable will be incorrect.
  274. *
  275. * @note - The system frequency computed by this function is not the real
  276. * frequency in the chip. It is calculated based on the predefined
  277. * constant and the selected clock source:
  278. *
  279. * - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*)
  280. * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
  281. * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
  282. * - If SYSCLK source is PLL, SystemCoreClock will contain the CSI_VALUE(*),
  283. * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
  284. *
  285. * (*) CSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
  286. * 4 MHz) but the real value may vary depending on the variations
  287. * in voltage and temperature.
  288. * (**) HSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
  289. * 64 MHz) but the real value may vary depending on the variations
  290. * in voltage and temperature.
  291. *
  292. * (***)HSE_VALUE is a constant defined in stm32h7xx_hal.h file (default value
  293. * 25 MHz), user has to ensure that HSE_VALUE is same as the real
  294. * frequency of the crystal used. Otherwise, this function may
  295. * have wrong result.
  296. *
  297. * - The result of this function could be not correct when using fractional
  298. * value for HSE crystal.
  299. * @param None
  300. * @retval None
  301. */
  302. void SystemCoreClockUpdate (void)
  303. {
  304. uint32_t pllp, pllsource, pllm, pllfracen, hsivalue, tmp;
  305. uint32_t common_system_clock;
  306. float_t fracn1, pllvco;
  307. /* Get SYSCLK source -------------------------------------------------------*/
  308. switch (RCC->CFGR & RCC_CFGR_SWS)
  309. {
  310. case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */
  311. common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
  312. break;
  313. case RCC_CFGR_SWS_CSI: /* CSI used as system clock source */
  314. common_system_clock = CSI_VALUE;
  315. break;
  316. case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */
  317. common_system_clock = HSE_VALUE;
  318. break;
  319. case RCC_CFGR_SWS_PLL1: /* PLL1 used as system clock source */
  320. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
  321. SYSCLK = PLL_VCO / PLLR
  322. */
  323. pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
  324. pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4) ;
  325. pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
  326. fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
  327. if (pllm != 0U)
  328. {
  329. switch (pllsource)
  330. {
  331. case RCC_PLLCKSELR_PLLSRC_HSI: /* HSI used as PLL clock source */
  332. hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
  333. pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  334. break;
  335. case RCC_PLLCKSELR_PLLSRC_CSI: /* CSI used as PLL clock source */
  336. pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  337. break;
  338. case RCC_PLLCKSELR_PLLSRC_HSE: /* HSE used as PLL clock source */
  339. pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  340. break;
  341. default:
  342. hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
  343. pllvco = ((float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  344. break;
  345. }
  346. pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ;
  347. common_system_clock = (uint32_t)(float_t)(pllvco/(float_t)pllp);
  348. }
  349. else
  350. {
  351. common_system_clock = 0U;
  352. }
  353. break;
  354. default:
  355. common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
  356. break;
  357. }
  358. /* Compute SystemClock frequency --------------------------------------------------*/
  359. #if defined (RCC_D1CFGR_D1CPRE)
  360. tmp = D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos];
  361. /* common_system_clock frequency : CM7 CPU frequency */
  362. common_system_clock >>= tmp;
  363. /* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency */
  364. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
  365. #else
  366. tmp = D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE)>> RCC_CDCFGR1_CDCPRE_Pos];
  367. /* common_system_clock frequency : CM7 CPU frequency */
  368. common_system_clock >>= tmp;
  369. /* SystemD2Clock frequency : AXI and AHBs Clock frequency */
  370. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
  371. #endif
  372. #if defined(DUAL_CORE) && defined(CORE_CM4)
  373. SystemCoreClock = SystemD2Clock;
  374. #else
  375. SystemCoreClock = common_system_clock;
  376. #endif /* DUAL_CORE && CORE_CM4 */
  377. }
  378. /**
  379. * @brief Exit Run* mode and Configure the system Power Supply
  380. *
  381. * @note This function exits the Run* mode and configures the system power supply
  382. * according to the definition to be used at compilation preprocessing level.
  383. * The application shall set one of the following configuration option:
  384. * - PWR_LDO_SUPPLY
  385. * - PWR_DIRECT_SMPS_SUPPLY
  386. * - PWR_EXTERNAL_SOURCE_SUPPLY
  387. * - PWR_SMPS_1V8_SUPPLIES_LDO
  388. * - PWR_SMPS_2V5_SUPPLIES_LDO
  389. * - PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO
  390. * - PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO
  391. * - PWR_SMPS_1V8_SUPPLIES_EXT
  392. * - PWR_SMPS_2V5_SUPPLIES_EXT
  393. *
  394. * @note The function modifies the PWR->CR3 register to enable or disable specific
  395. * power supply modes and waits until the voltage level flag is set, indicating
  396. * that the power supply configuration is stable.
  397. *
  398. * @param None
  399. * @retval None
  400. */
  401. void ExitRun0Mode(void)
  402. {
  403. #if defined(USE_PWR_LDO_SUPPLY)
  404. #if defined(SMPS)
  405. /* Exit Run* mode by disabling SMPS and enabling LDO */
  406. PWR->CR3 = (PWR->CR3 & ~PWR_CR3_SMPSEN) | PWR_CR3_LDOEN;
  407. #else
  408. /* Enable LDO mode */
  409. PWR->CR3 |= PWR_CR3_LDOEN;
  410. #endif /* SMPS */
  411. /* Wait till voltage level flag is set */
  412. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  413. {}
  414. #elif defined(USE_PWR_EXTERNAL_SOURCE_SUPPLY)
  415. #if defined(SMPS)
  416. /* Exit Run* mode */
  417. PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_SMPSEN | PWR_CR3_LDOEN)) | PWR_CR3_BYPASS;
  418. #else
  419. PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_LDOEN)) | PWR_CR3_BYPASS;
  420. #endif /* SMPS */
  421. /* Wait till voltage level flag is set */
  422. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  423. {}
  424. #elif defined(USE_PWR_DIRECT_SMPS_SUPPLY) && defined(SMPS)
  425. /* Exit Run* mode */
  426. PWR->CR3 &= ~(PWR_CR3_LDOEN);
  427. /* Wait till voltage level flag is set */
  428. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  429. {}
  430. #elif defined(USE_PWR_SMPS_1V8_SUPPLIES_LDO) && defined(SMPS)
  431. /* Exit Run* mode */
  432. PWR->CR3 |= PWR_CR3_SMPSLEVEL_0 | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
  433. /* Wait till voltage level flag is set */
  434. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  435. {}
  436. #elif defined(USE_PWR_SMPS_2V5_SUPPLIES_LDO) && defined(SMPS)
  437. /* Exit Run* mode */
  438. PWR->CR3 |= PWR_CR3_SMPSLEVEL_1 | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
  439. /* Wait till voltage level flag is set */
  440. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  441. {}
  442. #elif defined(USE_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO) && defined(SMPS)
  443. /* Exit Run* mode */
  444. PWR->CR3 |= PWR_CR3_SMPSLEVEL_0 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
  445. /* Wait till voltage level flag is set */
  446. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  447. {}
  448. #elif defined(USE_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO) && defined(SMPS)
  449. /* Exit Run* mode */
  450. PWR->CR3 |= PWR_CR3_SMPSLEVEL_1 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_LDOEN;
  451. /* Wait till voltage level flag is set */
  452. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  453. {}
  454. #elif defined(USE_PWR_SMPS_1V8_SUPPLIES_EXT) && defined(SMPS)
  455. /* Exit Run* mode */
  456. PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_LDOEN)) | PWR_CR3_SMPSLEVEL_0 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_BYPASS;
  457. /* Wait till voltage level flag is set */
  458. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  459. {}
  460. #elif defined(USE_PWR_SMPS_2V5_SUPPLIES_EXT) && defined(SMPS)
  461. /* Exit Run* mode */
  462. PWR->CR3 = (PWR->CR3 & ~(PWR_CR3_LDOEN)) | PWR_CR3_SMPSLEVEL_1 | PWR_CR3_SMPSEXTHP | PWR_CR3_SMPSEN | PWR_CR3_BYPASS;
  463. /* Wait till voltage level flag is set */
  464. while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0U)
  465. {}
  466. #else
  467. /* No system power supply configuration is selected at exit Run* mode */
  468. #endif /* USE_PWR_LDO_SUPPLY */
  469. }
  470. /**
  471. * @}
  472. */
  473. /**
  474. * @}
  475. */
  476. /**
  477. * @}
  478. */