STM32L4xx_HAL_Driver  1.14.0

System Configuration functions. More...

Functions

void LL_SetSystemCoreClock (uint32_t HCLKFrequency)
 This function sets directly SystemCoreClock CMSIS variable. More...
 
ErrorStatus LL_PLL_ConfigSystemClock_MSI (LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
 This function configures system clock with MSI as clock source of the PLL. More...
 
ErrorStatus LL_PLL_ConfigSystemClock_HSI (LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
 This function configures system clock at maximum frequency with HSI as clock source of the PLL. More...
 
ErrorStatus LL_PLL_ConfigSystemClock_HSE (uint32_t HSEFrequency, uint32_t HSEBypass, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
 This function configures system clock with HSE as clock source of the PLL. More...
 

Detailed Description

System Configuration functions.

===============================================================================
          ##### System Configuration functions #####
===============================================================================
   [..]
        System, AHB and APB buses clocks configuration

        (+) The maximum frequency of the SYSCLK, HCLK, PCLK1 and PCLK2 is
            120000000 Hz for STM32L4Rx/STM32L4Sx devices and 80000000 Hz for others.

Function Documentation

◆ LL_PLL_ConfigSystemClock_HSE()

ErrorStatus LL_PLL_ConfigSystemClock_HSE ( uint32_t  HSEFrequency,
uint32_t  HSEBypass,
LL_UTILS_PLLInitTypeDef UTILS_PLLInitStruct,
LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct 
)

This function configures system clock with HSE as clock source of the PLL.

Note
The application need to ensure that PLL, PLLSAI1 and/or PLLSAI2 are disabled.
Function is based on the following formula:
  • PLL output frequency = (((HSE frequency / PLLM) * PLLN) / PLLR)
  • PLLM: ensure that the VCO input frequency ranges from 4 to 16 MHz (PLLVCO_input = HSE frequency / PLLM)
  • PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
  • PLLR: ensure that max frequency at 120000000 Hz is reached (PLLVCO_output / PLLR)
Parameters
HSEFrequencyValue between Min_Data = 4000000 and Max_Data = 48000000
HSEBypassThis parameter can be one of the following values:
  • LL_UTILS_HSEBYPASS_ON
  • LL_UTILS_HSEBYPASS_OFF
UTILS_PLLInitStructpointer to a LL_UTILS_PLLInitTypeDef structure that contains the configuration information for the PLL.
UTILS_ClkInitStructpointer to a LL_UTILS_ClkInitTypeDef structure that contains the configuration information for the BUS prescalers.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Max frequency configuration done
  • ERROR: Max frequency configuration not done

Definition at line 507 of file stm32l4xx_ll_utils.c.

509 {
510  ErrorStatus status;
511  uint32_t pllfreq;
512 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
513  uint32_t hpre = 0U; /* Set default value */
514 #endif
515 
516  /* Check the parameters */
517  assert_param(IS_LL_UTILS_HSE_FREQUENCY(HSEFrequency));
518  assert_param(IS_LL_UTILS_HSE_BYPASS(HSEBypass));
519 
520  /* Check if one of the PLL is enabled */
521  if(UTILS_PLL_IsBusy() == SUCCESS)
522  {
523  /* Calculate the new PLL output frequency */
524  pllfreq = UTILS_GetPLLOutputFrequency(HSEFrequency, UTILS_PLLInitStruct);
525 
526  /* Enable HSE if not enabled */
527  if(LL_RCC_HSE_IsReady() != 1U)
528  {
529  /* Check if need to enable HSE bypass feature or not */
530  if(HSEBypass == LL_UTILS_HSEBYPASS_ON)
531  {
533  }
534  else
535  {
537  }
538 
539  /* Enable HSE */
541  while (LL_RCC_HSE_IsReady() != 1U)
542  {
543  /* Wait for HSE ready */
544  }
545  }
546 
547  /* Configure PLL */
548  LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
549  UTILS_PLLInitStruct->PLLR);
550 
551 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
552  /* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
553  if(pllfreq > 80000000U)
554  {
555  hpre = UTILS_ClkInitStruct->AHBCLKDivider;
556  if(hpre == LL_RCC_SYSCLK_DIV_1)
557  {
558  UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
559  }
560  }
561 #endif
562  /* Enable PLL and switch system clock to PLL */
563  status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
564 
565 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
566  /* Apply definitive AHB prescaler value if necessary */
567  if((status == SUCCESS) && (hpre != 0U))
568  {
569  UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
570  LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
571  }
572 #endif
573  }
574  else
575  {
576  /* Current PLL configuration cannot be modified */
577  status = ERROR;
578  }
579 
580  return status;
581 }
__STATIC_INLINE void LL_RCC_HSE_Enable(void)
Enable HSE crystal oscillator (HSE ON) CR HSEON LL_RCC_HSE_Enable.
__STATIC_INLINE void LL_RCC_SetAHBPrescaler(uint32_t Prescaler)
Set AHB prescaler CFGR HPRE LL_RCC_SetAHBPrescaler.
__STATIC_INLINE void LL_RCC_HSE_DisableBypass(void)
Disable HSE external oscillator (HSE Bypass) CR HSEBYP LL_RCC_HSE_DisableBypass. ...
__STATIC_INLINE void LL_RCC_HSE_EnableBypass(void)
Enable HSE external oscillator (HSE Bypass) CR HSEBYP LL_RCC_HSE_EnableBypass.
static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct)
Function to check that PLL can be modified.
__STATIC_INLINE void LL_RCC_PLL_ConfigDomain_SYS(uint32_t Source, uint32_t PLLM, uint32_t PLLN, uint32_t PLLR)
Configure PLL used for SYSCLK Domain.
static ErrorStatus UTILS_PLL_IsBusy(void)
Function to check that PLL can be modified.
__STATIC_INLINE uint32_t LL_RCC_HSE_IsReady(void)
Check if HSE oscillator Ready CR HSERDY LL_RCC_HSE_IsReady.
static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
Function to enable PLL and switch system clock to PLL.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ LL_PLL_ConfigSystemClock_HSI()

ErrorStatus LL_PLL_ConfigSystemClock_HSI ( LL_UTILS_PLLInitTypeDef UTILS_PLLInitStruct,
LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct 
)

This function configures system clock at maximum frequency with HSI as clock source of the PLL.

Note
The application need to ensure that PLL, PLLSAI1 and/or PLLSAI2 are disabled.
Function is based on the following formula:
  • PLL output frequency = (((HSI frequency / PLLM) * PLLN) / PLLR)
  • PLLM: ensure that the VCO input frequency ranges from 4 to 16 MHz (PLLVCO_input = HSI frequency / PLLM)
  • PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
  • PLLR: ensure that max frequency at 120000000 Hz is reach (PLLVCO_output / PLLR)
Parameters
UTILS_PLLInitStructpointer to a LL_UTILS_PLLInitTypeDef structure that contains the configuration information for the PLL.
UTILS_ClkInitStructpointer to a LL_UTILS_ClkInitTypeDef structure that contains the configuration information for the BUS prescalers.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Max frequency configuration done
  • ERROR: Max frequency configuration not done

Definition at line 426 of file stm32l4xx_ll_utils.c.

428 {
429  ErrorStatus status;
430  uint32_t pllfreq;
431 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
432  uint32_t hpre = 0U; /* Set default value */
433 #endif
434 
435  /* Check if one of the PLL is enabled */
436  if(UTILS_PLL_IsBusy() == SUCCESS)
437  {
438  /* Calculate the new PLL output frequency */
439  pllfreq = UTILS_GetPLLOutputFrequency(HSI_VALUE, UTILS_PLLInitStruct);
440 
441  /* Enable HSI if not enabled */
442  if(LL_RCC_HSI_IsReady() != 1U)
443  {
445  while (LL_RCC_HSI_IsReady() != 1U)
446  {
447  /* Wait for HSI ready */
448  }
449  }
450 
451  /* Configure PLL */
452  LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
453  UTILS_PLLInitStruct->PLLR);
454 
455 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
456  /* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
457  if(pllfreq > 80000000U)
458  {
459  hpre = UTILS_ClkInitStruct->AHBCLKDivider;
460  if(hpre == LL_RCC_SYSCLK_DIV_1)
461  {
462  UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
463  }
464  }
465 #endif
466  /* Enable PLL and switch system clock to PLL */
467  status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
468 
469 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
470  /* Apply definitive AHB prescaler value if necessary */
471  if((status == SUCCESS) && (hpre != 0U))
472  {
473  UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
474  LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
475  }
476 #endif
477  }
478  else
479  {
480  /* Current PLL configuration cannot be modified */
481  status = ERROR;
482  }
483 
484  return status;
485 }
__STATIC_INLINE uint32_t LL_RCC_HSI_IsReady(void)
Check if HSI clock is ready CR HSIRDY LL_RCC_HSI_IsReady.
__STATIC_INLINE void LL_RCC_SetAHBPrescaler(uint32_t Prescaler)
Set AHB prescaler CFGR HPRE LL_RCC_SetAHBPrescaler.
__STATIC_INLINE void LL_RCC_HSI_Enable(void)
Enable HSI oscillator CR HSION LL_RCC_HSI_Enable.
static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct)
Function to check that PLL can be modified.
__STATIC_INLINE void LL_RCC_PLL_ConfigDomain_SYS(uint32_t Source, uint32_t PLLM, uint32_t PLLN, uint32_t PLLR)
Configure PLL used for SYSCLK Domain.
static ErrorStatus UTILS_PLL_IsBusy(void)
Function to check that PLL can be modified.
static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
Function to enable PLL and switch system clock to PLL.

◆ LL_PLL_ConfigSystemClock_MSI()

ErrorStatus LL_PLL_ConfigSystemClock_MSI ( LL_UTILS_PLLInitTypeDef UTILS_PLLInitStruct,
LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct 
)

This function configures system clock with MSI as clock source of the PLL.

Note
The application needs to ensure that PLL, PLLSAI1 and/or PLLSAI2 are disabled.
Function is based on the following formula:
  • PLL output frequency = (((MSI frequency / PLLM) * PLLN) / PLLR)
  • PLLM: ensure that the VCO input frequency ranges from 4 to 16 MHz (PLLVCO_input = MSI frequency / PLLM)
  • PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
  • PLLR: ensure that max frequency at 120000000 Hz is reached (PLLVCO_output / PLLR)
Parameters
UTILS_PLLInitStructpointer to a LL_UTILS_PLLInitTypeDef structure that contains the configuration information for the PLL.
UTILS_ClkInitStructpointer to a LL_UTILS_ClkInitTypeDef structure that contains the configuration information for the BUS prescalers.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: Max frequency configuration done
  • ERROR: Max frequency configuration not done

Definition at line 300 of file stm32l4xx_ll_utils.c.

302 {
303  ErrorStatus status = SUCCESS;
304  uint32_t pllfreq, msi_range;
305 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
306  uint32_t hpre = 0U; /* Set default value */
307 #endif
308 
309  /* Check if one of the PLL is enabled */
310  if(UTILS_PLL_IsBusy() == SUCCESS)
311  {
312  /* Get the current MSI range */
314  {
315  msi_range = LL_RCC_MSI_GetRange();
316  switch (msi_range)
317  {
318  case LL_RCC_MSIRANGE_0: /* MSI = 100 KHz */
319  case LL_RCC_MSIRANGE_1: /* MSI = 200 KHz */
320  case LL_RCC_MSIRANGE_2: /* MSI = 400 KHz */
321  case LL_RCC_MSIRANGE_3: /* MSI = 800 KHz */
322  case LL_RCC_MSIRANGE_4: /* MSI = 1 MHz */
323  case LL_RCC_MSIRANGE_5: /* MSI = 2 MHz */
324  /* PLLVCO input frequency is not in the range from 4 to 16 MHz*/
325  status = ERROR;
326  break;
327 
328  case LL_RCC_MSIRANGE_6: /* MSI = 4 MHz */
329  case LL_RCC_MSIRANGE_7: /* MSI = 8 MHz */
330  case LL_RCC_MSIRANGE_8: /* MSI = 16 MHz */
331  case LL_RCC_MSIRANGE_9: /* MSI = 24 MHz */
332  case LL_RCC_MSIRANGE_10: /* MSI = 32 MHz */
333  case LL_RCC_MSIRANGE_11: /* MSI = 48 MHz */
334  default:
335  break;
336  }
337  }
338  else
339  {
340  msi_range = LL_RCC_MSI_GetRangeAfterStandby();
341  switch (msi_range)
342  {
343  case LL_RCC_MSISRANGE_4: /* MSI = 1 MHz */
344  case LL_RCC_MSISRANGE_5: /* MSI = 2 MHz */
345  /* PLLVCO input frequency is not in the range from 4 to 16 MHz*/
346  status = ERROR;
347  break;
348 
349  case LL_RCC_MSISRANGE_7: /* MSI = 8 MHz */
350  case LL_RCC_MSISRANGE_6: /* MSI = 4 MHz */
351  default:
352  break;
353  }
354  }
355 
356  /* Main PLL configuration and activation */
357  if(status != ERROR)
358  {
359  /* Calculate the new PLL output frequency */
360  pllfreq = UTILS_GetPLLOutputFrequency(__LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), msi_range),
361  UTILS_PLLInitStruct);
362 
363  /* Enable MSI if not enabled */
364  if(LL_RCC_MSI_IsReady() != 1U)
365  {
367  while ((LL_RCC_MSI_IsReady() != 1U))
368  {
369  /* Wait for MSI ready */
370  }
371  }
372 
373  /* Configure PLL */
374  LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_MSI, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
375  UTILS_PLLInitStruct->PLLR);
376 
377 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
378  /* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
379  if(pllfreq > 80000000U)
380  {
381  hpre = UTILS_ClkInitStruct->AHBCLKDivider;
382  if(hpre == LL_RCC_SYSCLK_DIV_1)
383  {
384  UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
385  }
386  }
387 #endif
388  /* Enable PLL and switch system clock to PLL */
389  status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
390 
391 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
392  /* Apply definitive AHB prescaler value if necessary */
393  if((status == SUCCESS) && (hpre != 0U))
394  {
395  UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
396  LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
397  }
398 #endif
399  }
400  }
401  else
402  {
403  /* Current PLL configuration cannot be modified */
404  status = ERROR;
405  }
406 
407  return status;
408 }
__STATIC_INLINE void LL_RCC_SetAHBPrescaler(uint32_t Prescaler)
Set AHB prescaler CFGR HPRE LL_RCC_SetAHBPrescaler.
__STATIC_INLINE uint32_t LL_RCC_MSI_GetRangeAfterStandby(void)
Get MSI range used after standby CSR MSISRANGE LL_RCC_MSI_GetRangeAfterStandby.
__STATIC_INLINE uint32_t LL_RCC_MSI_IsReady(void)
Check if MSI oscillator Ready CR MSIRDY LL_RCC_MSI_IsReady.
__STATIC_INLINE uint32_t LL_RCC_MSI_IsEnabledRangeSelect(void)
Check if MSI clock range is selected with MSIRANGE register CR MSIRGSEL LL_RCC_MSI_IsEnabledRangeSel...
__STATIC_INLINE void LL_RCC_MSI_Enable(void)
Enable MSI oscillator CR MSION LL_RCC_MSI_Enable.
static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct)
Function to check that PLL can be modified.
__STATIC_INLINE void LL_RCC_PLL_ConfigDomain_SYS(uint32_t Source, uint32_t PLLM, uint32_t PLLN, uint32_t PLLR)
Configure PLL used for SYSCLK Domain.
static ErrorStatus UTILS_PLL_IsBusy(void)
Function to check that PLL can be modified.
__STATIC_INLINE uint32_t LL_RCC_MSI_GetRange(void)
Get the Internal Multi Speed oscillator (MSI) clock range in run mode. CR MSIRANGE LL_RCC_MSI_GetRan...
static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
Function to enable PLL and switch system clock to PLL.

◆ LL_SetSystemCoreClock()

void LL_SetSystemCoreClock ( uint32_t  HCLKFrequency)

This function sets directly SystemCoreClock CMSIS variable.

Note
Variable can be calculated also through SystemCoreClockUpdate function.
Parameters
HCLKFrequencyHCLK frequency in Hz (can be calculated thanks to RCC helper macro)
Return values
None

Definition at line 278 of file stm32l4xx_ll_utils.c.

279 {
280  /* HCLK clock frequency */
281  SystemCoreClock = HCLKFrequency;
282 }