stm32l4xx_ll_utils.c 36 KB

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