STM32L4xx_HAL_Driver  1.14.0
RCCEx Private Functions

Functions

static HAL_StatusTypeDef RCCEx_PLLSAI1_Config (RCC_PLLSAI1InitTypeDef *PllSai1, uint32_t Divider)
 Configure the parameters N & P & optionally M of PLLSAI1 and enable PLLSAI1 output clock(s). More...
 
static HAL_StatusTypeDef RCCEx_PLLSAI2_Config (RCC_PLLSAI2InitTypeDef *PllSai2, uint32_t Divider)
 Configure the parameters N & P & optionally M of PLLSAI2 and enable PLLSAI2 output clock(s). More...
 
static uint32_t RCCEx_GetSAIxPeriphCLKFreq (uint32_t PeriphClk, uint32_t InputFrequency)
 

Detailed Description

Function Documentation

◆ RCCEx_GetSAIxPeriphCLKFreq()

static uint32_t RCCEx_GetSAIxPeriphCLKFreq ( uint32_t  PeriphClk,
uint32_t  InputFrequency 
)
static

Definition at line 3290 of file stm32l4xx_hal_rcc_ex.c.

3291 {
3292  uint32_t frequency = 0U;
3293  uint32_t srcclk = 0U;
3294  uint32_t pllvco, plln; /* no init needed */
3295 #if defined(RCC_PLLP_SUPPORT)
3296  uint32_t pllp = 0U;
3297 #endif /* RCC_PLLP_SUPPORT */
3298 
3299  /* Handle SAIs */
3300  if(PeriphClk == RCC_PERIPHCLK_SAI1)
3301  {
3302  srcclk = __HAL_RCC_GET_SAI1_SOURCE();
3303  if(srcclk == RCC_SAI1CLKSOURCE_PIN)
3304  {
3305  frequency = EXTERNAL_SAI1_CLOCK_VALUE;
3306  }
3307  /* Else, PLL clock output to check below */
3308  }
3309 #if defined(SAI2)
3310  else
3311  {
3312  if(PeriphClk == RCC_PERIPHCLK_SAI2)
3313  {
3314  srcclk = __HAL_RCC_GET_SAI2_SOURCE();
3315  if(srcclk == RCC_SAI2CLKSOURCE_PIN)
3316  {
3317  frequency = EXTERNAL_SAI2_CLOCK_VALUE;
3318  }
3319  /* Else, PLL clock output to check below */
3320  }
3321  }
3322 #endif /* SAI2 */
3323 
3324  if(frequency == 0U)
3325  {
3326  pllvco = InputFrequency;
3327 
3328 #if defined(SAI2)
3329  if((srcclk == RCC_SAI1CLKSOURCE_PLL) || (srcclk == RCC_SAI2CLKSOURCE_PLL))
3330  {
3331  if(__HAL_RCC_GET_PLLCLKOUT_CONFIG(RCC_PLL_SAI3CLK) != 0U)
3332  {
3333  /* f(PLL Source) / PLLM */
3334  pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
3335  /* f(PLLSAI3CLK) = f(VCO input) * PLLN / PLLP */
3336  plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
3337 #if defined(RCC_PLLP_DIV_2_31_SUPPORT)
3338  pllp = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLPDIV) >> RCC_PLLCFGR_PLLPDIV_Pos;
3339 #endif
3340  if(pllp == 0U)
3341  {
3342  if(READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) != 0U)
3343  {
3344  pllp = 17U;
3345  }
3346  else
3347  {
3348  pllp = 7U;
3349  }
3350  }
3351  frequency = (pllvco * plln) / pllp;
3352  }
3353  }
3354  else if(srcclk == 0U) /* RCC_SAI1CLKSOURCE_PLLSAI1 || RCC_SAI2CLKSOURCE_PLLSAI1 */
3355  {
3356  if(__HAL_RCC_GET_PLLSAI1CLKOUT_CONFIG(RCC_PLLSAI1_SAI1CLK) != 0U)
3357  {
3358 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
3359  /* PLLSAI1M exists: apply PLLSAI1M divider for PLLSAI1 output computation */
3360  /* f(PLLSAI1 Source) / PLLSAI1M */
3361  pllvco = (pllvco / ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U));
3362 #else
3363  /* f(PLL Source) / PLLM */
3364  pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
3365 #endif
3366  /* f(PLLSAI1CLK) = f(VCOSAI1 input) * PLLSAI1N / PLLSAI1P */
3367  plln = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
3368 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
3369  pllp = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1PDIV) >> RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos;
3370 #endif
3371  if(pllp == 0U)
3372  {
3373  if(READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1P) != 0U)
3374  {
3375  pllp = 17U;
3376  }
3377  else
3378  {
3379  pllp = 7U;
3380  }
3381  }
3382  frequency = (pllvco * plln) / pllp;
3383  }
3384  }
3385 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
3386  else if((srcclk == RCC_SAI1CLKSOURCE_HSI) || (srcclk == RCC_SAI2CLKSOURCE_HSI))
3387  {
3388  if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
3389  {
3390  frequency = HSI_VALUE;
3391  }
3392  }
3393 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
3394 
3395 #else
3396  if(srcclk == RCC_SAI1CLKSOURCE_PLL)
3397  {
3398  if(__HAL_RCC_GET_PLLCLKOUT_CONFIG(RCC_PLL_SAI2CLK) != 0U)
3399  {
3400  /* f(PLL Source) / PLLM */
3401  pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
3402  /* f(PLLSAI2CLK) = f(VCO input) * PLLN / PLLP */
3403  plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
3404 #if defined(RCC_PLLP_DIV_2_31_SUPPORT)
3405  pllp = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLPDIV) >> RCC_PLLCFGR_PLLPDIV_Pos;
3406 #endif
3407  if(pllp == 0U)
3408  {
3409  if(READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) != 0U)
3410  {
3411  pllp = 17U;
3412  }
3413  else
3414  {
3415  pllp = 7U;
3416  }
3417  }
3418  frequency = (pllvco * plln) / pllp;
3419  }
3420  else if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
3421  {
3422  /* HSI automatically selected as clock source if PLLs not enabled */
3423  frequency = HSI_VALUE;
3424  }
3425  else
3426  {
3427  /* No clock source, frequency default init at 0 */
3428  }
3429  }
3430  else if(srcclk == RCC_SAI1CLKSOURCE_PLLSAI1)
3431  {
3432  if(__HAL_RCC_GET_PLLSAI1CLKOUT_CONFIG(RCC_PLLSAI1_SAI1CLK) != 0U)
3433  {
3434 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
3435  /* PLLSAI1M exists: apply PLLSAI1M divider for PLLSAI1 output computation */
3436  /* f(PLLSAI1 Source) / PLLSAI1M */
3437  pllvco = (pllvco / ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U));
3438 #else
3439  /* f(PLL Source) / PLLM */
3440  pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
3441 #endif
3442  /* f(PLLSAI1CLK) = f(VCOSAI1 input) * PLLSAI1N / PLLSAI1P */
3443  plln = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
3444 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
3445  pllp = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1PDIV) >> RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos;
3446 #endif
3447  if(pllp == 0U)
3448  {
3449  if(READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1P) != 0U)
3450  {
3451  pllp = 17U;
3452  }
3453  else
3454  {
3455  pllp = 7U;
3456  }
3457  }
3458  frequency = (pllvco * plln) / pllp;
3459  }
3460  else if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
3461  {
3462  /* HSI automatically selected as clock source if PLLs not enabled */
3463  frequency = HSI_VALUE;
3464  }
3465  else
3466  {
3467  /* No clock source, frequency default init at 0 */
3468  }
3469  }
3470 #endif /* SAI2 */
3471 
3472 #if defined(RCC_PLLSAI2_SUPPORT)
3473 
3474  else if((srcclk == RCC_SAI1CLKSOURCE_PLLSAI2) || (srcclk == RCC_SAI2CLKSOURCE_PLLSAI2))
3475  {
3476  if(__HAL_RCC_GET_PLLSAI2CLKOUT_CONFIG(RCC_PLLSAI2_SAI2CLK) != 0U)
3477  {
3478 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
3479  /* PLLSAI2M exists: apply PLLSAI2M divider for PLLSAI2 output computation */
3480  /* f(PLLSAI2 Source) / PLLSAI2M */
3481  pllvco = (pllvco / ((READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2M) >> RCC_PLLSAI2CFGR_PLLSAI2M_Pos) + 1U));
3482 #else
3483  /* f(PLL Source) / PLLM */
3484  pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
3485 #endif
3486  /* f(PLLSAI2CLK) = f(VCOSAI2 input) * PLLSAI2N / PLLSAI2P */
3487  plln = READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2N) >> RCC_PLLSAI2CFGR_PLLSAI2N_Pos;
3488 #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
3489  pllp = READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2PDIV) >> RCC_PLLSAI2CFGR_PLLSAI2PDIV_Pos;
3490 #endif
3491  if(pllp == 0U)
3492  {
3493  if(READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2P) != 0U)
3494  {
3495  pllp = 17U;
3496  }
3497  else
3498  {
3499  pllp = 7U;
3500  }
3501  }
3502  frequency = (pllvco * plln) / pllp;
3503  }
3504  }
3505 
3506 #endif /* RCC_PLLSAI2_SUPPORT */
3507 
3508  else
3509  {
3510  /* No clock source, frequency default init at 0 */
3511  }
3512  }
3513 
3514 
3515  return frequency;
3516 }
__STATIC_INLINE void uint32_t PeriphClk

◆ RCCEx_PLLSAI1_Config()

static HAL_StatusTypeDef RCCEx_PLLSAI1_Config ( RCC_PLLSAI1InitTypeDef *  PllSai1,
uint32_t  Divider 
)
static

Configure the parameters N & P & optionally M of PLLSAI1 and enable PLLSAI1 output clock(s).

Parameters
PllSai1pointer to an RCC_PLLSAI1InitTypeDef structure that contains the configuration parameters N & P & optionally M as well as PLLSAI1 output clock(s)
Dividerdivider parameter to be updated
Note
PLLSAI1 is temporary disable to apply new parameters
Return values
HALstatus

Definition at line 2888 of file stm32l4xx_hal_rcc_ex.c.

2889 {
2890  uint32_t tickstart;
2891  HAL_StatusTypeDef status = HAL_OK;
2892 
2893  /* check for PLLSAI1 Parameters used to output PLLSAI1CLK */
2894  /* P, Q and R dividers are verified in each specific divider case below */
2895  assert_param(IS_RCC_PLLSAI1SOURCE(PllSai1->PLLSAI1Source));
2896  assert_param(IS_RCC_PLLSAI1M_VALUE(PllSai1->PLLSAI1M));
2897  assert_param(IS_RCC_PLLSAI1N_VALUE(PllSai1->PLLSAI1N));
2898  assert_param(IS_RCC_PLLSAI1CLOCKOUT_VALUE(PllSai1->PLLSAI1ClockOut));
2899 
2900  /* Check that PLLSAI1 clock source and divider M can be applied */
2901  if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_NONE)
2902  {
2903  /* PLL clock source and divider M already set, check that no request for change */
2904  if((__HAL_RCC_GET_PLL_OSCSOURCE() != PllSai1->PLLSAI1Source)
2905  ||
2906  (PllSai1->PLLSAI1Source == RCC_PLLSOURCE_NONE)
2907 #if !defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
2908  ||
2909  (((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U) != PllSai1->PLLSAI1M)
2910 #endif
2911  )
2912  {
2913  status = HAL_ERROR;
2914  }
2915  }
2916  else
2917  {
2918  /* Check PLLSAI1 clock source availability */
2919  switch(PllSai1->PLLSAI1Source)
2920  {
2921  case RCC_PLLSOURCE_MSI:
2922  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_MSIRDY))
2923  {
2924  status = HAL_ERROR;
2925  }
2926  break;
2927  case RCC_PLLSOURCE_HSI:
2928  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSIRDY))
2929  {
2930  status = HAL_ERROR;
2931  }
2932  break;
2933  case RCC_PLLSOURCE_HSE:
2934  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSERDY))
2935  {
2936  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSEBYP))
2937  {
2938  status = HAL_ERROR;
2939  }
2940  }
2941  break;
2942  default:
2943  status = HAL_ERROR;
2944  break;
2945  }
2946 
2947  if(status == HAL_OK)
2948  {
2949 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
2950  /* Set PLLSAI1 clock source */
2951  MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PllSai1->PLLSAI1Source);
2952 #else
2953  /* Set PLLSAI1 clock source and divider M */
2954  MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM, PllSai1->PLLSAI1Source | (PllSai1->PLLSAI1M - 1U) << RCC_PLLCFGR_PLLM_Pos);
2955 #endif
2956  }
2957  }
2958 
2959  if(status == HAL_OK)
2960  {
2961  /* Disable the PLLSAI1 */
2962  __HAL_RCC_PLLSAI1_DISABLE();
2963 
2964  /* Get Start Tick*/
2965  tickstart = HAL_GetTick();
2966 
2967  /* Wait till PLLSAI1 is ready to be updated */
2968  while(READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) != 0U)
2969  {
2970  if((HAL_GetTick() - tickstart) > PLLSAI1_TIMEOUT_VALUE)
2971  {
2972  status = HAL_TIMEOUT;
2973  break;
2974  }
2975  }
2976 
2977  if(status == HAL_OK)
2978  {
2979  if(Divider == DIVIDER_P_UPDATE)
2980  {
2981  assert_param(IS_RCC_PLLSAI1P_VALUE(PllSai1->PLLSAI1P));
2982 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
2983 
2984  /* Configure the PLLSAI1 Division factor M, P and Multiplication factor N*/
2985 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
2986  MODIFY_REG(RCC->PLLSAI1CFGR,
2987  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1PDIV | RCC_PLLSAI1CFGR_PLLSAI1M,
2988  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
2989  (PllSai1->PLLSAI1P << RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos) |
2990  ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
2991 #else
2992  MODIFY_REG(RCC->PLLSAI1CFGR,
2993  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1P | RCC_PLLSAI1CFGR_PLLSAI1M,
2994  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
2995  ((PllSai1->PLLSAI1P >> 4U) << RCC_PLLSAI1CFGR_PLLSAI1P_Pos) |
2996  ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
2997 #endif /* RCC_PLLSAI1P_DIV_2_31_SUPPORT */
2998 
2999 #else
3000  /* Configure the PLLSAI1 Division factor P and Multiplication factor N*/
3001 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
3002  MODIFY_REG(RCC->PLLSAI1CFGR,
3003  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1PDIV,
3004  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
3005  (PllSai1->PLLSAI1P << RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos));
3006 #else
3007  MODIFY_REG(RCC->PLLSAI1CFGR,
3008  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1P,
3009  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
3010  ((PllSai1->PLLSAI1P >> 4U) << RCC_PLLSAI1CFGR_PLLSAI1P_Pos));
3011 #endif /* RCC_PLLSAI1P_DIV_2_31_SUPPORT */
3012 
3013 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
3014  }
3015  else if(Divider == DIVIDER_Q_UPDATE)
3016  {
3017  assert_param(IS_RCC_PLLSAI1Q_VALUE(PllSai1->PLLSAI1Q));
3018 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
3019  /* Configure the PLLSAI1 Division factor M, Q and Multiplication factor N*/
3020  MODIFY_REG(RCC->PLLSAI1CFGR,
3021  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1Q | RCC_PLLSAI1CFGR_PLLSAI1M,
3022  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
3023  (((PllSai1->PLLSAI1Q >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1Q_Pos) |
3024  ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
3025 #else
3026  /* Configure the PLLSAI1 Division factor Q and Multiplication factor N*/
3027  MODIFY_REG(RCC->PLLSAI1CFGR,
3028  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1Q,
3029  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
3030  (((PllSai1->PLLSAI1Q >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1Q_Pos));
3031 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
3032  }
3033  else
3034  {
3035  assert_param(IS_RCC_PLLSAI1R_VALUE(PllSai1->PLLSAI1R));
3036 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
3037  /* Configure the PLLSAI1 Division factor M, R and Multiplication factor N*/
3038  MODIFY_REG(RCC->PLLSAI1CFGR,
3039  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1R | RCC_PLLSAI1CFGR_PLLSAI1M,
3040  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
3041  (((PllSai1->PLLSAI1R >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1R_Pos) |
3042  ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
3043 #else
3044  /* Configure the PLLSAI1 Division factor R and Multiplication factor N*/
3045  MODIFY_REG(RCC->PLLSAI1CFGR,
3046  RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1R,
3047  (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
3048  (((PllSai1->PLLSAI1R >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1R_Pos));
3049 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
3050  }
3051 
3052  /* Enable the PLLSAI1 again by setting PLLSAI1ON to 1*/
3053  __HAL_RCC_PLLSAI1_ENABLE();
3054 
3055  /* Get Start Tick*/
3056  tickstart = HAL_GetTick();
3057 
3058  /* Wait till PLLSAI1 is ready */
3059  while(READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) == 0U)
3060  {
3061  if((HAL_GetTick() - tickstart) > PLLSAI1_TIMEOUT_VALUE)
3062  {
3063  status = HAL_TIMEOUT;
3064  break;
3065  }
3066  }
3067 
3068  if(status == HAL_OK)
3069  {
3070  /* Configure the PLLSAI1 Clock output(s) */
3071  __HAL_RCC_PLLSAI1CLKOUT_ENABLE(PllSai1->PLLSAI1ClockOut);
3072  }
3073  }
3074  }
3075 
3076  return status;
3077 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK
ADC handle Structure definition.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ RCCEx_PLLSAI2_Config()

static HAL_StatusTypeDef RCCEx_PLLSAI2_Config ( RCC_PLLSAI2InitTypeDef PllSai2,
uint32_t  Divider 
)
static

Configure the parameters N & P & optionally M of PLLSAI2 and enable PLLSAI2 output clock(s).

Parameters
PllSai2pointer to an RCC_PLLSAI2InitTypeDef structure that contains the configuration parameters N & P & optionally M as well as PLLSAI2 output clock(s)
Dividerdivider parameter to be updated
Note
PLLSAI2 is temporary disable to apply new parameters
Return values
HALstatus

Definition at line 3093 of file stm32l4xx_hal_rcc_ex.c.

3094 {
3095  uint32_t tickstart;
3096  HAL_StatusTypeDef status = HAL_OK;
3097 
3098  /* check for PLLSAI2 Parameters used to output PLLSAI2CLK */
3099  /* P, Q and R dividers are verified in each specific divider case below */
3100  assert_param(IS_RCC_PLLSAI2SOURCE(PllSai2->PLLSAI2Source));
3101  assert_param(IS_RCC_PLLSAI2M_VALUE(PllSai2->PLLSAI2M));
3102  assert_param(IS_RCC_PLLSAI2N_VALUE(PllSai2->PLLSAI2N));
3103  assert_param(IS_RCC_PLLSAI2CLOCKOUT_VALUE(PllSai2->PLLSAI2ClockOut));
3104 
3105  /* Check that PLLSAI2 clock source and divider M can be applied */
3106  if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_NONE)
3107  {
3108  /* PLL clock source and divider M already set, check that no request for change */
3109  if((__HAL_RCC_GET_PLL_OSCSOURCE() != PllSai2->PLLSAI2Source)
3110  ||
3111  (PllSai2->PLLSAI2Source == RCC_PLLSOURCE_NONE)
3112 #if !defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
3113  ||
3114  (((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U) != PllSai2->PLLSAI2M)
3115 #endif
3116  )
3117  {
3118  status = HAL_ERROR;
3119  }
3120  }
3121  else
3122  {
3123  /* Check PLLSAI2 clock source availability */
3124  switch(PllSai2->PLLSAI2Source)
3125  {
3126  case RCC_PLLSOURCE_MSI:
3127  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_MSIRDY))
3128  {
3129  status = HAL_ERROR;
3130  }
3131  break;
3132  case RCC_PLLSOURCE_HSI:
3133  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSIRDY))
3134  {
3135  status = HAL_ERROR;
3136  }
3137  break;
3138  case RCC_PLLSOURCE_HSE:
3139  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSERDY))
3140  {
3141  if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSEBYP))
3142  {
3143  status = HAL_ERROR;
3144  }
3145  }
3146  break;
3147  default:
3148  status = HAL_ERROR;
3149  break;
3150  }
3151 
3152  if(status == HAL_OK)
3153  {
3154 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
3155  /* Set PLLSAI2 clock source */
3156  MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PllSai2->PLLSAI2Source);
3157 #else
3158  /* Set PLLSAI2 clock source and divider M */
3159  MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM, PllSai2->PLLSAI2Source | (PllSai2->PLLSAI2M - 1U) << RCC_PLLCFGR_PLLM_Pos);
3160 #endif
3161  }
3162  }
3163 
3164  if(status == HAL_OK)
3165  {
3166  /* Disable the PLLSAI2 */
3167  __HAL_RCC_PLLSAI2_DISABLE();
3168 
3169  /* Get Start Tick*/
3170  tickstart = HAL_GetTick();
3171 
3172  /* Wait till PLLSAI2 is ready to be updated */
3173  while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) != 0U)
3174  {
3175  if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
3176  {
3177  status = HAL_TIMEOUT;
3178  break;
3179  }
3180  }
3181 
3182  if(status == HAL_OK)
3183  {
3184  if(Divider == DIVIDER_P_UPDATE)
3185  {
3186  assert_param(IS_RCC_PLLSAI2P_VALUE(PllSai2->PLLSAI2P));
3187 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
3188 
3189  /* Configure the PLLSAI2 Division factor M, P and Multiplication factor N*/
3190 #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
3191  MODIFY_REG(RCC->PLLSAI2CFGR,
3192  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2PDIV | RCC_PLLSAI2CFGR_PLLSAI2M,
3193  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3194  (PllSai2->PLLSAI2P << RCC_PLLSAI2CFGR_PLLSAI2PDIV_Pos) |
3195  ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
3196 #else
3197  MODIFY_REG(RCC->PLLSAI2CFGR,
3198  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2P | RCC_PLLSAI2CFGR_PLLSAI2M,
3199  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3200  ((PllSai2->PLLSAI2P >> 4U) << RCC_PLLSAI2CFGR_PLLSAI2P_Pos) |
3201  ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
3202 #endif /* RCC_PLLSAI2P_DIV_2_31_SUPPORT */
3203 
3204 #else
3205  /* Configure the PLLSAI2 Division factor P and Multiplication factor N*/
3206 #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
3207  MODIFY_REG(RCC->PLLSAI2CFGR,
3208  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2PDIV,
3209  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3210  (PllSai2->PLLSAI2P << RCC_PLLSAI2CFGR_PLLSAI2PDIV_Pos));
3211 #else
3212  MODIFY_REG(RCC->PLLSAI2CFGR,
3213  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2P,
3214  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3215  ((PllSai2->PLLSAI2P >> 4U) << RCC_PLLSAI2CFGR_PLLSAI2P_Pos));
3216 #endif /* RCC_PLLSAI2P_DIV_2_31_SUPPORT */
3217 
3218 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT */
3219  }
3220 #if defined(RCC_PLLSAI2Q_DIV_SUPPORT)
3221  else if(Divider == DIVIDER_Q_UPDATE)
3222  {
3223  assert_param(IS_RCC_PLLSAI2Q_VALUE(PllSai2->PLLSAI2Q));
3224 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
3225  /* Configure the PLLSAI2 Division factor M, Q and Multiplication factor N*/
3226  MODIFY_REG(RCC->PLLSAI2CFGR,
3227  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2Q | RCC_PLLSAI2CFGR_PLLSAI2M,
3228  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3229  (((PllSai2->PLLSAI2Q >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2Q_Pos) |
3230  ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
3231 #else
3232  /* Configure the PLLSAI2 Division factor Q and Multiplication factor N*/
3233  MODIFY_REG(RCC->PLLSAI2CFGR,
3234  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2Q,
3235  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3236  (((PllSai2->PLLSAI2Q >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2Q_Pos));
3237 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT */
3238  }
3239 #endif /* RCC_PLLSAI2Q_DIV_SUPPORT */
3240  else
3241  {
3242  assert_param(IS_RCC_PLLSAI2R_VALUE(PllSai2->PLLSAI2R));
3243 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
3244  /* Configure the PLLSAI2 Division factor M, R and Multiplication factor N*/
3245  MODIFY_REG(RCC->PLLSAI2CFGR,
3246  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2R | RCC_PLLSAI2CFGR_PLLSAI2M,
3247  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3248  (((PllSai2->PLLSAI2R >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2R_Pos) |
3249  ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
3250 #else
3251  /* Configure the PLLSAI2 Division factor R and Multiplication factor N*/
3252  MODIFY_REG(RCC->PLLSAI2CFGR,
3253  RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2R,
3254  (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
3255  (((PllSai2->PLLSAI2R >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2R_Pos));
3256 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT */
3257  }
3258 
3259  /* Enable the PLLSAI2 again by setting PLLSAI2ON to 1*/
3260  __HAL_RCC_PLLSAI2_ENABLE();
3261 
3262  /* Get Start Tick*/
3263  tickstart = HAL_GetTick();
3264 
3265  /* Wait till PLLSAI2 is ready */
3266  while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) == 0U)
3267  {
3268  if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
3269  {
3270  status = HAL_TIMEOUT;
3271  break;
3272  }
3273  }
3274 
3275  if(status == HAL_OK)
3276  {
3277  /* Configure the PLLSAI2 Clock output(s) */
3278  __HAL_RCC_PLLSAI2CLKOUT_ENABLE(PllSai2->PLLSAI2ClockOut);
3279  }
3280  }
3281  }
3282 
3283  return status;
3284 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK
ADC handle Structure definition.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))