DIY Logging Volt/Ampmeter
UTILS Private functions

Functions

static uint32_t UTILS_GetPLLOutputFrequency (uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct)
 Function to check that PLL can be modified. More...
 
static ErrorStatus UTILS_EnablePLLAndSwitchSystem (uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
 Function to enable PLL and switch system clock to PLL. More...
 
static ErrorStatus UTILS_PLL_IsBusy (void)
 Function to check that PLL can be modified. More...
 

Detailed Description

Function Documentation

◆ UTILS_EnablePLLAndSwitchSystem()

static ErrorStatus UTILS_EnablePLLAndSwitchSystem ( uint32_t  SYSCLK_Frequency,
LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct 
)
static

Function to enable PLL and switch system clock to PLL.

Parameters
SYSCLK_FrequencySYSCLK frequency
UTILS_ClkInitStructpointer to a LL_UTILS_ClkInitTypeDef structure that contains the configuration information for the BUS prescalers.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: No problem to switch system to PLL
  • ERROR: Problem to switch system to PLL

Definition at line 535 of file stm32f1xx_ll_utils.c.

536 {
537  ErrorStatus status = SUCCESS;
538 #if defined(FLASH_ACR_LATENCY)
539  uint32_t sysclk_frequency_current = 0U;
540 #endif /* FLASH_ACR_LATENCY */
541 
542  assert_param(IS_LL_UTILS_SYSCLK_DIV(UTILS_ClkInitStruct->AHBCLKDivider));
543  assert_param(IS_LL_UTILS_APB1_DIV(UTILS_ClkInitStruct->APB1CLKDivider));
544  assert_param(IS_LL_UTILS_APB2_DIV(UTILS_ClkInitStruct->APB2CLKDivider));
545 
546 #if defined(FLASH_ACR_LATENCY)
547  /* Calculate current SYSCLK frequency */
548  sysclk_frequency_current = (SystemCoreClock << AHBPrescTable[LL_RCC_GetAHBPrescaler() >> RCC_CFGR_HPRE_Pos]);
549 #endif /* FLASH_ACR_LATENCY */
550 
551  /* Increasing the number of wait states because of higher CPU frequency */
552 #if defined (FLASH_ACR_LATENCY)
553  if (sysclk_frequency_current < SYSCLK_Frequency)
554  {
555  /* Set FLASH latency to highest latency */
556  status = LL_SetFlashLatency(SYSCLK_Frequency);
557  }
558 #endif /* FLASH_ACR_LATENCY */
559 
560  /* Update system clock configuration */
561  if (status == SUCCESS)
562  {
563 #if defined(RCC_PLL2_SUPPORT)
564  if (LL_RCC_PLL_GetMainSource() != LL_RCC_PLLSOURCE_HSI_DIV_2)
565  {
566  /* Enable PLL2 */
567  LL_RCC_PLL2_Enable();
568  while (LL_RCC_PLL2_IsReady() != 1U)
569  {
570  /* Wait for PLL2 ready */
571  }
572  }
573 #endif /* RCC_PLL2_SUPPORT */
574  /* Enable PLL */
575  LL_RCC_PLL_Enable();
576  while (LL_RCC_PLL_IsReady() != 1U)
577  {
578  /* Wait for PLL ready */
579  }
580 
581  /* Sysclk activation on the main PLL */
582  LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
583  LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
584  while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
585  {
586  /* Wait for system clock switch to PLL */
587  }
588 
589  /* Set APB1 & APB2 prescaler*/
590  LL_RCC_SetAPB1Prescaler(UTILS_ClkInitStruct->APB1CLKDivider);
591  LL_RCC_SetAPB2Prescaler(UTILS_ClkInitStruct->APB2CLKDivider);
592  }
593 
594  /* Decreasing the number of wait states because of lower CPU frequency */
595 #if defined (FLASH_ACR_LATENCY)
596  if (sysclk_frequency_current > SYSCLK_Frequency)
597  {
598  /* Set FLASH latency to lowest latency */
599  status = LL_SetFlashLatency(SYSCLK_Frequency);
600  }
601 #endif /* FLASH_ACR_LATENCY */
602 
603  /* Update SystemCoreClock variable */
604  if (status == SUCCESS)
605  {
606  LL_SetSystemCoreClock(__LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, UTILS_ClkInitStruct->AHBCLKDivider));
607  }
608 
609  return status;
610 }

◆ UTILS_GetPLLOutputFrequency()

static uint32_t UTILS_GetPLLOutputFrequency ( uint32_t  PLL_InputFrequency,
LL_UTILS_PLLInitTypeDef UTILS_PLLInitStruct 
)
static

Function to check that PLL can be modified.

Parameters
PLL_InputFrequencyPLL input frequency (in Hz)
UTILS_PLLInitStructpointer to a LL_UTILS_PLLInitTypeDef structure that contains the configuration information for the PLL.
Return values
PLLoutput frequency (in Hz)

Definition at line 471 of file stm32f1xx_ll_utils.c.

472 {
473  uint32_t pllfreq = 0U;
474 
475  /* Check the parameters */
476  assert_param(IS_LL_UTILS_PLLMUL_VALUE(UTILS_PLLInitStruct->PLLMul));
477 
478  /* Check different PLL parameters according to RM */
479 #if defined (RCC_CFGR2_PREDIV1)
480  pllfreq = __LL_RCC_CALC_PLLCLK_FREQ(PLL_InputFrequency / (UTILS_PLLInitStruct->Prediv + 1U), UTILS_PLLInitStruct->PLLMul);
481 #else
482  pllfreq = __LL_RCC_CALC_PLLCLK_FREQ(PLL_InputFrequency / ((UTILS_PLLInitStruct->Prediv >> RCC_CFGR_PLLXTPRE_Pos) + 1U), UTILS_PLLInitStruct->PLLMul);
483 #endif /*RCC_CFGR2_PREDIV1SRC*/
485 
486  return pllfreq;
487 }

◆ UTILS_PLL_IsBusy()

static ErrorStatus UTILS_PLL_IsBusy ( void  )
static

Function to check that PLL can be modified.

Return values
AnErrorStatus enumeration value:
  • SUCCESS: PLL modification can be done
  • ERROR: PLL is busy

Definition at line 495 of file stm32f1xx_ll_utils.c.

496 {
497  ErrorStatus status = SUCCESS;
498 
499  /* Check if PLL is busy*/
500  if (LL_RCC_PLL_IsReady() != 0U)
501  {
502  /* PLL configuration cannot be modified */
503  status = ERROR;
504  }
505 #if defined(RCC_PLL2_SUPPORT)
506  /* Check if PLL2 is busy*/
507  if (LL_RCC_PLL2_IsReady() != 0U)
508  {
509  /* PLL2 configuration cannot be modified */
510  status = ERROR;
511  }
512 #endif /* RCC_PLL2_SUPPORT */
513 
514 #if defined(RCC_PLLI2S_SUPPORT)
515  /* Check if PLLI2S is busy*/
516  if (LL_RCC_PLLI2S_IsReady() != 0U)
517  {
518  /* PLLI2S configuration cannot be modified */
519  status = ERROR;
520  }
521 #endif /* RCC_PLLI2S_SUPPORT */
522 
523  return status;
524 }
ERROR
@ ERROR
Definition: stm32f1xx.h:167
LL_SetSystemCoreClock
void LL_SetSystemCoreClock(uint32_t HCLKFrequency)
This function sets directly SystemCoreClock CMSIS variable.
Definition: stm32f1xx_ll_utils.c:240
LL_UTILS_ClkInitTypeDef::APB2CLKDivider
uint32_t APB2CLKDivider
Definition: stm32f1xx_ll_utils.h:122
AHBPrescTable
const uint8_t AHBPrescTable[16U]
Definition: system_stm32f1xx.c:143
IS_LL_UTILS_PLL_FREQUENCY
#define IS_LL_UTILS_PLL_FREQUENCY(__VALUE__)
Definition: stm32f1xx_ll_utils.c:127
IS_LL_UTILS_PLLMUL_VALUE
#define IS_LL_UTILS_PLLMUL_VALUE(__VALUE__)
Definition: stm32f1xx_ll_utils.c:97
LL_UTILS_PLLInitTypeDef::Prediv
uint32_t Prediv
Definition: stm32f1xx_ll_utils.h:98
IS_LL_UTILS_APB2_DIV
#define IS_LL_UTILS_APB2_DIV(__VALUE__)
Definition: stm32f1xx_ll_utils.c:82
assert_param
#define assert_param(expr)
Definition: stm32f1xx_ll_utils.c:27
IS_LL_UTILS_SYSCLK_DIV
#define IS_LL_UTILS_SYSCLK_DIV(__VALUE__)
Definition: stm32f1xx_ll_utils.c:66
RCC_CFGR_HPRE_Pos
#define RCC_CFGR_HPRE_Pos
Definition: stm32f103xb.h:957
IS_LL_UTILS_APB1_DIV
#define IS_LL_UTILS_APB1_DIV(__VALUE__)
Definition: stm32f1xx_ll_utils.c:76
LL_UTILS_ClkInitTypeDef::APB1CLKDivider
uint32_t APB1CLKDivider
Definition: stm32f1xx_ll_utils.h:116
RCC_CFGR_PLLXTPRE_Pos
#define RCC_CFGR_PLLXTPRE_Pos
Definition: stm32f103xb.h:1019
LL_UTILS_ClkInitTypeDef::AHBCLKDivider
uint32_t AHBCLKDivider
Definition: stm32f1xx_ll_utils.h:110
LL_UTILS_PLLInitTypeDef::PLLMul
uint32_t PLLMul
Definition: stm32f1xx_ll_utils.h:92
SystemCoreClock
uint32_t SystemCoreClock
Definition: system_stm32f1xx.c:142
SUCCESS
@ SUCCESS
Definition: stm32f1xx.h:166
ErrorStatus
ErrorStatus
Definition: stm32f1xx.h:164