stm32l4xx_ll_utils.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_utils.c
  4. * @author MCD Application Team
  5. * @brief UTILS LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Includes ------------------------------------------------------------------*/
  36. #include "stm32l4xx_ll_utils.h"
  37. #include "stm32l4xx_ll_rcc.h"
  38. #include "stm32l4xx_ll_system.h"
  39. #include "stm32l4xx_ll_pwr.h"
  40. #ifdef USE_FULL_ASSERT
  41. #include "stm32_assert.h"
  42. #else
  43. #define assert_param(expr) ((void)0U)
  44. #endif /* USE_FULL_ASSERT */
  45. /** @addtogroup STM32L4xx_LL_Driver
  46. * @{
  47. */
  48. /** @addtogroup UTILS_LL
  49. * @{
  50. */
  51. /* Private types -------------------------------------------------------------*/
  52. /* Private variables ---------------------------------------------------------*/
  53. /* Private constants ---------------------------------------------------------*/
  54. /** @addtogroup UTILS_LL_Private_Constants
  55. * @{
  56. */
  57. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  58. #define UTILS_MAX_FREQUENCY_SCALE1 120000000U /*!< Maximum frequency for system clock at power scale1, in Hz */
  59. #define UTILS_MAX_FREQUENCY_SCALE2 26000000U /*!< Maximum frequency for system clock at power scale2, in Hz */
  60. #else
  61. #define UTILS_MAX_FREQUENCY_SCALE1 80000000U /*!< Maximum frequency for system clock at power scale1, in Hz */
  62. #define UTILS_MAX_FREQUENCY_SCALE2 26000000U /*!< Maximum frequency for system clock at power scale2, in Hz */
  63. #endif
  64. /* Defines used for PLL range */
  65. #define UTILS_PLLVCO_INPUT_MIN 4000000U /*!< Frequency min for PLLVCO input, in Hz */
  66. #define UTILS_PLLVCO_INPUT_MAX 16000000U /*!< Frequency max for PLLVCO input, in Hz */
  67. #define UTILS_PLLVCO_OUTPUT_MIN 64000000U /*!< Frequency min for PLLVCO output, in Hz */
  68. #define UTILS_PLLVCO_OUTPUT_MAX 344000000U /*!< Frequency max for PLLVCO output, in Hz */
  69. /* Defines used for HSE range */
  70. #define UTILS_HSE_FREQUENCY_MIN 4000000U /*!< Frequency min for HSE frequency, in Hz */
  71. #define UTILS_HSE_FREQUENCY_MAX 48000000U /*!< Frequency max for HSE frequency, in Hz */
  72. /* Defines used for FLASH latency according to HCLK Frequency */
  73. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  74. #define UTILS_SCALE1_LATENCY1_FREQ 20000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 1 */
  75. #define UTILS_SCALE1_LATENCY2_FREQ 40000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 1 */
  76. #define UTILS_SCALE1_LATENCY3_FREQ 60000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 1 */
  77. #define UTILS_SCALE1_LATENCY4_FREQ 80000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 1 */
  78. #define UTILS_SCALE1_LATENCY5_FREQ 100000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 1 */
  79. #define UTILS_SCALE2_LATENCY1_FREQ 8000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 2 */
  80. #define UTILS_SCALE2_LATENCY2_FREQ 16000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 2 */
  81. #else
  82. #define UTILS_SCALE1_LATENCY1_FREQ 16000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 1 */
  83. #define UTILS_SCALE1_LATENCY2_FREQ 32000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 1 */
  84. #define UTILS_SCALE1_LATENCY3_FREQ 48000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 1 */
  85. #define UTILS_SCALE1_LATENCY4_FREQ 64000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 1 */
  86. #define UTILS_SCALE2_LATENCY1_FREQ 6000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 2 */
  87. #define UTILS_SCALE2_LATENCY2_FREQ 12000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 2 */
  88. #define UTILS_SCALE2_LATENCY3_FREQ 18000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 2 */
  89. #endif
  90. /**
  91. * @}
  92. */
  93. /* Private macros ------------------------------------------------------------*/
  94. /** @addtogroup UTILS_LL_Private_Macros
  95. * @{
  96. */
  97. #define IS_LL_UTILS_SYSCLK_DIV(__VALUE__) (((__VALUE__) == LL_RCC_SYSCLK_DIV_1) \
  98. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_2) \
  99. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_4) \
  100. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_8) \
  101. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_16) \
  102. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_64) \
  103. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_128) \
  104. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_256) \
  105. || ((__VALUE__) == LL_RCC_SYSCLK_DIV_512))
  106. #define IS_LL_UTILS_APB1_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB1_DIV_1) \
  107. || ((__VALUE__) == LL_RCC_APB1_DIV_2) \
  108. || ((__VALUE__) == LL_RCC_APB1_DIV_4) \
  109. || ((__VALUE__) == LL_RCC_APB1_DIV_8) \
  110. || ((__VALUE__) == LL_RCC_APB1_DIV_16))
  111. #define IS_LL_UTILS_APB2_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB2_DIV_1) \
  112. || ((__VALUE__) == LL_RCC_APB2_DIV_2) \
  113. || ((__VALUE__) == LL_RCC_APB2_DIV_4) \
  114. || ((__VALUE__) == LL_RCC_APB2_DIV_8) \
  115. || ((__VALUE__) == LL_RCC_APB2_DIV_16))
  116. #define IS_LL_UTILS_PLLM_VALUE(__VALUE__) (((__VALUE__) == LL_RCC_PLLM_DIV_1) \
  117. || ((__VALUE__) == LL_RCC_PLLM_DIV_2) \
  118. || ((__VALUE__) == LL_RCC_PLLM_DIV_3) \
  119. || ((__VALUE__) == LL_RCC_PLLM_DIV_4) \
  120. || ((__VALUE__) == LL_RCC_PLLM_DIV_5) \
  121. || ((__VALUE__) == LL_RCC_PLLM_DIV_6) \
  122. || ((__VALUE__) == LL_RCC_PLLM_DIV_7) \
  123. || ((__VALUE__) == LL_RCC_PLLM_DIV_8))
  124. #define IS_LL_UTILS_PLLN_VALUE(__VALUE__) ((8 <= (__VALUE__)) && ((__VALUE__) <= 86))
  125. #define IS_LL_UTILS_PLLR_VALUE(__VALUE__) (((__VALUE__) == LL_RCC_PLLR_DIV_2) \
  126. || ((__VALUE__) == LL_RCC_PLLR_DIV_4) \
  127. || ((__VALUE__) == LL_RCC_PLLR_DIV_6) \
  128. || ((__VALUE__) == LL_RCC_PLLR_DIV_8))
  129. #define IS_LL_UTILS_PLLVCO_INPUT(__VALUE__) ((UTILS_PLLVCO_INPUT_MIN <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_INPUT_MAX))
  130. #define IS_LL_UTILS_PLLVCO_OUTPUT(__VALUE__) ((UTILS_PLLVCO_OUTPUT_MIN <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_OUTPUT_MAX))
  131. #define IS_LL_UTILS_PLL_FREQUENCY(__VALUE__) ((LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1) ? ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE1) : \
  132. ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE2))
  133. #define IS_LL_UTILS_HSE_BYPASS(__STATE__) (((__STATE__) == LL_UTILS_HSEBYPASS_ON) \
  134. || ((__STATE__) == LL_UTILS_HSEBYPASS_OFF))
  135. #define IS_LL_UTILS_HSE_FREQUENCY(__FREQUENCY__) (((__FREQUENCY__) >= UTILS_HSE_FREQUENCY_MIN) && ((__FREQUENCY__) <= UTILS_HSE_FREQUENCY_MAX))
  136. /**
  137. * @}
  138. */
  139. /* Private function prototypes -----------------------------------------------*/
  140. /** @defgroup UTILS_LL_Private_Functions UTILS Private functions
  141. * @{
  142. */
  143. static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency,
  144. LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct);
  145. static ErrorStatus UTILS_SetFlashLatency(uint32_t HCLK_Frequency);
  146. static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
  147. static ErrorStatus UTILS_PLL_IsBusy(void);
  148. /**
  149. * @}
  150. */
  151. /* Exported functions --------------------------------------------------------*/
  152. /** @addtogroup UTILS_LL_Exported_Functions
  153. * @{
  154. */
  155. /** @addtogroup UTILS_LL_EF_DELAY
  156. * @{
  157. */
  158. /**
  159. * @brief This function configures the Cortex-M SysTick source to have 1ms time base.
  160. * @note When a RTOS is used, it is recommended to avoid changing the Systick
  161. * configuration by calling this function, for a delay use rather osDelay RTOS service.
  162. * @param HCLKFrequency HCLK frequency in Hz
  163. * @note HCLK frequency can be calculated thanks to RCC helper macro or function @ref LL_RCC_GetSystemClocksFreq
  164. * @retval None
  165. */
  166. void LL_Init1msTick(uint32_t HCLKFrequency)
  167. {
  168. /* Use frequency provided in argument */
  169. LL_InitTick(HCLKFrequency, 1000U);
  170. }
  171. /**
  172. * @brief This function provides accurate delay (in milliseconds) based
  173. * on SysTick counter flag
  174. * @note When a RTOS is used, it is recommended to avoid using blocking delay
  175. * and use rather osDelay service.
  176. * @note To respect 1ms timebase, user should call @ref LL_Init1msTick function which
  177. * will configure Systick to 1ms
  178. * @param Delay specifies the delay time length, in milliseconds.
  179. * @retval None
  180. */
  181. void LL_mDelay(uint32_t Delay)
  182. {
  183. __IO uint32_t tmp = SysTick->CTRL; /* Clear the COUNTFLAG first */
  184. /* Add this code to indicate that local variable is not used */
  185. ((void)tmp);
  186. /* Add a period to guaranty minimum wait */
  187. if(Delay < LL_MAX_DELAY)
  188. {
  189. Delay++;
  190. }
  191. while (Delay)
  192. {
  193. if((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) != 0U)
  194. {
  195. Delay--;
  196. }
  197. }
  198. }
  199. /**
  200. * @}
  201. */
  202. /** @addtogroup UTILS_EF_SYSTEM
  203. * @brief System Configuration functions
  204. *
  205. @verbatim
  206. ===============================================================================
  207. ##### System Configuration functions #####
  208. ===============================================================================
  209. [..]
  210. System, AHB and APB buses clocks configuration
  211. (+) The maximum frequency of the SYSCLK, HCLK, PCLK1 and PCLK2 is
  212. 120000000 Hz for STM32L4Rx/STM32L4Sx devices and 80000000 Hz for others.
  213. @endverbatim
  214. @internal
  215. Depending on the device voltage range, the maximum frequency should be
  216. adapted accordingly:
  217. (++) Table 1. HCLK clock frequency for STM32L4Rx/STM32L4Sx devices
  218. (++) +--------------------------------------------------------+
  219. (++) | Latency | HCLK clock frequency (MHz) |
  220. (++) | |--------------------------------------|
  221. (++) | | voltage range 1 | voltage range 2 |
  222. (++) | | 1.2 V | 1.0 V |
  223. (++) |-----------------|-------------------|------------------|
  224. (++) |0WS(1 CPU cycles)| 0 < HCLK <= 20 | 0 < HCLK <= 8 |
  225. (++) |-----------------|-------------------|------------------|
  226. (++) |1WS(2 CPU cycles)| 20 < HCLK <= 40 | 8 < HCLK <= 16 |
  227. (++) |-----------------|-------------------|------------------|
  228. (++) |2WS(3 CPU cycles)| 40 < HCLK <= 60 | 16 < HCLK <= 26 |
  229. (++) |-----------------|-------------------|------------------|
  230. (++) |3WS(4 CPU cycles)| 60 < HCLK <= 80 | 16 < HCLK <= 26 |
  231. (++) |-----------------|-------------------|------------------|
  232. (++) |4WS(5 CPU cycles)| 80 < HCLK <= 100 | 16 < HCLK <= 26 |
  233. (++) |-----------------|-------------------|------------------|
  234. (++) |5WS(6 CPU cycles)| 100 < HCLK <= 120 | 16 < HCLK <= 26 |
  235. (++) +--------------------------------------------------------+
  236. (++) Table 2. HCLK clock frequency for other STM32L4 devices
  237. (++) +-------------------------------------------------------+
  238. (++) | Latency | HCLK clock frequency (MHz) |
  239. (++) | |-------------------------------------|
  240. (++) | | voltage range 1 | voltage range 2 |
  241. (++) | | 1.2 V | 1.0 V |
  242. (++) |-----------------|------------------|------------------|
  243. (++) |0WS(1 CPU cycles)| 0 < HCLK <= 16 | 0 < HCLK <= 6 |
  244. (++) |-----------------|------------------|------------------|
  245. (++) |1WS(2 CPU cycles)| 16 < HCLK <= 32 | 6 < HCLK <= 12 |
  246. (++) |-----------------|------------------|------------------|
  247. (++) |2WS(3 CPU cycles)| 32 < HCLK <= 48 | 12 < HCLK <= 18 |
  248. (++) |-----------------|------------------|------------------|
  249. (++) |3WS(4 CPU cycles)| 48 < HCLK <= 64 | 18 < HCLK <= 26 |
  250. (++) |-----------------|------------------|------------------|
  251. (++) |4WS(5 CPU cycles)| 64 < HCLK <= 80 | 18 < HCLK <= 26 |
  252. (++) +-------------------------------------------------------+
  253. @endinternal
  254. * @{
  255. */
  256. /**
  257. * @brief This function sets directly SystemCoreClock CMSIS variable.
  258. * @note Variable can be calculated also through SystemCoreClockUpdate function.
  259. * @param HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
  260. * @retval None
  261. */
  262. void LL_SetSystemCoreClock(uint32_t HCLKFrequency)
  263. {
  264. /* HCLK clock frequency */
  265. SystemCoreClock = HCLKFrequency;
  266. }
  267. /**
  268. * @brief This function configures system clock with MSI as clock source of the PLL
  269. * @note The application needs to ensure that PLL, PLLSAI1 and/or PLLSAI2 are disabled.
  270. * @note Function is based on the following formula:
  271. * - PLL output frequency = (((MSI frequency / PLLM) * PLLN) / PLLR)
  272. * - PLLM: ensure that the VCO input frequency ranges from 4 to 16 MHz (PLLVCO_input = MSI frequency / PLLM)
  273. * - PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
  274. * - PLLR: ensure that max frequency at 120000000 Hz is reached (PLLVCO_output / PLLR)
  275. * @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains
  276. * the configuration information for the PLL.
  277. * @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains
  278. * the configuration information for the BUS prescalers.
  279. * @retval An ErrorStatus enumeration value:
  280. * - SUCCESS: Max frequency configuration done
  281. * - ERROR: Max frequency configuration not done
  282. */
  283. ErrorStatus LL_PLL_ConfigSystemClock_MSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
  284. LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
  285. {
  286. ErrorStatus status = SUCCESS;
  287. uint32_t pllfreq = 0U, msi_range = 0U;
  288. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  289. uint32_t hpre = 0U;
  290. #endif
  291. /* Check if one of the PLL is enabled */
  292. if(UTILS_PLL_IsBusy() == SUCCESS)
  293. {
  294. /* Get the current MSI range */
  295. if(LL_RCC_MSI_IsEnabledRangeSelect())
  296. {
  297. msi_range = LL_RCC_MSI_GetRange();
  298. switch (msi_range)
  299. {
  300. case LL_RCC_MSIRANGE_0: /* MSI = 100 KHz */
  301. case LL_RCC_MSIRANGE_1: /* MSI = 200 KHz */
  302. case LL_RCC_MSIRANGE_2: /* MSI = 400 KHz */
  303. case LL_RCC_MSIRANGE_3: /* MSI = 800 KHz */
  304. case LL_RCC_MSIRANGE_4: /* MSI = 1 MHz */
  305. case LL_RCC_MSIRANGE_5: /* MSI = 2 MHz */
  306. /* PLLVCO input frequency is not in the range from 4 to 16 MHz*/
  307. status = ERROR;
  308. break;
  309. case LL_RCC_MSIRANGE_6: /* MSI = 4 MHz */
  310. case LL_RCC_MSIRANGE_7: /* MSI = 8 MHz */
  311. case LL_RCC_MSIRANGE_8: /* MSI = 16 MHz */
  312. case LL_RCC_MSIRANGE_9: /* MSI = 24 MHz */
  313. case LL_RCC_MSIRANGE_10: /* MSI = 32 MHz */
  314. case LL_RCC_MSIRANGE_11: /* MSI = 48 MHz */
  315. default:
  316. break;
  317. }
  318. }
  319. else
  320. {
  321. msi_range = LL_RCC_MSI_GetRangeAfterStandby();
  322. switch (msi_range)
  323. {
  324. case LL_RCC_MSISRANGE_4: /* MSI = 1 MHz */
  325. case LL_RCC_MSISRANGE_5: /* MSI = 2 MHz */
  326. /* PLLVCO input frequency is not in the range from 4 to 16 MHz*/
  327. status = ERROR;
  328. break;
  329. case LL_RCC_MSISRANGE_7: /* MSI = 8 MHz */
  330. case LL_RCC_MSISRANGE_6: /* MSI = 4 MHz */
  331. default:
  332. break;
  333. }
  334. }
  335. /* Main PLL configuration and activation */
  336. if(status != ERROR)
  337. {
  338. /* Calculate the new PLL output frequency */
  339. pllfreq = UTILS_GetPLLOutputFrequency(__LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), msi_range),
  340. UTILS_PLLInitStruct);
  341. /* Enable MSI if not enabled */
  342. if(LL_RCC_MSI_IsReady() != 1U)
  343. {
  344. LL_RCC_MSI_Enable();
  345. while ((LL_RCC_MSI_IsReady() != 1U))
  346. {
  347. /* Wait for MSI ready */
  348. }
  349. }
  350. /* Configure PLL */
  351. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_MSI, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
  352. UTILS_PLLInitStruct->PLLR);
  353. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  354. /* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
  355. if(pllfreq > 80000000U)
  356. {
  357. hpre = UTILS_ClkInitStruct->AHBCLKDivider;
  358. if(hpre == LL_RCC_SYSCLK_DIV_1)
  359. {
  360. UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
  361. }
  362. }
  363. #endif
  364. /* Enable PLL and switch system clock to PLL */
  365. status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
  366. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  367. /* Apply definitive AHB prescaler value if necessary */
  368. if((status == SUCCESS) && (hpre != 0U))
  369. {
  370. UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
  371. LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
  372. }
  373. #endif
  374. }
  375. }
  376. else
  377. {
  378. /* Current PLL configuration cannot be modified */
  379. status = ERROR;
  380. }
  381. return status;
  382. }
  383. /**
  384. * @brief This function configures system clock at maximum frequency with HSI as clock source of the PLL
  385. * @note The application need to ensure that PLL, PLLSAI1 and/or PLLSAI2 are disabled.
  386. * @note Function is based on the following formula:
  387. * - PLL output frequency = (((HSI frequency / PLLM) * PLLN) / PLLR)
  388. * - PLLM: ensure that the VCO input frequency ranges from 4 to 16 MHz (PLLVCO_input = HSI frequency / PLLM)
  389. * - PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
  390. * - PLLR: ensure that max frequency at 120000000 Hz is reach (PLLVCO_output / PLLR)
  391. * @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains
  392. * the configuration information for the PLL.
  393. * @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains
  394. * the configuration information for the BUS prescalers.
  395. * @retval An ErrorStatus enumeration value:
  396. * - SUCCESS: Max frequency configuration done
  397. * - ERROR: Max frequency configuration not done
  398. */
  399. ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
  400. LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
  401. {
  402. ErrorStatus status = SUCCESS;
  403. uint32_t pllfreq = 0U;
  404. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  405. uint32_t hpre = 0U;
  406. #endif
  407. /* Check if one of the PLL is enabled */
  408. if(UTILS_PLL_IsBusy() == SUCCESS)
  409. {
  410. /* Calculate the new PLL output frequency */
  411. pllfreq = UTILS_GetPLLOutputFrequency(HSI_VALUE, UTILS_PLLInitStruct);
  412. /* Enable HSI if not enabled */
  413. if(LL_RCC_HSI_IsReady() != 1U)
  414. {
  415. LL_RCC_HSI_Enable();
  416. while (LL_RCC_HSI_IsReady() != 1U)
  417. {
  418. /* Wait for HSI ready */
  419. }
  420. }
  421. /* Configure PLL */
  422. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
  423. UTILS_PLLInitStruct->PLLR);
  424. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  425. /* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
  426. if(pllfreq > 80000000U)
  427. {
  428. hpre = UTILS_ClkInitStruct->AHBCLKDivider;
  429. if(hpre == LL_RCC_SYSCLK_DIV_1)
  430. {
  431. UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
  432. }
  433. }
  434. #endif
  435. /* Enable PLL and switch system clock to PLL */
  436. status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
  437. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  438. /* Apply definitive AHB prescaler value if necessary */
  439. if((status == SUCCESS) && (hpre != 0U))
  440. {
  441. UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
  442. LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
  443. }
  444. #endif
  445. }
  446. else
  447. {
  448. /* Current PLL configuration cannot be modified */
  449. status = ERROR;
  450. }
  451. return status;
  452. }
  453. /**
  454. * @brief This function configures system clock with HSE as clock source of the PLL
  455. * @note The application need to ensure that PLL, PLLSAI1 and/or PLLSAI2 are disabled.
  456. * @note Function is based on the following formula:
  457. * - PLL output frequency = (((HSE frequency / PLLM) * PLLN) / PLLR)
  458. * - PLLM: ensure that the VCO input frequency ranges from 4 to 16 MHz (PLLVCO_input = HSE frequency / PLLM)
  459. * - PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
  460. * - PLLR: ensure that max frequency at 120000000 Hz is reached (PLLVCO_output / PLLR)
  461. * @param HSEFrequency Value between Min_Data = 4000000 and Max_Data = 48000000
  462. * @param HSEBypass This parameter can be one of the following values:
  463. * @arg @ref LL_UTILS_HSEBYPASS_ON
  464. * @arg @ref LL_UTILS_HSEBYPASS_OFF
  465. * @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains
  466. * the configuration information for the PLL.
  467. * @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains
  468. * the configuration information for the BUS prescalers.
  469. * @retval An ErrorStatus enumeration value:
  470. * - SUCCESS: Max frequency configuration done
  471. * - ERROR: Max frequency configuration not done
  472. */
  473. ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency, uint32_t HSEBypass,
  474. LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
  475. {
  476. ErrorStatus status = SUCCESS;
  477. uint32_t pllfreq = 0U;
  478. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  479. uint32_t hpre = 0U;
  480. #endif
  481. /* Check the parameters */
  482. assert_param(IS_LL_UTILS_HSE_FREQUENCY(HSEFrequency));
  483. assert_param(IS_LL_UTILS_HSE_BYPASS(HSEBypass));
  484. /* Check if one of the PLL is enabled */
  485. if(UTILS_PLL_IsBusy() == SUCCESS)
  486. {
  487. /* Calculate the new PLL output frequency */
  488. pllfreq = UTILS_GetPLLOutputFrequency(HSEFrequency, UTILS_PLLInitStruct);
  489. /* Enable HSE if not enabled */
  490. if(LL_RCC_HSE_IsReady() != 1U)
  491. {
  492. /* Check if need to enable HSE bypass feature or not */
  493. if(HSEBypass == LL_UTILS_HSEBYPASS_ON)
  494. {
  495. LL_RCC_HSE_EnableBypass();
  496. }
  497. else
  498. {
  499. LL_RCC_HSE_DisableBypass();
  500. }
  501. /* Enable HSE */
  502. LL_RCC_HSE_Enable();
  503. while (LL_RCC_HSE_IsReady() != 1U)
  504. {
  505. /* Wait for HSE ready */
  506. }
  507. }
  508. /* Configure PLL */
  509. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
  510. UTILS_PLLInitStruct->PLLR);
  511. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  512. /* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
  513. if(pllfreq > 80000000U)
  514. {
  515. hpre = UTILS_ClkInitStruct->AHBCLKDivider;
  516. if(hpre == LL_RCC_SYSCLK_DIV_1)
  517. {
  518. UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
  519. }
  520. }
  521. #endif
  522. /* Enable PLL and switch system clock to PLL */
  523. status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
  524. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  525. /* Apply definitive AHB prescaler value if necessary */
  526. if((status == SUCCESS) && (hpre != 0U))
  527. {
  528. UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
  529. LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
  530. }
  531. #endif
  532. }
  533. else
  534. {
  535. /* Current PLL configuration cannot be modified */
  536. status = ERROR;
  537. }
  538. return status;
  539. }
  540. /**
  541. * @}
  542. */
  543. /**
  544. * @}
  545. */
  546. /** @addtogroup UTILS_LL_Private_Functions
  547. * @{
  548. */
  549. /**
  550. * @brief Update number of Flash wait states in line with new frequency and current
  551. voltage range.
  552. * @param HCLK_Frequency HCLK frequency
  553. * @retval An ErrorStatus enumeration value:
  554. * - SUCCESS: Latency has been modified
  555. * - ERROR: Latency cannot be modified
  556. */
  557. static ErrorStatus UTILS_SetFlashLatency(uint32_t HCLK_Frequency)
  558. {
  559. ErrorStatus status = SUCCESS;
  560. uint32_t latency = LL_FLASH_LATENCY_0; /* default value 0WS */
  561. /* Frequency cannot be equal to 0 */
  562. if(HCLK_Frequency == 0U)
  563. {
  564. status = ERROR;
  565. }
  566. else
  567. {
  568. if(LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1)
  569. {
  570. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  571. if(HCLK_Frequency > UTILS_SCALE1_LATENCY5_FREQ)
  572. {
  573. /* 100 < HCLK <= 120 => 5WS (6 CPU cycles) */
  574. latency = LL_FLASH_LATENCY_5;
  575. }
  576. else if(HCLK_Frequency > UTILS_SCALE1_LATENCY4_FREQ)
  577. {
  578. /* 80 < HCLK <= 100 => 4WS (5 CPU cycles) */
  579. latency = LL_FLASH_LATENCY_4;
  580. }
  581. else if(HCLK_Frequency > UTILS_SCALE1_LATENCY3_FREQ)
  582. {
  583. /* 60 < HCLK <= 80 => 3WS (4 CPU cycles) */
  584. latency = LL_FLASH_LATENCY_3;
  585. }
  586. else if(HCLK_Frequency > UTILS_SCALE1_LATENCY2_FREQ)
  587. {
  588. /* 40 < HCLK <= 20 => 2WS (3 CPU cycles) */
  589. latency = LL_FLASH_LATENCY_2;
  590. }
  591. else
  592. {
  593. if(HCLK_Frequency > UTILS_SCALE1_LATENCY1_FREQ)
  594. {
  595. /* 20 < HCLK <= 40 => 1WS (2 CPU cycles) */
  596. latency = LL_FLASH_LATENCY_1;
  597. }
  598. /* else HCLK_Frequency <= 10MHz default LL_FLASH_LATENCY_0 0WS */
  599. }
  600. #else
  601. if(HCLK_Frequency > UTILS_SCALE1_LATENCY4_FREQ)
  602. {
  603. /* 64 < HCLK <= 80 => 4WS (5 CPU cycles) */
  604. latency = LL_FLASH_LATENCY_4;
  605. }
  606. else if(HCLK_Frequency > UTILS_SCALE1_LATENCY3_FREQ)
  607. {
  608. /* 48 < HCLK <= 64 => 3WS (4 CPU cycles) */
  609. latency = LL_FLASH_LATENCY_3;
  610. }
  611. else if(HCLK_Frequency > UTILS_SCALE1_LATENCY2_FREQ)
  612. {
  613. /* 32 < HCLK <= 48 => 2WS (3 CPU cycles) */
  614. latency = LL_FLASH_LATENCY_2;
  615. }
  616. else
  617. {
  618. if(HCLK_Frequency > UTILS_SCALE1_LATENCY1_FREQ)
  619. {
  620. /* 16 < HCLK <= 32 => 1WS (2 CPU cycles) */
  621. latency = LL_FLASH_LATENCY_1;
  622. }
  623. /* else HCLK_Frequency <= 16MHz default LL_FLASH_LATENCY_0 0WS */
  624. }
  625. #endif
  626. }
  627. else /* SCALE2 */
  628. {
  629. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  630. if(HCLK_Frequency > UTILS_SCALE2_LATENCY2_FREQ)
  631. {
  632. /* 16 < HCLK <= 26 => 2WS (3 CPU cycles) */
  633. latency = LL_FLASH_LATENCY_2;
  634. }
  635. else
  636. {
  637. if(HCLK_Frequency > UTILS_SCALE2_LATENCY1_FREQ)
  638. {
  639. /* 8 < HCLK <= 16 => 1WS (2 CPU cycles) */
  640. latency = LL_FLASH_LATENCY_1;
  641. }
  642. /* else HCLK_Frequency <= 8MHz default LL_FLASH_LATENCY_0 0WS */
  643. }
  644. #else
  645. if(HCLK_Frequency > UTILS_SCALE2_LATENCY3_FREQ)
  646. {
  647. /* 18 < HCLK <= 26 => 3WS (4 CPU cycles) */
  648. latency = LL_FLASH_LATENCY_3;
  649. }
  650. else if(HCLK_Frequency > UTILS_SCALE2_LATENCY2_FREQ)
  651. {
  652. /* 12 < HCLK <= 18 => 2WS (3 CPU cycles) */
  653. latency = LL_FLASH_LATENCY_2;
  654. }
  655. else
  656. {
  657. if(HCLK_Frequency > UTILS_SCALE2_LATENCY1_FREQ)
  658. {
  659. /* 6 < HCLK <= 12 => 1WS (2 CPU cycles) */
  660. latency = LL_FLASH_LATENCY_1;
  661. }
  662. /* else HCLK_Frequency <= 6MHz default LL_FLASH_LATENCY_0 0WS */
  663. }
  664. #endif
  665. }
  666. LL_FLASH_SetLatency(latency);
  667. /* Check that the new number of wait states is taken into account to access the Flash
  668. memory by reading the FLASH_ACR register */
  669. if(LL_FLASH_GetLatency() != latency)
  670. {
  671. status = ERROR;
  672. }
  673. }
  674. return status;
  675. }
  676. /**
  677. * @brief Function to check that PLL can be modified
  678. * @param PLL_InputFrequency PLL input frequency (in Hz)
  679. * @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains
  680. * the configuration information for the PLL.
  681. * @retval PLL output frequency (in Hz)
  682. */
  683. static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct)
  684. {
  685. uint32_t pllfreq = 0U;
  686. /* Check the parameters */
  687. assert_param(IS_LL_UTILS_PLLM_VALUE(UTILS_PLLInitStruct->PLLM));
  688. assert_param(IS_LL_UTILS_PLLN_VALUE(UTILS_PLLInitStruct->PLLN));
  689. assert_param(IS_LL_UTILS_PLLR_VALUE(UTILS_PLLInitStruct->PLLR));
  690. /* Check different PLL parameters according to RM */
  691. /* - PLLM: ensure that the VCO input frequency ranges from 4 to 16 MHz. */
  692. pllfreq = PLL_InputFrequency / (((UTILS_PLLInitStruct->PLLM >> RCC_PLLCFGR_PLLM_Pos) + 1));
  693. assert_param(IS_LL_UTILS_PLLVCO_INPUT(pllfreq));
  694. /* - PLLN: ensure that the VCO output frequency is between 64 and 344 MHz.*/
  695. pllfreq = pllfreq * (UTILS_PLLInitStruct->PLLN & (RCC_PLLCFGR_PLLN >> RCC_PLLCFGR_PLLN_Pos));
  696. assert_param(IS_LL_UTILS_PLLVCO_OUTPUT(pllfreq));
  697. /* - PLLR: ensure that max frequency at 120000000 Hz is reached */
  698. pllfreq = pllfreq / (((UTILS_PLLInitStruct->PLLR >> RCC_PLLCFGR_PLLR_Pos) + 1) * 2);
  699. assert_param(IS_LL_UTILS_PLL_FREQUENCY(pllfreq));
  700. return pllfreq;
  701. }
  702. /**
  703. * @brief Function to check that PLL can be modified
  704. * @retval An ErrorStatus enumeration value:
  705. * - SUCCESS: PLL modification can be done
  706. * - ERROR: PLL is busy
  707. */
  708. static ErrorStatus UTILS_PLL_IsBusy(void)
  709. {
  710. ErrorStatus status = SUCCESS;
  711. /* Check if PLL is busy*/
  712. if(LL_RCC_PLL_IsReady() != 0U)
  713. {
  714. /* PLL configuration cannot be modified */
  715. status = ERROR;
  716. }
  717. /* Check if PLLSAI1 is busy*/
  718. if(LL_RCC_PLLSAI1_IsReady() != 0U)
  719. {
  720. /* PLLSAI1 configuration cannot be modified */
  721. status = ERROR;
  722. }
  723. #if defined(RCC_PLLSAI2_SUPPORT)
  724. /* Check if PLLSAI2 is busy*/
  725. if(LL_RCC_PLLSAI2_IsReady() != 0U)
  726. {
  727. /* PLLSAI2 configuration cannot be modified */
  728. status = ERROR;
  729. }
  730. #endif /*RCC_PLLSAI2_SUPPORT*/
  731. return status;
  732. }
  733. /**
  734. * @brief Function to enable PLL and switch system clock to PLL
  735. * @param SYSCLK_Frequency SYSCLK frequency
  736. * @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains
  737. * the configuration information for the BUS prescalers.
  738. * @retval An ErrorStatus enumeration value:
  739. * - SUCCESS: No problem to switch system to PLL
  740. * - ERROR: Problem to switch system to PLL
  741. */
  742. static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
  743. {
  744. ErrorStatus status = SUCCESS;
  745. uint32_t hclk_frequency = 0U;
  746. assert_param(IS_LL_UTILS_SYSCLK_DIV(UTILS_ClkInitStruct->AHBCLKDivider));
  747. assert_param(IS_LL_UTILS_APB1_DIV(UTILS_ClkInitStruct->APB1CLKDivider));
  748. assert_param(IS_LL_UTILS_APB2_DIV(UTILS_ClkInitStruct->APB2CLKDivider));
  749. /* Calculate HCLK frequency */
  750. hclk_frequency = __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, UTILS_ClkInitStruct->AHBCLKDivider);
  751. /* Increasing the number of wait states because of higher CPU frequency */
  752. if(SystemCoreClock < hclk_frequency)
  753. {
  754. /* Set FLASH latency to highest latency */
  755. status = UTILS_SetFlashLatency(hclk_frequency);
  756. }
  757. /* Update system clock configuration */
  758. if(status == SUCCESS)
  759. {
  760. /* Enable PLL */
  761. LL_RCC_PLL_Enable();
  762. LL_RCC_PLL_EnableDomain_SYS();
  763. while (LL_RCC_PLL_IsReady() != 1U)
  764. {
  765. /* Wait for PLL ready */
  766. }
  767. /* Sysclk activation on the main PLL */
  768. LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
  769. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  770. while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  771. {
  772. /* Wait for system clock switch to PLL */
  773. }
  774. /* Set APB1 & APB2 prescaler*/
  775. LL_RCC_SetAPB1Prescaler(UTILS_ClkInitStruct->APB1CLKDivider);
  776. LL_RCC_SetAPB2Prescaler(UTILS_ClkInitStruct->APB2CLKDivider);
  777. }
  778. /* Decreasing the number of wait states because of lower CPU frequency */
  779. if(SystemCoreClock > hclk_frequency)
  780. {
  781. /* Set FLASH latency to lowest latency */
  782. status = UTILS_SetFlashLatency(hclk_frequency);
  783. }
  784. /* Update SystemCoreClock variable */
  785. if(status == SUCCESS)
  786. {
  787. LL_SetSystemCoreClock(hclk_frequency);
  788. }
  789. return status;
  790. }
  791. /**
  792. * @}
  793. */
  794. /**
  795. * @}
  796. */
  797. /**
  798. * @}
  799. */
  800. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/