2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_rcc_ex.c
\r
4 * @author MCD Application Team
\r
5 * @brief Extended RCC HAL module driver.
\r
6 * This file provides firmware functions to manage the following
\r
7 * functionalities RCC extended peripheral:
\r
8 * + Extended Peripheral Control functions
\r
9 * + Extended Clock management functions
\r
10 * + Extended Clock Recovery System Control functions
\r
12 ******************************************************************************
\r
15 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
16 * All rights reserved.</center></h2>
\r
18 * This software component is licensed by ST under BSD 3-Clause license,
\r
19 * the "License"; You may not use this file except in compliance with the
\r
20 * License. You may obtain a copy of the License at:
\r
21 * opensource.org/licenses/BSD-3-Clause
\r
23 ******************************************************************************
\r
26 /* Includes ------------------------------------------------------------------*/
\r
27 #include "stm32l4xx_hal.h"
\r
29 /** @addtogroup STM32L4xx_HAL_Driver
\r
33 /** @defgroup RCCEx RCCEx
\r
34 * @brief RCC Extended HAL module driver
\r
38 #ifdef HAL_RCC_MODULE_ENABLED
\r
40 /* Private typedef -----------------------------------------------------------*/
\r
41 /* Private defines -----------------------------------------------------------*/
\r
42 /** @defgroup RCCEx_Private_Constants RCCEx Private Constants
\r
45 #define PLLSAI1_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
\r
46 #define PLLSAI2_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
\r
47 #define PLL_TIMEOUT_VALUE 2U /* 2 ms (minimum Tick + 1) */
\r
49 #define DIVIDER_P_UPDATE 0U
\r
50 #define DIVIDER_Q_UPDATE 1U
\r
51 #define DIVIDER_R_UPDATE 2U
\r
53 #define __LSCO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
\r
54 #define LSCO_GPIO_PORT GPIOA
\r
55 #define LSCO_PIN GPIO_PIN_2
\r
60 /* Private macros ------------------------------------------------------------*/
\r
61 /* Private variables ---------------------------------------------------------*/
\r
62 /* Private function prototypes -----------------------------------------------*/
\r
63 /** @defgroup RCCEx_Private_Functions RCCEx Private Functions
\r
66 #if defined(RCC_PLLSAI1_SUPPORT)
\r
68 static HAL_StatusTypeDef RCCEx_PLLSAI1_Config(RCC_PLLSAI1InitTypeDef *PllSai1, uint32_t Divider);
\r
70 #endif /* RCC_PLLSAI1_SUPPORT */
\r
72 #if defined(RCC_PLLSAI2_SUPPORT)
\r
74 static HAL_StatusTypeDef RCCEx_PLLSAI2_Config(RCC_PLLSAI2InitTypeDef *PllSai2, uint32_t Divider);
\r
76 #endif /* RCC_PLLSAI2_SUPPORT */
\r
80 static uint32_t RCCEx_GetSAIxPeriphCLKFreq(uint32_t PeriphClk, uint32_t InputFrequency);
\r
87 /* Exported functions --------------------------------------------------------*/
\r
89 /** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
\r
93 /** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
\r
94 * @brief Extended Peripheral Control functions
\r
97 ===============================================================================
\r
98 ##### Extended Peripheral Control functions #####
\r
99 ===============================================================================
\r
101 This subsection provides a set of functions allowing to control the RCC Clocks
\r
104 (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
\r
105 select the RTC clock source; in this case the Backup domain will be reset in
\r
106 order to modify the RTC Clock source, as consequence RTC registers (including
\r
107 the backup registers) are set to their reset values.
\r
113 * @brief Initialize the RCC extended peripherals clocks according to the specified
\r
114 * parameters in the RCC_PeriphCLKInitTypeDef.
\r
115 * @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
\r
116 * contains a field PeriphClockSelection which can be a combination of the following values:
\r
117 * @arg @ref RCC_PERIPHCLK_RTC RTC peripheral clock
\r
118 * @arg @ref RCC_PERIPHCLK_ADC ADC peripheral clock
\r
120 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral clock (only for devices with DFSDM1)
\r
123 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral clock (only for devices with DFSDM1)
\r
126 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral clock (only for devices with DFSDM1)
\r
128 * @arg @ref RCC_PERIPHCLK_I2C1 I2C1 peripheral clock
\r
129 * @arg @ref RCC_PERIPHCLK_I2C2 I2C2 peripheral clock
\r
130 * @arg @ref RCC_PERIPHCLK_I2C3 I2C3 peripheral clock
\r
132 * @arg @ref RCC_PERIPHCLK_I2C4 I2C4 peripheral clock (only for devices with I2C4)
\r
135 * @arg @ref RCC_PERIPHCLK_I2C4 I2C4 peripheral clock (only for devices with I2C4)
\r
138 * @arg @ref RCC_PERIPHCLK_I2C4 I2C4 peripheral clock (only for devices with I2C4)
\r
140 * @arg @ref RCC_PERIPHCLK_LPTIM1 LPTIM1 peripheral clock
\r
141 * @arg @ref RCC_PERIPHCLK_LPTIM2 LPTIM2 peripheral clock
\r
142 * @arg @ref RCC_PERIPHCLK_LPUART1 LPUART1 peripheral clock
\r
143 * @arg @ref RCC_PERIPHCLK_RNG RNG peripheral clock
\r
144 * @arg @ref RCC_PERIPHCLK_SAI1 SAI1 peripheral clock (only for devices with SAI1)
\r
146 * @arg @ref RCC_PERIPHCLK_SAI2 SAI2 peripheral clock (only for devices with SAI2)
\r
149 * @arg @ref RCC_PERIPHCLK_SAI2 SAI2 peripheral clock (only for devices with SAI2)
\r
152 * @arg @ref RCC_PERIPHCLK_SAI2 SAI2 peripheral clock (only for devices with SAI2)
\r
154 * @arg @ref RCC_PERIPHCLK_SDMMC1 SDMMC1 peripheral clock
\r
156 * @arg @ref RCC_PERIPHCLK_SWPMI1 SWPMI1 peripheral clock (only for devices with SWPMI1)
\r
159 * @arg @ref RCC_PERIPHCLK_SWPMI1 SWPMI1 peripheral clock (only for devices with SWPMI1)
\r
162 * @arg @ref RCC_PERIPHCLK_SWPMI1 SWPMI1 peripheral clock (only for devices with SWPMI1)
\r
164 * @arg @ref RCC_PERIPHCLK_USART1 USART1 peripheral clock
\r
165 * @arg @ref RCC_PERIPHCLK_USART2 USART1 peripheral clock
\r
166 * @arg @ref RCC_PERIPHCLK_USART3 USART1 peripheral clock
\r
168 * @arg @ref RCC_PERIPHCLK_UART4 USART1 peripheral clock (only for devices with UART4)
\r
171 * @arg @ref RCC_PERIPHCLK_UART4 USART1 peripheral clock (only for devices with UART4)
\r
172 * @arg @ref RCC_PERIPHCLK_UART5 USART1 peripheral clock (only for devices with UART5)
\r
173 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock (only for devices with USB)
\r
176 * @arg @ref RCC_PERIPHCLK_UART4 USART1 peripheral clock (only for devices with UART4)
\r
177 * @arg @ref RCC_PERIPHCLK_UART5 USART1 peripheral clock (only for devices with UART5)
\r
178 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock (only for devices with USB)
\r
181 * @arg @ref RCC_PERIPHCLK_UART4 USART1 peripheral clock (only for devices with UART4)
\r
182 * @arg @ref RCC_PERIPHCLK_UART5 USART1 peripheral clock (only for devices with UART5)
\r
183 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock (only for devices with USB)
\r
184 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral kernel clock (only for devices with DFSDM1)
\r
185 * @arg @ref RCC_PERIPHCLK_DFSDM1AUDIO DFSDM1 peripheral audio clock (only for devices with DFSDM1)
\r
186 * @arg @ref RCC_PERIPHCLK_LTDC LTDC peripheral clock (only for devices with LTDC)
\r
187 * @arg @ref RCC_PERIPHCLK_DSI DSI peripheral clock (only for devices with DSI)
\r
188 * @arg @ref RCC_PERIPHCLK_OSPI OctoSPI peripheral clock (only for devices with OctoSPI)
\r
191 * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
\r
192 * the RTC clock source: in this case the access to Backup domain is enabled.
\r
194 * @retval HAL status
\r
196 HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
\r
198 uint32_t tmpregister, tickstart; /* no init needed */
\r
199 HAL_StatusTypeDef ret = HAL_OK; /* Intermediate status */
\r
200 HAL_StatusTypeDef status = HAL_OK; /* Final status */
\r
202 /* Check the parameters */
\r
203 assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
\r
207 /*-------------------------- SAI1 clock source configuration ---------------------*/
\r
208 if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1))
\r
210 /* Check the parameters */
\r
211 assert_param(IS_RCC_SAI1CLK(PeriphClkInit->Sai1ClockSelection));
\r
213 switch(PeriphClkInit->Sai1ClockSelection)
\r
215 case RCC_SAI1CLKSOURCE_PLL: /* PLL is used as clock source for SAI1*/
\r
216 /* Enable SAI Clock output generated form System PLL . */
\r
217 #if defined(RCC_PLLSAI2_SUPPORT)
\r
218 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_SAI3CLK);
\r
220 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_SAI2CLK);
\r
221 #endif /* RCC_PLLSAI2_SUPPORT */
\r
222 /* SAI1 clock source config set later after clock selection check */
\r
225 case RCC_SAI1CLKSOURCE_PLLSAI1: /* PLLSAI1 is used as clock source for SAI1*/
\r
226 /* PLLSAI1 input clock, parameters M, N & P configuration and clock output (PLLSAI1ClockOut) */
\r
227 ret = RCCEx_PLLSAI1_Config(&(PeriphClkInit->PLLSAI1), DIVIDER_P_UPDATE);
\r
228 /* SAI1 clock source config set later after clock selection check */
\r
231 #if defined(RCC_PLLSAI2_SUPPORT)
\r
233 case RCC_SAI1CLKSOURCE_PLLSAI2: /* PLLSAI2 is used as clock source for SAI1*/
\r
234 /* PLLSAI2 input clock, parameters M, N & P configuration clock output (PLLSAI2ClockOut) */
\r
235 ret = RCCEx_PLLSAI2_Config(&(PeriphClkInit->PLLSAI2), DIVIDER_P_UPDATE);
\r
236 /* SAI1 clock source config set later after clock selection check */
\r
239 #endif /* RCC_PLLSAI2_SUPPORT */
\r
241 case RCC_SAI1CLKSOURCE_PIN: /* External clock is used as source of SAI1 clock*/
\r
242 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
243 case RCC_SAI1CLKSOURCE_HSI: /* HSI is used as source of SAI1 clock*/
\r
244 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
245 /* SAI1 clock source config set later after clock selection check */
\r
255 /* Set the source of SAI1 clock*/
\r
256 __HAL_RCC_SAI1_CONFIG(PeriphClkInit->Sai1ClockSelection);
\r
260 /* set overall return value */
\r
269 /*-------------------------- SAI2 clock source configuration ---------------------*/
\r
270 if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2))
\r
272 /* Check the parameters */
\r
273 assert_param(IS_RCC_SAI2CLK(PeriphClkInit->Sai2ClockSelection));
\r
275 switch(PeriphClkInit->Sai2ClockSelection)
\r
277 case RCC_SAI2CLKSOURCE_PLL: /* PLL is used as clock source for SAI2*/
\r
278 /* Enable SAI Clock output generated form System PLL . */
\r
279 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_SAI3CLK);
\r
280 /* SAI2 clock source config set later after clock selection check */
\r
283 case RCC_SAI2CLKSOURCE_PLLSAI1: /* PLLSAI1 is used as clock source for SAI2*/
\r
284 /* PLLSAI1 input clock, parameters M, N & P configuration and clock output (PLLSAI1ClockOut) */
\r
285 ret = RCCEx_PLLSAI1_Config(&(PeriphClkInit->PLLSAI1), DIVIDER_P_UPDATE);
\r
286 /* SAI2 clock source config set later after clock selection check */
\r
289 case RCC_SAI2CLKSOURCE_PLLSAI2: /* PLLSAI2 is used as clock source for SAI2*/
\r
290 /* PLLSAI2 input clock, parameters M, N & P configuration and clock output (PLLSAI2ClockOut) */
\r
291 ret = RCCEx_PLLSAI2_Config(&(PeriphClkInit->PLLSAI2), DIVIDER_P_UPDATE);
\r
292 /* SAI2 clock source config set later after clock selection check */
\r
295 case RCC_SAI2CLKSOURCE_PIN: /* External clock is used as source of SAI2 clock*/
\r
296 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
297 case RCC_SAI2CLKSOURCE_HSI: /* HSI is used as source of SAI2 clock*/
\r
298 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
299 /* SAI2 clock source config set later after clock selection check */
\r
309 /* Set the source of SAI2 clock*/
\r
310 __HAL_RCC_SAI2_CONFIG(PeriphClkInit->Sai2ClockSelection);
\r
314 /* set overall return value */
\r
320 /*-------------------------- RTC clock source configuration ----------------------*/
\r
321 if((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)
\r
323 FlagStatus pwrclkchanged = RESET;
\r
325 /* Check for RTC Parameters used to output RTCCLK */
\r
326 assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
\r
328 /* Enable Power Clock */
\r
329 if(__HAL_RCC_PWR_IS_CLK_DISABLED() != 0U)
\r
331 __HAL_RCC_PWR_CLK_ENABLE();
\r
332 pwrclkchanged = SET;
\r
335 /* Enable write access to Backup domain */
\r
336 SET_BIT(PWR->CR1, PWR_CR1_DBP);
\r
338 /* Wait for Backup domain Write protection disable */
\r
339 tickstart = HAL_GetTick();
\r
341 while(READ_BIT(PWR->CR1, PWR_CR1_DBP) == 0U)
\r
343 if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
\r
352 /* Reset the Backup domain only if the RTC Clock source selection is modified from default */
\r
353 tmpregister = READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL);
\r
355 if((tmpregister != RCC_RTCCLKSOURCE_NONE) && (tmpregister != PeriphClkInit->RTCClockSelection))
\r
357 /* Store the content of BDCR register before the reset of Backup Domain */
\r
358 tmpregister = READ_BIT(RCC->BDCR, ~(RCC_BDCR_RTCSEL));
\r
359 /* RTC Clock selection can be changed only if the Backup Domain is reset */
\r
360 __HAL_RCC_BACKUPRESET_FORCE();
\r
361 __HAL_RCC_BACKUPRESET_RELEASE();
\r
362 /* Restore the Content of BDCR register */
\r
363 RCC->BDCR = tmpregister;
\r
366 /* Wait for LSE reactivation if LSE was enable prior to Backup Domain reset */
\r
367 if (HAL_IS_BIT_SET(tmpregister, RCC_BDCR_LSEON))
\r
369 /* Get Start Tick*/
\r
370 tickstart = HAL_GetTick();
\r
372 /* Wait till LSE is ready */
\r
373 while(READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U)
\r
375 if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
\r
385 /* Apply new RTC clock source selection */
\r
386 __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
\r
390 /* set overall return value */
\r
396 /* set overall return value */
\r
400 /* Restore clock configuration if changed */
\r
401 if(pwrclkchanged == SET)
\r
403 __HAL_RCC_PWR_CLK_DISABLE();
\r
407 /*-------------------------- USART1 clock source configuration -------------------*/
\r
408 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1)
\r
410 /* Check the parameters */
\r
411 assert_param(IS_RCC_USART1CLKSOURCE(PeriphClkInit->Usart1ClockSelection));
\r
413 /* Configure the USART1 clock source */
\r
414 __HAL_RCC_USART1_CONFIG(PeriphClkInit->Usart1ClockSelection);
\r
417 /*-------------------------- USART2 clock source configuration -------------------*/
\r
418 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2)
\r
420 /* Check the parameters */
\r
421 assert_param(IS_RCC_USART2CLKSOURCE(PeriphClkInit->Usart2ClockSelection));
\r
423 /* Configure the USART2 clock source */
\r
424 __HAL_RCC_USART2_CONFIG(PeriphClkInit->Usart2ClockSelection);
\r
427 #if defined(USART3)
\r
429 /*-------------------------- USART3 clock source configuration -------------------*/
\r
430 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3)
\r
432 /* Check the parameters */
\r
433 assert_param(IS_RCC_USART3CLKSOURCE(PeriphClkInit->Usart3ClockSelection));
\r
435 /* Configure the USART3 clock source */
\r
436 __HAL_RCC_USART3_CONFIG(PeriphClkInit->Usart3ClockSelection);
\r
439 #endif /* USART3 */
\r
443 /*-------------------------- UART4 clock source configuration --------------------*/
\r
444 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4)
\r
446 /* Check the parameters */
\r
447 assert_param(IS_RCC_UART4CLKSOURCE(PeriphClkInit->Uart4ClockSelection));
\r
449 /* Configure the UART4 clock source */
\r
450 __HAL_RCC_UART4_CONFIG(PeriphClkInit->Uart4ClockSelection);
\r
457 /*-------------------------- UART5 clock source configuration --------------------*/
\r
458 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5)
\r
460 /* Check the parameters */
\r
461 assert_param(IS_RCC_UART5CLKSOURCE(PeriphClkInit->Uart5ClockSelection));
\r
463 /* Configure the UART5 clock source */
\r
464 __HAL_RCC_UART5_CONFIG(PeriphClkInit->Uart5ClockSelection);
\r
469 /*-------------------------- LPUART1 clock source configuration ------------------*/
\r
470 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1)
\r
472 /* Check the parameters */
\r
473 assert_param(IS_RCC_LPUART1CLKSOURCE(PeriphClkInit->Lpuart1ClockSelection));
\r
475 /* Configure the LPUAR1 clock source */
\r
476 __HAL_RCC_LPUART1_CONFIG(PeriphClkInit->Lpuart1ClockSelection);
\r
479 /*-------------------------- LPTIM1 clock source configuration -------------------*/
\r
480 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM1) == (RCC_PERIPHCLK_LPTIM1))
\r
482 assert_param(IS_RCC_LPTIM1CLK(PeriphClkInit->Lptim1ClockSelection));
\r
483 __HAL_RCC_LPTIM1_CONFIG(PeriphClkInit->Lptim1ClockSelection);
\r
486 /*-------------------------- LPTIM2 clock source configuration -------------------*/
\r
487 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM2) == (RCC_PERIPHCLK_LPTIM2))
\r
489 assert_param(IS_RCC_LPTIM2CLK(PeriphClkInit->Lptim2ClockSelection));
\r
490 __HAL_RCC_LPTIM2_CONFIG(PeriphClkInit->Lptim2ClockSelection);
\r
493 /*-------------------------- I2C1 clock source configuration ---------------------*/
\r
494 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1)
\r
496 /* Check the parameters */
\r
497 assert_param(IS_RCC_I2C1CLKSOURCE(PeriphClkInit->I2c1ClockSelection));
\r
499 /* Configure the I2C1 clock source */
\r
500 __HAL_RCC_I2C1_CONFIG(PeriphClkInit->I2c1ClockSelection);
\r
505 /*-------------------------- I2C2 clock source configuration ---------------------*/
\r
506 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2)
\r
508 /* Check the parameters */
\r
509 assert_param(IS_RCC_I2C2CLKSOURCE(PeriphClkInit->I2c2ClockSelection));
\r
511 /* Configure the I2C2 clock source */
\r
512 __HAL_RCC_I2C2_CONFIG(PeriphClkInit->I2c2ClockSelection);
\r
517 /*-------------------------- I2C3 clock source configuration ---------------------*/
\r
518 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3)
\r
520 /* Check the parameters */
\r
521 assert_param(IS_RCC_I2C3CLKSOURCE(PeriphClkInit->I2c3ClockSelection));
\r
523 /* Configure the I2C3 clock source */
\r
524 __HAL_RCC_I2C3_CONFIG(PeriphClkInit->I2c3ClockSelection);
\r
529 /*-------------------------- I2C4 clock source configuration ---------------------*/
\r
530 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4)
\r
532 /* Check the parameters */
\r
533 assert_param(IS_RCC_I2C4CLKSOURCE(PeriphClkInit->I2c4ClockSelection));
\r
535 /* Configure the I2C4 clock source */
\r
536 __HAL_RCC_I2C4_CONFIG(PeriphClkInit->I2c4ClockSelection);
\r
541 #if defined(USB_OTG_FS) || defined(USB)
\r
543 /*-------------------------- USB clock source configuration ----------------------*/
\r
544 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == (RCC_PERIPHCLK_USB))
\r
546 assert_param(IS_RCC_USBCLKSOURCE(PeriphClkInit->UsbClockSelection));
\r
547 __HAL_RCC_USB_CONFIG(PeriphClkInit->UsbClockSelection);
\r
549 if(PeriphClkInit->UsbClockSelection == RCC_USBCLKSOURCE_PLL)
\r
551 /* Enable PLL48M1CLK output */
\r
552 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_48M1CLK);
\r
556 #if defined(RCC_PLLSAI1_SUPPORT)
\r
557 if(PeriphClkInit->UsbClockSelection == RCC_USBCLKSOURCE_PLLSAI1)
\r
559 /* PLLSAI1 input clock, parameters M, N & Q configuration and clock output (PLLSAI1ClockOut) */
\r
560 ret = RCCEx_PLLSAI1_Config(&(PeriphClkInit->PLLSAI1), DIVIDER_Q_UPDATE);
\r
564 /* set overall return value */
\r
568 #endif /* RCC_PLLSAI1_SUPPORT */
\r
572 #endif /* USB_OTG_FS || USB */
\r
574 #if defined(SDMMC1)
\r
576 /*-------------------------- SDMMC1 clock source configuration -------------------*/
\r
577 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC1) == (RCC_PERIPHCLK_SDMMC1))
\r
579 assert_param(IS_RCC_SDMMC1CLKSOURCE(PeriphClkInit->Sdmmc1ClockSelection));
\r
580 __HAL_RCC_SDMMC1_CONFIG(PeriphClkInit->Sdmmc1ClockSelection);
\r
582 if(PeriphClkInit->Sdmmc1ClockSelection == RCC_SDMMC1CLKSOURCE_PLL) /* PLL "Q" ? */
\r
584 /* Enable PLL48M1CLK output */
\r
585 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_48M1CLK);
\r
587 #if defined(RCC_CCIPR2_SDMMCSEL)
\r
588 else if(PeriphClkInit->Sdmmc1ClockSelection == RCC_SDMMC1CLKSOURCE_PLLP) /* PLL "P" ? */
\r
590 /* Enable PLLSAI3CLK output */
\r
591 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_SAI3CLK);
\r
594 else if(PeriphClkInit->Sdmmc1ClockSelection == RCC_SDMMC1CLKSOURCE_PLLSAI1)
\r
596 /* PLLSAI1 input clock, parameters M, N & Q configuration and clock output (PLLSAI1ClockOut) */
\r
597 ret = RCCEx_PLLSAI1_Config(&(PeriphClkInit->PLLSAI1), DIVIDER_Q_UPDATE);
\r
601 /* set overall return value */
\r
607 /* nothing to do */
\r
611 #endif /* SDMMC1 */
\r
613 /*-------------------------- RNG clock source configuration ----------------------*/
\r
614 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RNG) == (RCC_PERIPHCLK_RNG))
\r
616 assert_param(IS_RCC_RNGCLKSOURCE(PeriphClkInit->RngClockSelection));
\r
617 __HAL_RCC_RNG_CONFIG(PeriphClkInit->RngClockSelection);
\r
619 if(PeriphClkInit->RngClockSelection == RCC_RNGCLKSOURCE_PLL)
\r
621 /* Enable PLL48M1CLK output */
\r
622 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_48M1CLK);
\r
624 #if defined(RCC_PLLSAI1_SUPPORT)
\r
625 else if(PeriphClkInit->RngClockSelection == RCC_RNGCLKSOURCE_PLLSAI1)
\r
627 /* PLLSAI1 input clock, parameters M, N & Q configuration and clock output (PLLSAI1ClockOut) */
\r
628 ret = RCCEx_PLLSAI1_Config(&(PeriphClkInit->PLLSAI1), DIVIDER_Q_UPDATE);
\r
632 /* set overall return value */
\r
636 #endif /* RCC_PLLSAI1_SUPPORT */
\r
639 /* nothing to do */
\r
643 /*-------------------------- ADC clock source configuration ----------------------*/
\r
644 #if !defined(STM32L412xx) && !defined(STM32L422xx)
\r
645 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC)
\r
647 /* Check the parameters */
\r
648 assert_param(IS_RCC_ADCCLKSOURCE(PeriphClkInit->AdcClockSelection));
\r
650 /* Configure the ADC interface clock source */
\r
651 __HAL_RCC_ADC_CONFIG(PeriphClkInit->AdcClockSelection);
\r
653 #if defined(RCC_PLLSAI1_SUPPORT)
\r
654 if(PeriphClkInit->AdcClockSelection == RCC_ADCCLKSOURCE_PLLSAI1)
\r
656 /* PLLSAI1 input clock, parameters M, N & R configuration and clock output (PLLSAI1ClockOut) */
\r
657 ret = RCCEx_PLLSAI1_Config(&(PeriphClkInit->PLLSAI1), DIVIDER_R_UPDATE);
\r
661 /* set overall return value */
\r
665 #endif /* RCC_PLLSAI1_SUPPORT */
\r
667 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
\r
669 else if(PeriphClkInit->AdcClockSelection == RCC_ADCCLKSOURCE_PLLSAI2)
\r
671 /* PLLSAI2 input clock, parameters M, N & R configuration and clock output (PLLSAI2ClockOut) */
\r
672 ret = RCCEx_PLLSAI2_Config(&(PeriphClkInit->PLLSAI2), DIVIDER_R_UPDATE);
\r
676 /* set overall return value */
\r
681 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || STM32L496xx || STM32L4A6xx */
\r
684 #endif /* !STM32L412xx && !STM32L422xx */
\r
686 #if defined(SWPMI1)
\r
688 /*-------------------------- SWPMI1 clock source configuration -------------------*/
\r
689 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1)
\r
691 /* Check the parameters */
\r
692 assert_param(IS_RCC_SWPMI1CLKSOURCE(PeriphClkInit->Swpmi1ClockSelection));
\r
694 /* Configure the SWPMI1 clock source */
\r
695 __HAL_RCC_SWPMI1_CONFIG(PeriphClkInit->Swpmi1ClockSelection);
\r
698 #endif /* SWPMI1 */
\r
700 #if defined(DFSDM1_Filter0)
\r
702 /*-------------------------- DFSDM1 clock source configuration -------------------*/
\r
703 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1)
\r
705 /* Check the parameters */
\r
706 assert_param(IS_RCC_DFSDM1CLKSOURCE(PeriphClkInit->Dfsdm1ClockSelection));
\r
708 /* Configure the DFSDM1 interface clock source */
\r
709 __HAL_RCC_DFSDM1_CONFIG(PeriphClkInit->Dfsdm1ClockSelection);
\r
712 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
713 /*-------------------------- DFSDM1 audio clock source configuration -------------*/
\r
714 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DFSDM1AUDIO) == RCC_PERIPHCLK_DFSDM1AUDIO)
\r
716 /* Check the parameters */
\r
717 assert_param(IS_RCC_DFSDM1AUDIOCLKSOURCE(PeriphClkInit->Dfsdm1AudioClockSelection));
\r
719 /* Configure the DFSDM1 interface audio clock source */
\r
720 __HAL_RCC_DFSDM1AUDIO_CONFIG(PeriphClkInit->Dfsdm1AudioClockSelection);
\r
723 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
725 #endif /* DFSDM1_Filter0 */
\r
729 /*-------------------------- LTDC clock source configuration --------------------*/
\r
730 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == RCC_PERIPHCLK_LTDC)
\r
732 /* Check the parameters */
\r
733 assert_param(IS_RCC_LTDCCLKSOURCE(PeriphClkInit->LtdcClockSelection));
\r
735 /* Disable the PLLSAI2 */
\r
736 __HAL_RCC_PLLSAI2_DISABLE();
\r
738 /* Get Start Tick*/
\r
739 tickstart = HAL_GetTick();
\r
741 /* Wait till PLLSAI2 is ready */
\r
742 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) != 0U)
\r
744 if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
\r
753 /* Configure the LTDC clock source */
\r
754 __HAL_RCC_LTDC_CONFIG(PeriphClkInit->LtdcClockSelection);
\r
756 /* PLLSAI2 input clock, parameters M, N & R configuration and clock output (PLLSAI2ClockOut) */
\r
757 ret = RCCEx_PLLSAI2_Config(&(PeriphClkInit->PLLSAI2), DIVIDER_R_UPDATE);
\r
762 /* set overall return value */
\r
771 /*-------------------------- DSI clock source configuration ---------------------*/
\r
772 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DSI) == RCC_PERIPHCLK_DSI)
\r
774 /* Check the parameters */
\r
775 assert_param(IS_RCC_DSICLKSOURCE(PeriphClkInit->DsiClockSelection));
\r
777 /* Configure the DSI clock source */
\r
778 __HAL_RCC_DSI_CONFIG(PeriphClkInit->DsiClockSelection);
\r
780 if(PeriphClkInit->DsiClockSelection == RCC_DSICLKSOURCE_PLLSAI2)
\r
782 /* PLLSAI2 input clock, parameters M, N & Q configuration and clock output (PLLSAI2ClockOut) */
\r
783 ret = RCCEx_PLLSAI2_Config(&(PeriphClkInit->PLLSAI2), DIVIDER_Q_UPDATE);
\r
787 /* set overall return value */
\r
795 #if defined(OCTOSPI1) || defined(OCTOSPI2)
\r
797 /*-------------------------- OctoSPIx clock source configuration ----------------*/
\r
798 if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_OSPI) == RCC_PERIPHCLK_OSPI)
\r
800 /* Check the parameters */
\r
801 assert_param(IS_RCC_OSPICLKSOURCE(PeriphClkInit->OspiClockSelection));
\r
803 /* Configure the OctoSPI clock source */
\r
804 __HAL_RCC_OSPI_CONFIG(PeriphClkInit->OspiClockSelection);
\r
806 if(PeriphClkInit->OspiClockSelection == RCC_OSPICLKSOURCE_PLL)
\r
808 /* Enable PLL48M1CLK output */
\r
809 __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_48M1CLK);
\r
813 #endif /* OCTOSPI1 || OCTOSPI2 */
\r
819 * @brief Get the RCC_ClkInitStruct according to the internal RCC configuration registers.
\r
820 * @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
\r
821 * returns the configuration information for the Extended Peripherals
\r
822 * clocks(SAI1, SAI2, LPTIM1, LPTIM2, I2C1, I2C2, I2C3, I2C4, LPUART,
\r
823 * USART1, USART2, USART3, UART4, UART5, RTC, ADCx, DFSDMx, SWPMI1, USB, SDMMC1 and RNG).
\r
826 void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
\r
828 /* Set all possible values for the extended clock type parameter------------*/
\r
830 #if defined(STM32L412xx) || defined(STM32L422xx)
\r
832 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | \
\r
833 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | \
\r
834 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_USB | \
\r
835 RCC_PERIPHCLK_RNG | \
\r
836 RCC_PERIPHCLK_RTC ;
\r
838 #elif defined(STM32L431xx)
\r
840 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | \
\r
841 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | \
\r
842 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | \
\r
843 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_SWPMI1 | \
\r
844 RCC_PERIPHCLK_RTC ;
\r
846 #elif defined(STM32L432xx) || defined(STM32L442xx)
\r
848 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | \
\r
849 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C3 | \
\r
850 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_USB | \
\r
851 RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_SWPMI1 | \
\r
852 RCC_PERIPHCLK_RTC ;
\r
854 #elif defined(STM32L433xx) || defined(STM32L443xx)
\r
856 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | \
\r
857 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | \
\r
858 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_USB | \
\r
859 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_SWPMI1 | \
\r
860 RCC_PERIPHCLK_RTC ;
\r
862 #elif defined(STM32L451xx)
\r
864 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | \
\r
865 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_I2C4 | \
\r
866 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | \
\r
867 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_DFSDM1 | \
\r
868 RCC_PERIPHCLK_RTC ;
\r
870 #elif defined(STM32L452xx) || defined(STM32L462xx)
\r
872 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | \
\r
873 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_I2C4 | \
\r
874 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_USB | \
\r
875 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_DFSDM1 | \
\r
876 RCC_PERIPHCLK_RTC ;
\r
878 #elif defined(STM32L471xx)
\r
880 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 | \
\r
881 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | \
\r
882 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 | \
\r
883 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_SWPMI1 | RCC_PERIPHCLK_DFSDM1 | \
\r
884 RCC_PERIPHCLK_RTC ;
\r
886 #elif defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx)
\r
888 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 | \
\r
889 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | \
\r
890 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 | RCC_PERIPHCLK_USB | \
\r
891 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_SWPMI1 | RCC_PERIPHCLK_DFSDM1 | \
\r
892 RCC_PERIPHCLK_RTC ;
\r
894 #elif defined(STM32L496xx) || defined(STM32L4A6xx)
\r
896 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 | \
\r
897 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_I2C4 | \
\r
898 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 | RCC_PERIPHCLK_USB | \
\r
899 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_SWPMI1 | RCC_PERIPHCLK_DFSDM1 | \
\r
900 RCC_PERIPHCLK_RTC ;
\r
902 #elif defined(STM32L4R5xx) || defined(STM32L4S5xx)
\r
904 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 | \
\r
905 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_I2C4 | \
\r
906 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 | RCC_PERIPHCLK_USB | \
\r
907 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_DFSDM1 | \
\r
908 RCC_PERIPHCLK_DFSDM1AUDIO | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_OSPI;
\r
910 #elif defined(STM32L4R7xx) || defined(STM32L4S7xx)
\r
912 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 | \
\r
913 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_I2C4 | \
\r
914 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 | RCC_PERIPHCLK_USB | \
\r
915 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_DFSDM1 | \
\r
916 RCC_PERIPHCLK_DFSDM1AUDIO | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_OSPI | RCC_PERIPHCLK_LTDC;
\r
918 #elif defined(STM32L4R9xx) || defined(STM32L4S9xx)
\r
920 PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 | \
\r
921 RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_I2C4 | \
\r
922 RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 | RCC_PERIPHCLK_USB | \
\r
923 RCC_PERIPHCLK_SDMMC1 | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_DFSDM1 | \
\r
924 RCC_PERIPHCLK_DFSDM1AUDIO | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_OSPI | RCC_PERIPHCLK_LTDC | RCC_PERIPHCLK_DSI;
\r
926 #endif /* STM32L431xx */
\r
928 #if defined(RCC_PLLSAI1_SUPPORT)
\r
930 /* Get the PLLSAI1 Clock configuration -----------------------------------------------*/
\r
932 PeriphClkInit->PLLSAI1.PLLSAI1Source = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC) >> RCC_PLLCFGR_PLLSRC_Pos;
\r
933 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
934 PeriphClkInit->PLLSAI1.PLLSAI1M = (READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U;
\r
936 PeriphClkInit->PLLSAI1.PLLSAI1M = (READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U;
\r
937 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
\r
938 PeriphClkInit->PLLSAI1.PLLSAI1N = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
\r
939 PeriphClkInit->PLLSAI1.PLLSAI1P = ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1P) >> RCC_PLLSAI1CFGR_PLLSAI1P_Pos) << 4U) + 7U;
\r
940 PeriphClkInit->PLLSAI1.PLLSAI1Q = ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1Q) >> RCC_PLLSAI1CFGR_PLLSAI1Q_Pos) + 1U) * 2U;
\r
941 PeriphClkInit->PLLSAI1.PLLSAI1R = ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1R) >> RCC_PLLSAI1CFGR_PLLSAI1R_Pos) + 1U) * 2U;
\r
943 #endif /* RCC_PLLSAI1_SUPPORT */
\r
945 #if defined(RCC_PLLSAI2_SUPPORT)
\r
947 /* Get the PLLSAI2 Clock configuration -----------------------------------------------*/
\r
949 PeriphClkInit->PLLSAI2.PLLSAI2Source = PeriphClkInit->PLLSAI1.PLLSAI1Source;
\r
950 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
951 PeriphClkInit->PLLSAI2.PLLSAI2M = (READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2M) >> RCC_PLLSAI2CFGR_PLLSAI2M_Pos) + 1U;
\r
953 PeriphClkInit->PLLSAI2.PLLSAI2M = PeriphClkInit->PLLSAI1.PLLSAI1M;
\r
954 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT */
\r
955 PeriphClkInit->PLLSAI2.PLLSAI2N = READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2N) >> RCC_PLLSAI2CFGR_PLLSAI2N_Pos;
\r
956 PeriphClkInit->PLLSAI2.PLLSAI2P = ((READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2P) >> RCC_PLLSAI2CFGR_PLLSAI2P_Pos) << 4U) + 7U;
\r
957 #if defined(RCC_PLLSAI2Q_DIV_SUPPORT)
\r
958 PeriphClkInit->PLLSAI2.PLLSAI2Q = ((READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2Q) >> RCC_PLLSAI2CFGR_PLLSAI2Q_Pos) + 1U) * 2U;
\r
959 #endif /* RCC_PLLSAI2Q_DIV_SUPPORT */
\r
960 PeriphClkInit->PLLSAI2.PLLSAI2R = ((READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2R)>> RCC_PLLSAI2CFGR_PLLSAI2R_Pos) + 1U) * 2U;
\r
962 #endif /* RCC_PLLSAI2_SUPPORT */
\r
964 /* Get the USART1 clock source ---------------------------------------------*/
\r
965 PeriphClkInit->Usart1ClockSelection = __HAL_RCC_GET_USART1_SOURCE();
\r
966 /* Get the USART2 clock source ---------------------------------------------*/
\r
967 PeriphClkInit->Usart2ClockSelection = __HAL_RCC_GET_USART2_SOURCE();
\r
969 #if defined(USART3)
\r
970 /* Get the USART3 clock source ---------------------------------------------*/
\r
971 PeriphClkInit->Usart3ClockSelection = __HAL_RCC_GET_USART3_SOURCE();
\r
972 #endif /* USART3 */
\r
975 /* Get the UART4 clock source ----------------------------------------------*/
\r
976 PeriphClkInit->Uart4ClockSelection = __HAL_RCC_GET_UART4_SOURCE();
\r
980 /* Get the UART5 clock source ----------------------------------------------*/
\r
981 PeriphClkInit->Uart5ClockSelection = __HAL_RCC_GET_UART5_SOURCE();
\r
984 /* Get the LPUART1 clock source --------------------------------------------*/
\r
985 PeriphClkInit->Lpuart1ClockSelection = __HAL_RCC_GET_LPUART1_SOURCE();
\r
987 /* Get the I2C1 clock source -----------------------------------------------*/
\r
988 PeriphClkInit->I2c1ClockSelection = __HAL_RCC_GET_I2C1_SOURCE();
\r
991 /* Get the I2C2 clock source ----------------------------------------------*/
\r
992 PeriphClkInit->I2c2ClockSelection = __HAL_RCC_GET_I2C2_SOURCE();
\r
995 /* Get the I2C3 clock source -----------------------------------------------*/
\r
996 PeriphClkInit->I2c3ClockSelection = __HAL_RCC_GET_I2C3_SOURCE();
\r
999 /* Get the I2C4 clock source -----------------------------------------------*/
\r
1000 PeriphClkInit->I2c4ClockSelection = __HAL_RCC_GET_I2C4_SOURCE();
\r
1003 /* Get the LPTIM1 clock source ---------------------------------------------*/
\r
1004 PeriphClkInit->Lptim1ClockSelection = __HAL_RCC_GET_LPTIM1_SOURCE();
\r
1006 /* Get the LPTIM2 clock source ---------------------------------------------*/
\r
1007 PeriphClkInit->Lptim2ClockSelection = __HAL_RCC_GET_LPTIM2_SOURCE();
\r
1010 /* Get the SAI1 clock source -----------------------------------------------*/
\r
1011 PeriphClkInit->Sai1ClockSelection = __HAL_RCC_GET_SAI1_SOURCE();
\r
1015 /* Get the SAI2 clock source -----------------------------------------------*/
\r
1016 PeriphClkInit->Sai2ClockSelection = __HAL_RCC_GET_SAI2_SOURCE();
\r
1019 /* Get the RTC clock source ------------------------------------------------*/
\r
1020 PeriphClkInit->RTCClockSelection = __HAL_RCC_GET_RTC_SOURCE();
\r
1022 #if defined(USB_OTG_FS) || defined(USB)
\r
1023 /* Get the USB clock source ------------------------------------------------*/
\r
1024 PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
\r
1025 #endif /* USB_OTG_FS || USB */
\r
1027 #if defined(SDMMC1)
\r
1028 /* Get the SDMMC1 clock source ---------------------------------------------*/
\r
1029 PeriphClkInit->Sdmmc1ClockSelection = __HAL_RCC_GET_SDMMC1_SOURCE();
\r
1030 #endif /* SDMMC1 */
\r
1032 /* Get the RNG clock source ------------------------------------------------*/
\r
1033 PeriphClkInit->RngClockSelection = __HAL_RCC_GET_RNG_SOURCE();
\r
1035 #if !defined(STM32L412xx) && !defined(STM32L422xx)
\r
1036 /* Get the ADC clock source ------------------------------------------------*/
\r
1037 PeriphClkInit->AdcClockSelection = __HAL_RCC_GET_ADC_SOURCE();
\r
1038 #endif /* !STM32L412xx && !STM32L422xx */
\r
1040 #if defined(SWPMI1)
\r
1041 /* Get the SWPMI1 clock source ---------------------------------------------*/
\r
1042 PeriphClkInit->Swpmi1ClockSelection = __HAL_RCC_GET_SWPMI1_SOURCE();
\r
1043 #endif /* SWPMI1 */
\r
1045 #if defined(DFSDM1_Filter0)
\r
1046 /* Get the DFSDM1 clock source ---------------------------------------------*/
\r
1047 PeriphClkInit->Dfsdm1ClockSelection = __HAL_RCC_GET_DFSDM1_SOURCE();
\r
1049 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
1050 /* Get the DFSDM1 audio clock source ---------------------------------------*/
\r
1051 PeriphClkInit->Dfsdm1AudioClockSelection = __HAL_RCC_GET_DFSDM1AUDIO_SOURCE();
\r
1052 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
1053 #endif /* DFSDM1_Filter0 */
\r
1056 /* Get the LTDC clock source -----------------------------------------------*/
\r
1057 PeriphClkInit->LtdcClockSelection = __HAL_RCC_GET_LTDC_SOURCE();
\r
1061 /* Get the DSI clock source ------------------------------------------------*/
\r
1062 PeriphClkInit->DsiClockSelection = __HAL_RCC_GET_DSI_SOURCE();
\r
1065 #if defined(OCTOSPI1) || defined(OCTOSPI2)
\r
1066 /* Get the OctoSPIclock source --------------------------------------------*/
\r
1067 PeriphClkInit->OspiClockSelection = __HAL_RCC_GET_OSPI_SOURCE();
\r
1068 #endif /* OCTOSPI1 || OCTOSPI2 */
\r
1072 * @brief Return the peripheral clock frequency for peripherals with clock source from PLLSAIs
\r
1073 * @note Return 0 if peripheral clock identifier not managed by this API
\r
1074 * @param PeriphClk Peripheral clock identifier
\r
1075 * This parameter can be one of the following values:
\r
1076 * @arg @ref RCC_PERIPHCLK_RTC RTC peripheral clock
\r
1077 * @arg @ref RCC_PERIPHCLK_ADC ADC peripheral clock
\r
1079 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral clock (only for devices with DFSDM)
\r
1082 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral clock (only for devices with DFSDM)
\r
1085 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral clock (only for devices with DFSDM)
\r
1087 * @arg @ref RCC_PERIPHCLK_I2C1 I2C1 peripheral clock
\r
1088 * @arg @ref RCC_PERIPHCLK_I2C2 I2C2 peripheral clock
\r
1089 * @arg @ref RCC_PERIPHCLK_I2C3 I2C3 peripheral clock
\r
1091 * @arg @ref RCC_PERIPHCLK_I2C4 I2C4 peripheral clock (only for devices with I2C4)
\r
1094 * @arg @ref RCC_PERIPHCLK_I2C4 I2C4 peripheral clock (only for devices with I2C4)
\r
1097 * @arg @ref RCC_PERIPHCLK_I2C4 I2C4 peripheral clock (only for devices with I2C4)
\r
1099 * @arg @ref RCC_PERIPHCLK_LPTIM1 LPTIM1 peripheral clock
\r
1100 * @arg @ref RCC_PERIPHCLK_LPTIM2 LPTIM2 peripheral clock
\r
1101 * @arg @ref RCC_PERIPHCLK_LPUART1 LPUART1 peripheral clock
\r
1102 * @arg @ref RCC_PERIPHCLK_RNG RNG peripheral clock
\r
1103 * @arg @ref RCC_PERIPHCLK_SAI1 SAI1 peripheral clock (only for devices with SAI1)
\r
1105 * @arg @ref RCC_PERIPHCLK_SAI2 SAI2 peripheral clock (only for devices with SAI2)
\r
1108 * @arg @ref RCC_PERIPHCLK_SAI2 SAI2 peripheral clock (only for devices with SAI2)
\r
1111 * @arg @ref RCC_PERIPHCLK_SAI2 SAI2 peripheral clock (only for devices with SAI2)
\r
1113 * @arg @ref RCC_PERIPHCLK_SDMMC1 SDMMC1 peripheral clock
\r
1115 * @arg @ref RCC_PERIPHCLK_SWPMI1 SWPMI1 peripheral clock (only for devices with SWPMI1)
\r
1118 * @arg @ref RCC_PERIPHCLK_SWPMI1 SWPMI1 peripheral clock (only for devices with SWPMI1)
\r
1121 * @arg @ref RCC_PERIPHCLK_SWPMI1 SWPMI1 peripheral clock (only for devices with SWPMI1)
\r
1123 * @arg @ref RCC_PERIPHCLK_USART1 USART1 peripheral clock
\r
1124 * @arg @ref RCC_PERIPHCLK_USART2 USART1 peripheral clock
\r
1125 * @arg @ref RCC_PERIPHCLK_USART3 USART1 peripheral clock
\r
1127 * @arg @ref RCC_PERIPHCLK_UART4 UART4 peripheral clock (only for devices with UART4)
\r
1128 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock (only for devices with USB)
\r
1131 * @arg @ref RCC_PERIPHCLK_UART4 UART4 peripheral clock (only for devices with UART4)
\r
1132 * @arg @ref RCC_PERIPHCLK_UART5 UART5 peripheral clock (only for devices with UART5)
\r
1133 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock (only for devices with USB)
\r
1136 * @arg @ref RCC_PERIPHCLK_UART4 UART4 peripheral clock (only for devices with UART4)
\r
1137 * @arg @ref RCC_PERIPHCLK_UART5 UART5 peripheral clock (only for devices with UART5)
\r
1138 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock (only for devices with USB)
\r
1141 * @arg @ref RCC_PERIPHCLK_UART4 USART1 peripheral clock (only for devices with UART4)
\r
1142 * @arg @ref RCC_PERIPHCLK_UART5 USART1 peripheral clock (only for devices with UART5)
\r
1143 * @arg @ref RCC_PERIPHCLK_USB USB peripheral clock (only for devices with USB)
\r
1144 * @arg @ref RCC_PERIPHCLK_DFSDM1 DFSDM1 peripheral kernel clock (only for devices with DFSDM1)
\r
1145 * @arg @ref RCC_PERIPHCLK_DFSDM1AUDIO DFSDM1 peripheral audio clock (only for devices with DFSDM1)
\r
1146 * @arg @ref RCC_PERIPHCLK_LTDC LTDC peripheral clock (only for devices with LTDC)
\r
1147 * @arg @ref RCC_PERIPHCLK_DSI DSI peripheral clock (only for devices with DSI)
\r
1148 * @arg @ref RCC_PERIPHCLK_OSPI OctoSPI peripheral clock (only for devices with OctoSPI)
\r
1150 * @retval Frequency in Hz
\r
1152 uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
\r
1154 uint32_t frequency = 0U;
\r
1155 uint32_t srcclk, pll_oscsource, pllvco, plln; /* no init needed */
\r
1156 #if defined(SDMMC1) && defined(RCC_CCIPR2_SDMMCSEL)
\r
1157 uint32_t pllp; /* no init needed */
\r
1160 /* Check the parameters */
\r
1161 assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
\r
1163 if(PeriphClk == RCC_PERIPHCLK_RTC)
\r
1165 /* Get the current RTC source */
\r
1166 srcclk = __HAL_RCC_GET_RTC_SOURCE();
\r
1170 case RCC_RTCCLKSOURCE_LSE:
\r
1171 /* Check if LSE is ready */
\r
1172 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1174 frequency = LSE_VALUE;
\r
1177 case RCC_RTCCLKSOURCE_LSI:
\r
1178 /* Check if LSI is ready */
\r
1179 if(HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY))
\r
1181 #if defined(RCC_CSR_LSIPREDIV)
\r
1182 if(HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIPREDIV))
\r
1184 frequency = LSI_VALUE/128U;
\r
1187 #endif /* RCC_CSR_LSIPREDIV */
\r
1189 frequency = LSI_VALUE;
\r
1193 case RCC_RTCCLKSOURCE_HSE_DIV32:
\r
1194 /* Check if HSE is ready */
\r
1195 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
\r
1197 frequency = HSE_VALUE / 32U;
\r
1201 /* No clock source, frequency default init at 0 */
\r
1207 /* Other external peripheral clock source than RTC */
\r
1208 pll_oscsource = __HAL_RCC_GET_PLL_OSCSOURCE();
\r
1210 /* Compute PLL clock input */
\r
1211 switch(pll_oscsource)
\r
1213 case RCC_PLLSOURCE_MSI: /* MSI ? */
\r
1214 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_MSIRDY))
\r
1216 /*MSI frequency range in HZ*/
\r
1217 pllvco = MSIRangeTable[(__HAL_RCC_GET_MSI_RANGE() >> 4U)];
\r
1224 case RCC_PLLSOURCE_HSI: /* HSI ? */
\r
1225 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1227 pllvco = HSI_VALUE;
\r
1234 case RCC_PLLSOURCE_HSE: /* HSE ? */
\r
1235 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
\r
1237 pllvco = HSE_VALUE;
\r
1254 case RCC_PERIPHCLK_SAI1:
\r
1255 frequency = RCCEx_GetSAIxPeriphCLKFreq(RCC_PERIPHCLK_SAI1, pllvco);
\r
1262 case RCC_PERIPHCLK_SAI2:
\r
1263 frequency = RCCEx_GetSAIxPeriphCLKFreq(RCC_PERIPHCLK_SAI2, pllvco);
\r
1268 #if defined(USB_OTG_FS) || defined(USB)
\r
1270 case RCC_PERIPHCLK_USB:
\r
1272 #endif /* USB_OTG_FS || USB */
\r
1274 case RCC_PERIPHCLK_RNG:
\r
1276 #if defined(SDMMC1) && !defined(RCC_CCIPR2_SDMMCSEL)
\r
1278 case RCC_PERIPHCLK_SDMMC1:
\r
1280 #endif /* SDMMC1 && !RCC_CCIPR2_SDMMCSEL */
\r
1282 srcclk = READ_BIT(RCC->CCIPR, RCC_CCIPR_CLK48SEL);
\r
1286 case RCC_CCIPR_CLK48SEL: /* MSI ? */
\r
1287 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_MSIRDY))
\r
1289 /*MSI frequency range in HZ*/
\r
1290 frequency = MSIRangeTable[(__HAL_RCC_GET_MSI_RANGE() >> 4U)];
\r
1293 case RCC_CCIPR_CLK48SEL_1: /* PLL ? */
\r
1294 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLRDY))
\r
1296 if(HAL_IS_BIT_SET(RCC->PLLCFGR, RCC_PLLCFGR_PLLQEN))
\r
1298 /* f(PLL Source) * PLLN / PLLM */
\r
1299 plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
\r
1300 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
1301 /* f(PLL48M1CLK) = f(VCO input) / PLLQ */
\r
1302 frequency = (pllvco / (((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos) + 1U) << 1U));
\r
1306 #if defined(RCC_PLLSAI1_SUPPORT)
\r
1307 case RCC_CCIPR_CLK48SEL_0: /* PLLSAI1 ? */
\r
1308 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLSAI1RDY))
\r
1310 if(HAL_IS_BIT_SET(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1QEN))
\r
1312 plln = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
\r
1313 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
1314 /* PLLSAI1M exists: apply PLLSAI1M divider for PLLSAI1 output computation */
\r
1315 /* f(PLLSAI1 Source) * PLLSAI1N / PLLSAI1M */
\r
1316 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U));
\r
1318 /* f(PLL Source) * PLLSAI1N / PLLM */
\r
1319 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
1321 /* f(PLL48M2CLK) = f(VCOSAI1 input) / PLLSAI1Q */
\r
1322 frequency = (pllvco / (((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1Q) >> RCC_PLLSAI1CFGR_PLLSAI1Q_Pos) + 1U) << 1U));
\r
1326 #endif /* RCC_PLLSAI1_SUPPORT */
\r
1327 #if defined(RCC_HSI48_SUPPORT)
\r
1329 if(HAL_IS_BIT_SET(RCC->CRRCR, RCC_CRRCR_HSI48RDY)) /* HSI48 ? */
\r
1331 frequency = HSI48_VALUE;
\r
1334 #endif /* RCC_HSI48_SUPPORT */
\r
1336 /* No clock source, frequency default init at 0 */
\r
1338 } /* switch(srcclk) */
\r
1342 #if defined(SDMMC1) && defined(RCC_CCIPR2_SDMMCSEL)
\r
1344 case RCC_PERIPHCLK_SDMMC1:
\r
1346 if(HAL_IS_BIT_SET(RCC->CCIPR2, RCC_CCIPR2_SDMMCSEL)) /* PLL "P" ? */
\r
1348 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLRDY))
\r
1350 if(HAL_IS_BIT_SET(RCC->PLLCFGR, RCC_PLLCFGR_PLLPEN))
\r
1352 /* f(PLL Source) * PLLN / PLLM */
\r
1353 plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
\r
1354 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
1355 /* f(PLLSAI3CLK) = f(VCO input) / PLLP */
\r
1356 pllp = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLPDIV) >> RCC_PLLCFGR_PLLPDIV_Pos;
\r
1359 if(READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) != 0U)
\r
1368 frequency = (pllvco / pllp);
\r
1372 else /* 48MHz from PLL "Q" or MSI or PLLSAI1Q or HSI48 */
\r
1374 srcclk = READ_BIT(RCC->CCIPR, RCC_CCIPR_CLK48SEL);
\r
1378 case RCC_CCIPR_CLK48SEL: /* MSI ? */
\r
1379 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_MSIRDY))
\r
1381 /*MSI frequency range in HZ*/
\r
1382 frequency = MSIRangeTable[(__HAL_RCC_GET_MSI_RANGE() >> 4U)];
\r
1385 case RCC_CCIPR_CLK48SEL_1: /* PLL "Q" ? */
\r
1386 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLRDY))
\r
1388 if(HAL_IS_BIT_SET(RCC->PLLCFGR, RCC_PLLCFGR_PLLQEN))
\r
1390 /* f(PLL Source) * PLLN / PLLM */
\r
1391 plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
\r
1392 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
1393 /* f(PLL48M1CLK) = f(VCO input) / PLLQ */
\r
1394 frequency = (pllvco / (((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos) + 1U) << 1U));
\r
1398 case RCC_CCIPR_CLK48SEL_0: /* PLLSAI1 ? */
\r
1399 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLSAI1RDY))
\r
1401 if(HAL_IS_BIT_SET(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1QEN))
\r
1403 /* f(PLLSAI1 Source) * PLLSAI1N / PLLSAI1M */
\r
1404 plln = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
\r
1405 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U));
\r
1406 /* f(PLL48M2CLK) = f(VCOSAI1 input) / PLLSAI1Q */
\r
1407 frequency = (pllvco / (((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1Q) >> RCC_PLLSAI1CFGR_PLLSAI1Q_Pos) + 1U) << 1U));
\r
1412 if(HAL_IS_BIT_SET(RCC->CRRCR, RCC_CRRCR_HSI48RDY)) /* HSI48 ? */
\r
1414 frequency = HSI48_VALUE;
\r
1418 /* No clock source, frequency default init at 0 */
\r
1420 } /* switch(srcclk) */
\r
1424 #endif /* SDMMC1 && RCC_CCIPR2_SDMMCSEL */
\r
1426 case RCC_PERIPHCLK_USART1:
\r
1428 /* Get the current USART1 source */
\r
1429 srcclk = __HAL_RCC_GET_USART1_SOURCE();
\r
1433 case RCC_USART1CLKSOURCE_PCLK2:
\r
1434 frequency = HAL_RCC_GetPCLK2Freq();
\r
1436 case RCC_USART1CLKSOURCE_SYSCLK:
\r
1437 frequency = HAL_RCC_GetSysClockFreq();
\r
1439 case RCC_USART1CLKSOURCE_HSI:
\r
1440 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1442 frequency = HSI_VALUE;
\r
1445 case RCC_USART1CLKSOURCE_LSE:
\r
1446 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1448 frequency = LSE_VALUE;
\r
1452 /* No clock source, frequency default init at 0 */
\r
1459 case RCC_PERIPHCLK_USART2:
\r
1461 /* Get the current USART2 source */
\r
1462 srcclk = __HAL_RCC_GET_USART2_SOURCE();
\r
1466 case RCC_USART2CLKSOURCE_PCLK1:
\r
1467 frequency = HAL_RCC_GetPCLK1Freq();
\r
1469 case RCC_USART2CLKSOURCE_SYSCLK:
\r
1470 frequency = HAL_RCC_GetSysClockFreq();
\r
1472 case RCC_USART2CLKSOURCE_HSI:
\r
1473 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1475 frequency = HSI_VALUE;
\r
1478 case RCC_USART2CLKSOURCE_LSE:
\r
1479 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1481 frequency = LSE_VALUE;
\r
1485 /* No clock source, frequency default init at 0 */
\r
1492 #if defined(USART3)
\r
1494 case RCC_PERIPHCLK_USART3:
\r
1496 /* Get the current USART3 source */
\r
1497 srcclk = __HAL_RCC_GET_USART3_SOURCE();
\r
1501 case RCC_USART3CLKSOURCE_PCLK1:
\r
1502 frequency = HAL_RCC_GetPCLK1Freq();
\r
1504 case RCC_USART3CLKSOURCE_SYSCLK:
\r
1505 frequency = HAL_RCC_GetSysClockFreq();
\r
1507 case RCC_USART3CLKSOURCE_HSI:
\r
1508 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1510 frequency = HSI_VALUE;
\r
1513 case RCC_USART3CLKSOURCE_LSE:
\r
1514 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1516 frequency = LSE_VALUE;
\r
1520 /* No clock source, frequency default init at 0 */
\r
1527 #endif /* USART3 */
\r
1529 #if defined(UART4)
\r
1531 case RCC_PERIPHCLK_UART4:
\r
1533 /* Get the current UART4 source */
\r
1534 srcclk = __HAL_RCC_GET_UART4_SOURCE();
\r
1538 case RCC_UART4CLKSOURCE_PCLK1:
\r
1539 frequency = HAL_RCC_GetPCLK1Freq();
\r
1541 case RCC_UART4CLKSOURCE_SYSCLK:
\r
1542 frequency = HAL_RCC_GetSysClockFreq();
\r
1544 case RCC_UART4CLKSOURCE_HSI:
\r
1545 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1547 frequency = HSI_VALUE;
\r
1550 case RCC_UART4CLKSOURCE_LSE:
\r
1551 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1553 frequency = LSE_VALUE;
\r
1557 /* No clock source, frequency default init at 0 */
\r
1564 #endif /* UART4 */
\r
1566 #if defined(UART5)
\r
1568 case RCC_PERIPHCLK_UART5:
\r
1570 /* Get the current UART5 source */
\r
1571 srcclk = __HAL_RCC_GET_UART5_SOURCE();
\r
1575 case RCC_UART5CLKSOURCE_PCLK1:
\r
1576 frequency = HAL_RCC_GetPCLK1Freq();
\r
1578 case RCC_UART5CLKSOURCE_SYSCLK:
\r
1579 frequency = HAL_RCC_GetSysClockFreq();
\r
1581 case RCC_UART5CLKSOURCE_HSI:
\r
1582 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1584 frequency = HSI_VALUE;
\r
1587 case RCC_UART5CLKSOURCE_LSE:
\r
1588 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1590 frequency = LSE_VALUE;
\r
1594 /* No clock source, frequency default init at 0 */
\r
1601 #endif /* UART5 */
\r
1603 case RCC_PERIPHCLK_LPUART1:
\r
1605 /* Get the current LPUART1 source */
\r
1606 srcclk = __HAL_RCC_GET_LPUART1_SOURCE();
\r
1610 case RCC_LPUART1CLKSOURCE_PCLK1:
\r
1611 frequency = HAL_RCC_GetPCLK1Freq();
\r
1613 case RCC_LPUART1CLKSOURCE_SYSCLK:
\r
1614 frequency = HAL_RCC_GetSysClockFreq();
\r
1616 case RCC_LPUART1CLKSOURCE_HSI:
\r
1617 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1619 frequency = HSI_VALUE;
\r
1622 case RCC_LPUART1CLKSOURCE_LSE:
\r
1623 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1625 frequency = LSE_VALUE;
\r
1629 /* No clock source, frequency default init at 0 */
\r
1636 case RCC_PERIPHCLK_ADC:
\r
1638 srcclk = __HAL_RCC_GET_ADC_SOURCE();
\r
1642 case RCC_ADCCLKSOURCE_SYSCLK:
\r
1643 frequency = HAL_RCC_GetSysClockFreq();
\r
1645 #if defined(RCC_PLLSAI1_SUPPORT)
\r
1646 case RCC_ADCCLKSOURCE_PLLSAI1:
\r
1647 if(__HAL_RCC_GET_PLLSAI1CLKOUT_CONFIG(RCC_PLLSAI1_ADC1CLK) != 0U)
\r
1649 plln = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
\r
1650 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
1651 /* PLLSAI1M exists: apply PLLSAI1M divider for PLLSAI1 output computation */
\r
1652 /* f(PLLSAI1 Source) * PLLSAI1N / PLLSAI1M */
\r
1653 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U));
\r
1655 /* f(PLL Source) * PLLSAI1N / PLLM */
\r
1656 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
1658 /* f(PLLADC1CLK) = f(VCOSAI1 input) / PLLSAI1R */
\r
1659 frequency = (pllvco / (((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1R) >> RCC_PLLSAI1CFGR_PLLSAI1R_Pos) + 1U) << 1U));
\r
1662 #endif /* RCC_PLLSAI1_SUPPORT */
\r
1663 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
\r
1664 case RCC_ADCCLKSOURCE_PLLSAI2:
\r
1665 if(__HAL_RCC_GET_PLLSAI2CLKOUT_CONFIG(RCC_PLLSAI2_ADC2CLK) != 0U)
\r
1667 plln = READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2N) >> RCC_PLLSAI2CFGR_PLLSAI2N_Pos;
\r
1668 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
1669 /* PLLSAI2M exists: apply PLLSAI2M divider for PLLSAI2 output computation */
\r
1670 /* f(PLLSAI2 Source) * PLLSAI2N / PLLSAI2M */
\r
1671 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2M) >> RCC_PLLSAI2CFGR_PLLSAI2M_Pos) + 1U));
\r
1673 /* f(PLL Source) * PLLSAI2N / PLLM */
\r
1674 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
1676 /* f(PLLADC2CLK) = f(VCOSAI2 input) / PLLSAI2R */
\r
1677 frequency = (pllvco / (((READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2R) >> RCC_PLLSAI2CFGR_PLLSAI2R_Pos) + 1U) << 1U));
\r
1680 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || STM32L496xx || STM32L4A6xx */
\r
1682 /* No clock source, frequency default init at 0 */
\r
1689 #if defined(DFSDM1_Filter0)
\r
1691 case RCC_PERIPHCLK_DFSDM1:
\r
1693 /* Get the current DFSDM1 source */
\r
1694 srcclk = __HAL_RCC_GET_DFSDM1_SOURCE();
\r
1696 if(srcclk == RCC_DFSDM1CLKSOURCE_PCLK2)
\r
1698 frequency = HAL_RCC_GetPCLK2Freq();
\r
1702 frequency = HAL_RCC_GetSysClockFreq();
\r
1708 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
1710 case RCC_PERIPHCLK_DFSDM1AUDIO:
\r
1712 /* Get the current DFSDM1 audio source */
\r
1713 srcclk = __HAL_RCC_GET_DFSDM1AUDIO_SOURCE();
\r
1717 case RCC_DFSDM1AUDIOCLKSOURCE_SAI1:
\r
1718 frequency = RCCEx_GetSAIxPeriphCLKFreq(RCC_PERIPHCLK_SAI1, pllvco);
\r
1720 case RCC_DFSDM1AUDIOCLKSOURCE_MSI:
\r
1721 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_MSIRDY))
\r
1723 /*MSI frequency range in HZ*/
\r
1724 frequency = MSIRangeTable[(__HAL_RCC_GET_MSI_RANGE() >> 4U)];
\r
1727 case RCC_DFSDM1AUDIOCLKSOURCE_HSI:
\r
1728 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1730 frequency = HSI_VALUE;
\r
1734 /* No clock source, frequency default init at 0 */
\r
1741 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
1743 #endif /* DFSDM1_Filter0 */
\r
1745 case RCC_PERIPHCLK_I2C1:
\r
1747 /* Get the current I2C1 source */
\r
1748 srcclk = __HAL_RCC_GET_I2C1_SOURCE();
\r
1752 case RCC_I2C1CLKSOURCE_PCLK1:
\r
1753 frequency = HAL_RCC_GetPCLK1Freq();
\r
1755 case RCC_I2C1CLKSOURCE_SYSCLK:
\r
1756 frequency = HAL_RCC_GetSysClockFreq();
\r
1758 case RCC_I2C1CLKSOURCE_HSI:
\r
1759 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1761 frequency = HSI_VALUE;
\r
1765 /* No clock source, frequency default init at 0 */
\r
1774 case RCC_PERIPHCLK_I2C2:
\r
1776 /* Get the current I2C2 source */
\r
1777 srcclk = __HAL_RCC_GET_I2C2_SOURCE();
\r
1781 case RCC_I2C2CLKSOURCE_PCLK1:
\r
1782 frequency = HAL_RCC_GetPCLK1Freq();
\r
1784 case RCC_I2C2CLKSOURCE_SYSCLK:
\r
1785 frequency = HAL_RCC_GetSysClockFreq();
\r
1787 case RCC_I2C2CLKSOURCE_HSI:
\r
1788 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1790 frequency = HSI_VALUE;
\r
1794 /* No clock source, frequency default init at 0 */
\r
1803 case RCC_PERIPHCLK_I2C3:
\r
1805 /* Get the current I2C3 source */
\r
1806 srcclk = __HAL_RCC_GET_I2C3_SOURCE();
\r
1810 case RCC_I2C3CLKSOURCE_PCLK1:
\r
1811 frequency = HAL_RCC_GetPCLK1Freq();
\r
1813 case RCC_I2C3CLKSOURCE_SYSCLK:
\r
1814 frequency = HAL_RCC_GetSysClockFreq();
\r
1816 case RCC_I2C3CLKSOURCE_HSI:
\r
1817 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1819 frequency = HSI_VALUE;
\r
1823 /* No clock source, frequency default init at 0 */
\r
1832 case RCC_PERIPHCLK_I2C4:
\r
1834 /* Get the current I2C4 source */
\r
1835 srcclk = __HAL_RCC_GET_I2C4_SOURCE();
\r
1839 case RCC_I2C4CLKSOURCE_PCLK1:
\r
1840 frequency = HAL_RCC_GetPCLK1Freq();
\r
1842 case RCC_I2C4CLKSOURCE_SYSCLK:
\r
1843 frequency = HAL_RCC_GetSysClockFreq();
\r
1845 case RCC_I2C4CLKSOURCE_HSI:
\r
1846 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1848 frequency = HSI_VALUE;
\r
1852 /* No clock source, frequency default init at 0 */
\r
1861 case RCC_PERIPHCLK_LPTIM1:
\r
1863 /* Get the current LPTIM1 source */
\r
1864 srcclk = __HAL_RCC_GET_LPTIM1_SOURCE();
\r
1868 case RCC_LPTIM1CLKSOURCE_PCLK1:
\r
1869 frequency = HAL_RCC_GetPCLK1Freq();
\r
1871 case RCC_LPTIM1CLKSOURCE_LSI:
\r
1872 if(HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY))
\r
1874 #if defined(RCC_CSR_LSIPREDIV)
\r
1875 if(HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIPREDIV))
\r
1877 frequency = LSI_VALUE/128U;
\r
1880 #endif /* RCC_CSR_LSIPREDIV */
\r
1882 frequency = LSI_VALUE;
\r
1886 case RCC_LPTIM1CLKSOURCE_HSI:
\r
1887 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1889 frequency = HSI_VALUE;
\r
1892 case RCC_LPTIM1CLKSOURCE_LSE:
\r
1893 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1895 frequency = LSE_VALUE;
\r
1899 /* No clock source, frequency default init at 0 */
\r
1906 case RCC_PERIPHCLK_LPTIM2:
\r
1908 /* Get the current LPTIM2 source */
\r
1909 srcclk = __HAL_RCC_GET_LPTIM2_SOURCE();
\r
1913 case RCC_LPTIM2CLKSOURCE_PCLK1:
\r
1914 frequency = HAL_RCC_GetPCLK1Freq();
\r
1916 case RCC_LPTIM2CLKSOURCE_LSI:
\r
1917 if(HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY))
\r
1919 #if defined(RCC_CSR_LSIPREDIV)
\r
1920 if(HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIPREDIV))
\r
1922 frequency = LSI_VALUE/128U;
\r
1925 #endif /* RCC_CSR_LSIPREDIV */
\r
1927 frequency = LSI_VALUE;
\r
1931 case RCC_LPTIM2CLKSOURCE_HSI:
\r
1932 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1934 frequency = HSI_VALUE;
\r
1937 case RCC_LPTIM2CLKSOURCE_LSE:
\r
1938 if(HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSERDY))
\r
1940 frequency = LSE_VALUE;
\r
1944 /* No clock source, frequency default init at 0 */
\r
1951 #if defined(SWPMI1)
\r
1953 case RCC_PERIPHCLK_SWPMI1:
\r
1955 /* Get the current SWPMI1 source */
\r
1956 srcclk = __HAL_RCC_GET_SWPMI1_SOURCE();
\r
1960 case RCC_SWPMI1CLKSOURCE_PCLK1:
\r
1961 frequency = HAL_RCC_GetPCLK1Freq();
\r
1963 case RCC_SWPMI1CLKSOURCE_HSI:
\r
1964 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
1966 frequency = HSI_VALUE;
\r
1970 /* No clock source, frequency default init at 0 */
\r
1977 #endif /* SWPMI1 */
\r
1979 #if defined(OCTOSPI1) || defined(OCTOSPI2)
\r
1981 case RCC_PERIPHCLK_OSPI:
\r
1983 /* Get the current OctoSPI clock source */
\r
1984 srcclk = __HAL_RCC_GET_OSPI_SOURCE();
\r
1988 case RCC_OSPICLKSOURCE_SYSCLK:
\r
1989 frequency = HAL_RCC_GetSysClockFreq();
\r
1991 case RCC_OSPICLKSOURCE_MSI:
\r
1992 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_MSIRDY))
\r
1994 /*MSI frequency range in HZ*/
\r
1995 frequency = MSIRangeTable[(__HAL_RCC_GET_MSI_RANGE() >> 4U)];
\r
1998 case RCC_OSPICLKSOURCE_PLL:
\r
1999 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLRDY))
\r
2001 if(HAL_IS_BIT_SET(RCC->PLLCFGR, RCC_PLLCFGR_PLLQEN))
\r
2003 /* f(PLL Source) * PLLN / PLLM */
\r
2004 plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
\r
2005 pllvco = ((pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
2006 /* f(PLL48M1CLK) = f(VCO input) / PLLQ */
\r
2007 frequency = (pllvco / (((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos) + 1U) << 1U));
\r
2012 /* No clock source, frequency default init at 0 */
\r
2019 #endif /* OCTOSPI1 || OCTOSPI2 */
\r
2026 return(frequency);
\r
2033 /** @defgroup RCCEx_Exported_Functions_Group2 Extended Clock management functions
\r
2034 * @brief Extended Clock management functions
\r
2037 ===============================================================================
\r
2038 ##### Extended clock management functions #####
\r
2039 ===============================================================================
\r
2041 This subsection provides a set of functions allowing to control the
\r
2042 activation or deactivation of MSI PLL-mode, PLLSAI1, PLLSAI2, LSE CSS,
\r
2043 Low speed clock output and clock after wake-up from STOP mode.
\r
2048 #if defined(RCC_PLLSAI1_SUPPORT)
\r
2051 * @brief Enable PLLSAI1.
\r
2052 * @param PLLSAI1Init pointer to an RCC_PLLSAI1InitTypeDef structure that
\r
2053 * contains the configuration information for the PLLSAI1
\r
2054 * @retval HAL status
\r
2056 HAL_StatusTypeDef HAL_RCCEx_EnablePLLSAI1(RCC_PLLSAI1InitTypeDef *PLLSAI1Init)
\r
2058 uint32_t tickstart;
\r
2059 HAL_StatusTypeDef status = HAL_OK;
\r
2061 /* check for PLLSAI1 Parameters used to output PLLSAI1CLK */
\r
2062 assert_param(IS_RCC_PLLSAI1SOURCE(PLLSAI1Init->PLLSAI1Source));
\r
2063 assert_param(IS_RCC_PLLSAI1M_VALUE(PLLSAI1Init->PLLSAI1M));
\r
2064 assert_param(IS_RCC_PLLSAI1N_VALUE(PLLSAI1Init->PLLSAI1N));
\r
2065 assert_param(IS_RCC_PLLSAI1P_VALUE(PLLSAI1Init->PLLSAI1P));
\r
2066 assert_param(IS_RCC_PLLSAI1Q_VALUE(PLLSAI1Init->PLLSAI1Q));
\r
2067 assert_param(IS_RCC_PLLSAI1R_VALUE(PLLSAI1Init->PLLSAI1R));
\r
2068 assert_param(IS_RCC_PLLSAI1CLOCKOUT_VALUE(PLLSAI1Init->PLLSAI1ClockOut));
\r
2070 /* Disable the PLLSAI1 */
\r
2071 __HAL_RCC_PLLSAI1_DISABLE();
\r
2073 /* Get Start Tick*/
\r
2074 tickstart = HAL_GetTick();
\r
2076 /* Wait till PLLSAI1 is ready to be updated */
\r
2077 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) != 0U)
\r
2079 if((HAL_GetTick() - tickstart) > PLLSAI1_TIMEOUT_VALUE)
\r
2081 status = HAL_TIMEOUT;
\r
2086 if(status == HAL_OK)
\r
2088 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
2089 /* Configure the PLLSAI1 Multiplication factor N */
\r
2090 /* Configure the PLLSAI1 Division factors M, P, Q and R */
\r
2091 __HAL_RCC_PLLSAI1_CONFIG(PLLSAI1Init->PLLSAI1M, PLLSAI1Init->PLLSAI1N, PLLSAI1Init->PLLSAI1P, PLLSAI1Init->PLLSAI1Q, PLLSAI1Init->PLLSAI1R);
\r
2093 /* Configure the PLLSAI1 Multiplication factor N */
\r
2094 /* Configure the PLLSAI1 Division factors P, Q and R */
\r
2095 __HAL_RCC_PLLSAI1_CONFIG(PLLSAI1Init->PLLSAI1N, PLLSAI1Init->PLLSAI1P, PLLSAI1Init->PLLSAI1Q, PLLSAI1Init->PLLSAI1R);
\r
2096 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
\r
2097 /* Configure the PLLSAI1 Clock output(s) */
\r
2098 __HAL_RCC_PLLSAI1CLKOUT_ENABLE(PLLSAI1Init->PLLSAI1ClockOut);
\r
2100 /* Enable the PLLSAI1 again by setting PLLSAI1ON to 1*/
\r
2101 __HAL_RCC_PLLSAI1_ENABLE();
\r
2103 /* Get Start Tick*/
\r
2104 tickstart = HAL_GetTick();
\r
2106 /* Wait till PLLSAI1 is ready */
\r
2107 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) == 0U)
\r
2109 if((HAL_GetTick() - tickstart) > PLLSAI1_TIMEOUT_VALUE)
\r
2111 status = HAL_TIMEOUT;
\r
2121 * @brief Disable PLLSAI1.
\r
2122 * @retval HAL status
\r
2124 HAL_StatusTypeDef HAL_RCCEx_DisablePLLSAI1(void)
\r
2126 uint32_t tickstart;
\r
2127 HAL_StatusTypeDef status = HAL_OK;
\r
2129 /* Disable the PLLSAI1 */
\r
2130 __HAL_RCC_PLLSAI1_DISABLE();
\r
2132 /* Get Start Tick*/
\r
2133 tickstart = HAL_GetTick();
\r
2135 /* Wait till PLLSAI1 is ready */
\r
2136 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) != 0U)
\r
2138 if((HAL_GetTick() - tickstart) > PLLSAI1_TIMEOUT_VALUE)
\r
2140 status = HAL_TIMEOUT;
\r
2145 /* Disable the PLLSAI1 Clock outputs */
\r
2146 __HAL_RCC_PLLSAI1CLKOUT_DISABLE(RCC_PLLSAI1CFGR_PLLSAI1PEN|RCC_PLLSAI1CFGR_PLLSAI1QEN|RCC_PLLSAI1CFGR_PLLSAI1REN);
\r
2148 /* Reset PLL source to save power if no PLLs on */
\r
2149 #if defined(RCC_PLLSAI2_SUPPORT)
\r
2150 if(READ_BIT(RCC->CR, (RCC_CR_PLLRDY | RCC_CR_PLLSAI2RDY)) == 0U)
\r
2152 MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, RCC_PLLSOURCE_NONE);
\r
2155 if(READ_BIT(RCC->CR, RCC_CR_PLLRDY) == 0U)
\r
2157 MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, RCC_PLLSOURCE_NONE);
\r
2159 #endif /* RCC_PLLSAI2_SUPPORT */
\r
2164 #endif /* RCC_PLLSAI1_SUPPORT */
\r
2166 #if defined(RCC_PLLSAI2_SUPPORT)
\r
2169 * @brief Enable PLLSAI2.
\r
2170 * @param PLLSAI2Init pointer to an RCC_PLLSAI2InitTypeDef structure that
\r
2171 * contains the configuration information for the PLLSAI2
\r
2172 * @retval HAL status
\r
2174 HAL_StatusTypeDef HAL_RCCEx_EnablePLLSAI2(RCC_PLLSAI2InitTypeDef *PLLSAI2Init)
\r
2176 uint32_t tickstart;
\r
2177 HAL_StatusTypeDef status = HAL_OK;
\r
2179 /* check for PLLSAI2 Parameters used to output PLLSAI2CLK */
\r
2180 assert_param(IS_RCC_PLLSAI2SOURCE(PLLSAI2Init->PLLSAI2Source));
\r
2181 assert_param(IS_RCC_PLLSAI2M_VALUE(PLLSAI2Init->PLLSAI2M));
\r
2182 assert_param(IS_RCC_PLLSAI2N_VALUE(PLLSAI2Init->PLLSAI2N));
\r
2183 assert_param(IS_RCC_PLLSAI2P_VALUE(PLLSAI2Init->PLLSAI2P));
\r
2184 #if defined(RCC_PLLSAI2Q_DIV_SUPPORT)
\r
2185 assert_param(IS_RCC_PLLSAI2Q_VALUE(PLLSAI2Init->PLLSAI2Q));
\r
2186 #endif /* RCC_PLLSAI2Q_DIV_SUPPORT */
\r
2187 assert_param(IS_RCC_PLLSAI2R_VALUE(PLLSAI2Init->PLLSAI2R));
\r
2188 assert_param(IS_RCC_PLLSAI2CLOCKOUT_VALUE(PLLSAI2Init->PLLSAI2ClockOut));
\r
2190 /* Disable the PLLSAI2 */
\r
2191 __HAL_RCC_PLLSAI2_DISABLE();
\r
2193 /* Get Start Tick*/
\r
2194 tickstart = HAL_GetTick();
\r
2196 /* Wait till PLLSAI2 is ready to be updated */
\r
2197 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) != 0U)
\r
2199 if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
\r
2201 status = HAL_TIMEOUT;
\r
2206 if(status == HAL_OK)
\r
2208 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT) && defined(RCC_PLLSAI2Q_DIV_SUPPORT)
\r
2209 /* Configure the PLLSAI2 Multiplication factor N */
\r
2210 /* Configure the PLLSAI2 Division factors M, P, Q and R */
\r
2211 __HAL_RCC_PLLSAI2_CONFIG(PLLSAI2Init->PLLSAI2M, PLLSAI2Init->PLLSAI2N, PLLSAI2Init->PLLSAI2P, PLLSAI2Init->PLLSAI2Q, PLLSAI2Init->PLLSAI2R);
\r
2212 #elif defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
2213 /* Configure the PLLSAI2 Multiplication factor N */
\r
2214 /* Configure the PLLSAI2 Division factors M, P and R */
\r
2215 __HAL_RCC_PLLSAI2_CONFIG(PLLSAI2Init->PLLSAI2M, PLLSAI2Init->PLLSAI2N, PLLSAI2Init->PLLSAI2P, PLLSAI2Init->PLLSAI2R);
\r
2216 #elif defined(RCC_PLLSAI2Q_DIV_SUPPORT)
\r
2217 /* Configure the PLLSAI2 Multiplication factor N */
\r
2218 /* Configure the PLLSAI2 Division factors P, Q and R */
\r
2219 __HAL_RCC_PLLSAI2_CONFIG(PLLSAI2Init->PLLSAI2N, PLLSAI2Init->PLLSAI2P, PLLSAI2Init->PLLSAI2Q, PLLSAI2Init->PLLSAI2R);
\r
2221 /* Configure the PLLSAI2 Multiplication factor N */
\r
2222 /* Configure the PLLSAI2 Division factors P and R */
\r
2223 __HAL_RCC_PLLSAI2_CONFIG(PLLSAI2Init->PLLSAI2N, PLLSAI2Init->PLLSAI2P, PLLSAI2Init->PLLSAI2R);
\r
2224 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT && RCC_PLLSAI2Q_DIV_SUPPORT */
\r
2225 /* Configure the PLLSAI2 Clock output(s) */
\r
2226 __HAL_RCC_PLLSAI2CLKOUT_ENABLE(PLLSAI2Init->PLLSAI2ClockOut);
\r
2228 /* Enable the PLLSAI2 again by setting PLLSAI2ON to 1*/
\r
2229 __HAL_RCC_PLLSAI2_ENABLE();
\r
2231 /* Get Start Tick*/
\r
2232 tickstart = HAL_GetTick();
\r
2234 /* Wait till PLLSAI2 is ready */
\r
2235 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) == 0U)
\r
2237 if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
\r
2239 status = HAL_TIMEOUT;
\r
2249 * @brief Disable PLLISAI2.
\r
2250 * @retval HAL status
\r
2252 HAL_StatusTypeDef HAL_RCCEx_DisablePLLSAI2(void)
\r
2254 uint32_t tickstart;
\r
2255 HAL_StatusTypeDef status = HAL_OK;
\r
2257 /* Disable the PLLSAI2 */
\r
2258 __HAL_RCC_PLLSAI2_DISABLE();
\r
2260 /* Get Start Tick*/
\r
2261 tickstart = HAL_GetTick();
\r
2263 /* Wait till PLLSAI2 is ready */
\r
2264 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) != 0U)
\r
2266 if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
\r
2268 status = HAL_TIMEOUT;
\r
2273 /* Disable the PLLSAI2 Clock outputs */
\r
2274 #if defined(RCC_PLLSAI2Q_DIV_SUPPORT)
\r
2275 __HAL_RCC_PLLSAI2CLKOUT_DISABLE(RCC_PLLSAI2CFGR_PLLSAI2PEN|RCC_PLLSAI2CFGR_PLLSAI2QEN|RCC_PLLSAI2CFGR_PLLSAI2REN);
\r
2277 __HAL_RCC_PLLSAI2CLKOUT_DISABLE(RCC_PLLSAI2CFGR_PLLSAI2PEN|RCC_PLLSAI2CFGR_PLLSAI2REN);
\r
2278 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT && RCC_PLLSAI2Q_DIV_SUPPORT */
\r
2280 /* Reset PLL source to save power if no PLLs on */
\r
2281 if(READ_BIT(RCC->CR, (RCC_CR_PLLRDY | RCC_CR_PLLSAI1RDY)) == 0U)
\r
2283 MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, RCC_PLLSOURCE_NONE);
\r
2289 #endif /* RCC_PLLSAI2_SUPPORT */
\r
2292 * @brief Configure the oscillator clock source for wakeup from Stop and CSS backup clock.
\r
2293 * @param WakeUpClk Wakeup clock
\r
2294 * This parameter can be one of the following values:
\r
2295 * @arg @ref RCC_STOP_WAKEUPCLOCK_MSI MSI oscillator selection
\r
2296 * @arg @ref RCC_STOP_WAKEUPCLOCK_HSI HSI oscillator selection
\r
2297 * @note This function shall not be called after the Clock Security System on HSE has been
\r
2301 void HAL_RCCEx_WakeUpStopCLKConfig(uint32_t WakeUpClk)
\r
2303 assert_param(IS_RCC_STOP_WAKEUPCLOCK(WakeUpClk));
\r
2305 __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(WakeUpClk);
\r
2309 * @brief Configure the MSI range after standby mode.
\r
2310 * @note After Standby its frequency can be selected between 4 possible values (1, 2, 4 or 8 MHz).
\r
2311 * @param MSIRange MSI range
\r
2312 * This parameter can be one of the following values:
\r
2313 * @arg @ref RCC_MSIRANGE_4 Range 4 around 1 MHz
\r
2314 * @arg @ref RCC_MSIRANGE_5 Range 5 around 2 MHz
\r
2315 * @arg @ref RCC_MSIRANGE_6 Range 6 around 4 MHz (reset value)
\r
2316 * @arg @ref RCC_MSIRANGE_7 Range 7 around 8 MHz
\r
2319 void HAL_RCCEx_StandbyMSIRangeConfig(uint32_t MSIRange)
\r
2321 assert_param(IS_RCC_MSI_STANDBY_CLOCK_RANGE(MSIRange));
\r
2323 __HAL_RCC_MSI_STANDBY_RANGE_CONFIG(MSIRange);
\r
2327 * @brief Enable the LSE Clock Security System.
\r
2328 * @note Prior to enable the LSE Clock Security System, LSE oscillator is to be enabled
\r
2329 * with HAL_RCC_OscConfig() and the LSE oscillator clock is to be selected as RTC
\r
2330 * clock with HAL_RCCEx_PeriphCLKConfig().
\r
2333 void HAL_RCCEx_EnableLSECSS(void)
\r
2335 SET_BIT(RCC->BDCR, RCC_BDCR_LSECSSON) ;
\r
2339 * @brief Disable the LSE Clock Security System.
\r
2340 * @note LSE Clock Security System can only be disabled after a LSE failure detection.
\r
2343 void HAL_RCCEx_DisableLSECSS(void)
\r
2345 CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSECSSON) ;
\r
2347 /* Disable LSE CSS IT if any */
\r
2348 __HAL_RCC_DISABLE_IT(RCC_IT_LSECSS);
\r
2352 * @brief Enable the LSE Clock Security System Interrupt & corresponding EXTI line.
\r
2353 * @note LSE Clock Security System Interrupt is mapped on RTC EXTI line 19
\r
2356 void HAL_RCCEx_EnableLSECSS_IT(void)
\r
2358 /* Enable LSE CSS */
\r
2359 SET_BIT(RCC->BDCR, RCC_BDCR_LSECSSON) ;
\r
2361 /* Enable LSE CSS IT */
\r
2362 __HAL_RCC_ENABLE_IT(RCC_IT_LSECSS);
\r
2364 /* Enable IT on EXTI Line 19 */
\r
2365 __HAL_RCC_LSECSS_EXTI_ENABLE_IT();
\r
2366 __HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE();
\r
2370 * @brief Handle the RCC LSE Clock Security System interrupt request.
\r
2373 void HAL_RCCEx_LSECSS_IRQHandler(void)
\r
2375 /* Check RCC LSE CSSF flag */
\r
2376 if(__HAL_RCC_GET_IT(RCC_IT_LSECSS))
\r
2378 /* RCC LSE Clock Security System interrupt user callback */
\r
2379 HAL_RCCEx_LSECSS_Callback();
\r
2381 /* Clear RCC LSE CSS pending bit */
\r
2382 __HAL_RCC_CLEAR_IT(RCC_IT_LSECSS);
\r
2387 * @brief RCCEx LSE Clock Security System interrupt callback.
\r
2390 __weak void HAL_RCCEx_LSECSS_Callback(void)
\r
2392 /* NOTE : This function should not be modified, when the callback is needed,
\r
2393 the @ref HAL_RCCEx_LSECSS_Callback should be implemented in the user file
\r
2398 * @brief Select the Low Speed clock source to output on LSCO pin (PA2).
\r
2399 * @param LSCOSource specifies the Low Speed clock source to output.
\r
2400 * This parameter can be one of the following values:
\r
2401 * @arg @ref RCC_LSCOSOURCE_LSI LSI clock selected as LSCO source
\r
2402 * @arg @ref RCC_LSCOSOURCE_LSE LSE clock selected as LSCO source
\r
2405 void HAL_RCCEx_EnableLSCO(uint32_t LSCOSource)
\r
2407 GPIO_InitTypeDef GPIO_InitStruct;
\r
2408 FlagStatus pwrclkchanged = RESET;
\r
2409 FlagStatus backupchanged = RESET;
\r
2411 /* Check the parameters */
\r
2412 assert_param(IS_RCC_LSCOSOURCE(LSCOSource));
\r
2414 /* LSCO Pin Clock Enable */
\r
2415 __LSCO_CLK_ENABLE();
\r
2417 /* Configue the LSCO pin in analog mode */
\r
2418 GPIO_InitStruct.Pin = LSCO_PIN;
\r
2419 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
\r
2420 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
\r
2421 GPIO_InitStruct.Pull = GPIO_NOPULL;
\r
2422 HAL_GPIO_Init(LSCO_GPIO_PORT, &GPIO_InitStruct);
\r
2424 /* Update LSCOSEL clock source in Backup Domain control register */
\r
2425 if(__HAL_RCC_PWR_IS_CLK_DISABLED())
\r
2427 __HAL_RCC_PWR_CLK_ENABLE();
\r
2428 pwrclkchanged = SET;
\r
2430 if(HAL_IS_BIT_CLR(PWR->CR1, PWR_CR1_DBP))
\r
2432 HAL_PWR_EnableBkUpAccess();
\r
2433 backupchanged = SET;
\r
2436 MODIFY_REG(RCC->BDCR, RCC_BDCR_LSCOSEL | RCC_BDCR_LSCOEN, LSCOSource | RCC_BDCR_LSCOEN);
\r
2438 if(backupchanged == SET)
\r
2440 HAL_PWR_DisableBkUpAccess();
\r
2442 if(pwrclkchanged == SET)
\r
2444 __HAL_RCC_PWR_CLK_DISABLE();
\r
2449 * @brief Disable the Low Speed clock output.
\r
2452 void HAL_RCCEx_DisableLSCO(void)
\r
2454 FlagStatus pwrclkchanged = RESET;
\r
2455 FlagStatus backupchanged = RESET;
\r
2457 /* Update LSCOEN bit in Backup Domain control register */
\r
2458 if(__HAL_RCC_PWR_IS_CLK_DISABLED())
\r
2460 __HAL_RCC_PWR_CLK_ENABLE();
\r
2461 pwrclkchanged = SET;
\r
2463 if(HAL_IS_BIT_CLR(PWR->CR1, PWR_CR1_DBP))
\r
2465 /* Enable access to the backup domain */
\r
2466 HAL_PWR_EnableBkUpAccess();
\r
2467 backupchanged = SET;
\r
2470 CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSCOEN);
\r
2472 /* Restore previous configuration */
\r
2473 if(backupchanged == SET)
\r
2475 /* Disable access to the backup domain */
\r
2476 HAL_PWR_DisableBkUpAccess();
\r
2478 if(pwrclkchanged == SET)
\r
2480 __HAL_RCC_PWR_CLK_DISABLE();
\r
2485 * @brief Enable the PLL-mode of the MSI.
\r
2486 * @note Prior to enable the PLL-mode of the MSI for automatic hardware
\r
2487 * calibration LSE oscillator is to be enabled with HAL_RCC_OscConfig().
\r
2490 void HAL_RCCEx_EnableMSIPLLMode(void)
\r
2492 SET_BIT(RCC->CR, RCC_CR_MSIPLLEN) ;
\r
2496 * @brief Disable the PLL-mode of the MSI.
\r
2497 * @note PLL-mode of the MSI is automatically reset when LSE oscillator is disabled.
\r
2500 void HAL_RCCEx_DisableMSIPLLMode(void)
\r
2502 CLEAR_BIT(RCC->CR, RCC_CR_MSIPLLEN) ;
\r
2511 /** @defgroup RCCEx_Exported_Functions_Group3 Extended Clock Recovery System Control functions
\r
2512 * @brief Extended Clock Recovery System Control functions
\r
2515 ===============================================================================
\r
2516 ##### Extended Clock Recovery System Control functions #####
\r
2517 ===============================================================================
\r
2519 For devices with Clock Recovery System feature (CRS), RCC Extention HAL driver can be used as follows:
\r
2521 (#) In System clock config, HSI48 needs to be enabled
\r
2523 (#) Enable CRS clock in IP MSP init which will use CRS functions
\r
2525 (#) Call CRS functions as follows:
\r
2526 (##) Prepare synchronization configuration necessary for HSI48 calibration
\r
2527 (+++) Default values can be set for frequency Error Measurement (reload and error limit)
\r
2528 and also HSI48 oscillator smooth trimming.
\r
2529 (+++) Macro __HAL_RCC_CRS_RELOADVALUE_CALCULATE can be also used to calculate
\r
2530 directly reload value with target and sychronization frequencies values
\r
2531 (##) Call function HAL_RCCEx_CRSConfig which
\r
2532 (+++) Resets CRS registers to their default values.
\r
2533 (+++) Configures CRS registers with synchronization configuration
\r
2534 (+++) Enables automatic calibration and frequency error counter feature
\r
2535 Note: When using USB LPM (Link Power Management) and the device is in Sleep mode, the
\r
2536 periodic USB SOF will not be generated by the host. No SYNC signal will therefore be
\r
2537 provided to the CRS to calibrate the HSI48 on the run. To guarantee the required clock
\r
2538 precision after waking up from Sleep mode, the LSE or reference clock on the GPIOs
\r
2539 should be used as SYNC signal.
\r
2541 (##) A polling function is provided to wait for complete synchronization
\r
2542 (+++) Call function HAL_RCCEx_CRSWaitSynchronization()
\r
2543 (+++) According to CRS status, user can decide to adjust again the calibration or continue
\r
2544 application if synchronization is OK
\r
2546 (#) User can retrieve information related to synchronization in calling function
\r
2547 HAL_RCCEx_CRSGetSynchronizationInfo()
\r
2549 (#) Regarding synchronization status and synchronization information, user can try a new calibration
\r
2550 in changing synchronization configuration and call again HAL_RCCEx_CRSConfig.
\r
2551 Note: When the SYNC event is detected during the downcounting phase (before reaching the zero value),
\r
2552 it means that the actual frequency is lower than the target (and so, that the TRIM value should be
\r
2553 incremented), while when it is detected during the upcounting phase it means that the actual frequency
\r
2554 is higher (and that the TRIM value should be decremented).
\r
2556 (#) In interrupt mode, user can resort to the available macros (__HAL_RCC_CRS_XXX_IT). Interrupts will go
\r
2557 through CRS Handler (CRS_IRQn/CRS_IRQHandler)
\r
2558 (++) Call function HAL_RCCEx_CRSConfig()
\r
2559 (++) Enable CRS_IRQn (thanks to NVIC functions)
\r
2560 (++) Enable CRS interrupt (__HAL_RCC_CRS_ENABLE_IT)
\r
2561 (++) Implement CRS status management in the following user callbacks called from
\r
2562 HAL_RCCEx_CRS_IRQHandler():
\r
2563 (+++) HAL_RCCEx_CRS_SyncOkCallback()
\r
2564 (+++) HAL_RCCEx_CRS_SyncWarnCallback()
\r
2565 (+++) HAL_RCCEx_CRS_ExpectedSyncCallback()
\r
2566 (+++) HAL_RCCEx_CRS_ErrorCallback()
\r
2568 (#) To force a SYNC EVENT, user can use the function HAL_RCCEx_CRSSoftwareSynchronizationGenerate().
\r
2569 This function can be called before calling HAL_RCCEx_CRSConfig (for instance in Systick handler)
\r
2576 * @brief Start automatic synchronization for polling mode
\r
2577 * @param pInit Pointer on RCC_CRSInitTypeDef structure
\r
2580 void HAL_RCCEx_CRSConfig(RCC_CRSInitTypeDef *pInit)
\r
2582 uint32_t value; /* no init needed */
\r
2584 /* Check the parameters */
\r
2585 assert_param(IS_RCC_CRS_SYNC_DIV(pInit->Prescaler));
\r
2586 assert_param(IS_RCC_CRS_SYNC_SOURCE(pInit->Source));
\r
2587 assert_param(IS_RCC_CRS_SYNC_POLARITY(pInit->Polarity));
\r
2588 assert_param(IS_RCC_CRS_RELOADVALUE(pInit->ReloadValue));
\r
2589 assert_param(IS_RCC_CRS_ERRORLIMIT(pInit->ErrorLimitValue));
\r
2590 assert_param(IS_RCC_CRS_HSI48CALIBRATION(pInit->HSI48CalibrationValue));
\r
2592 /* CONFIGURATION */
\r
2594 /* Before configuration, reset CRS registers to their default values*/
\r
2595 __HAL_RCC_CRS_FORCE_RESET();
\r
2596 __HAL_RCC_CRS_RELEASE_RESET();
\r
2598 /* Set the SYNCDIV[2:0] bits according to Prescaler value */
\r
2599 /* Set the SYNCSRC[1:0] bits according to Source value */
\r
2600 /* Set the SYNCSPOL bit according to Polarity value */
\r
2601 value = (pInit->Prescaler | pInit->Source | pInit->Polarity);
\r
2602 /* Set the RELOAD[15:0] bits according to ReloadValue value */
\r
2603 value |= pInit->ReloadValue;
\r
2604 /* Set the FELIM[7:0] bits according to ErrorLimitValue value */
\r
2605 value |= (pInit->ErrorLimitValue << CRS_CFGR_FELIM_Pos);
\r
2606 WRITE_REG(CRS->CFGR, value);
\r
2608 /* Adjust HSI48 oscillator smooth trimming */
\r
2609 /* Set the TRIM[6:0] bits for STM32L412xx/L422xx or TRIM[5:0] bits otherwise
\r
2610 according to RCC_CRS_HSI48CalibrationValue value */
\r
2611 MODIFY_REG(CRS->CR, CRS_CR_TRIM, (pInit->HSI48CalibrationValue << CRS_CR_TRIM_Pos));
\r
2613 /* START AUTOMATIC SYNCHRONIZATION*/
\r
2615 /* Enable Automatic trimming & Frequency error counter */
\r
2616 SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN | CRS_CR_CEN);
\r
2620 * @brief Generate the software synchronization event
\r
2623 void HAL_RCCEx_CRSSoftwareSynchronizationGenerate(void)
\r
2625 SET_BIT(CRS->CR, CRS_CR_SWSYNC);
\r
2629 * @brief Return synchronization info
\r
2630 * @param pSynchroInfo Pointer on RCC_CRSSynchroInfoTypeDef structure
\r
2633 void HAL_RCCEx_CRSGetSynchronizationInfo(RCC_CRSSynchroInfoTypeDef *pSynchroInfo)
\r
2635 /* Check the parameter */
\r
2636 assert_param(pSynchroInfo != (void *)NULL);
\r
2638 /* Get the reload value */
\r
2639 pSynchroInfo->ReloadValue = (READ_BIT(CRS->CFGR, CRS_CFGR_RELOAD));
\r
2641 /* Get HSI48 oscillator smooth trimming */
\r
2642 pSynchroInfo->HSI48CalibrationValue = (READ_BIT(CRS->CR, CRS_CR_TRIM) >> CRS_CR_TRIM_Pos);
\r
2644 /* Get Frequency error capture */
\r
2645 pSynchroInfo->FreqErrorCapture = (READ_BIT(CRS->ISR, CRS_ISR_FECAP) >> CRS_ISR_FECAP_Pos);
\r
2647 /* Get Frequency error direction */
\r
2648 pSynchroInfo->FreqErrorDirection = (READ_BIT(CRS->ISR, CRS_ISR_FEDIR));
\r
2652 * @brief Wait for CRS Synchronization status.
\r
2653 * @param Timeout Duration of the timeout
\r
2654 * @note Timeout is based on the maximum time to receive a SYNC event based on synchronization
\r
2656 * @note If Timeout set to HAL_MAX_DELAY, HAL_TIMEOUT will be never returned.
\r
2657 * @retval Combination of Synchronization status
\r
2658 * This parameter can be a combination of the following values:
\r
2659 * @arg @ref RCC_CRS_TIMEOUT
\r
2660 * @arg @ref RCC_CRS_SYNCOK
\r
2661 * @arg @ref RCC_CRS_SYNCWARN
\r
2662 * @arg @ref RCC_CRS_SYNCERR
\r
2663 * @arg @ref RCC_CRS_SYNCMISS
\r
2664 * @arg @ref RCC_CRS_TRIMOVF
\r
2666 uint32_t HAL_RCCEx_CRSWaitSynchronization(uint32_t Timeout)
\r
2668 uint32_t crsstatus = RCC_CRS_NONE;
\r
2669 uint32_t tickstart;
\r
2672 tickstart = HAL_GetTick();
\r
2674 /* Wait for CRS flag or timeout detection */
\r
2677 if(Timeout != HAL_MAX_DELAY)
\r
2679 if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
\r
2681 crsstatus = RCC_CRS_TIMEOUT;
\r
2684 /* Check CRS SYNCOK flag */
\r
2685 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCOK))
\r
2687 /* CRS SYNC event OK */
\r
2688 crsstatus |= RCC_CRS_SYNCOK;
\r
2690 /* Clear CRS SYNC event OK bit */
\r
2691 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCOK);
\r
2694 /* Check CRS SYNCWARN flag */
\r
2695 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCWARN))
\r
2697 /* CRS SYNC warning */
\r
2698 crsstatus |= RCC_CRS_SYNCWARN;
\r
2700 /* Clear CRS SYNCWARN bit */
\r
2701 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCWARN);
\r
2704 /* Check CRS TRIM overflow flag */
\r
2705 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_TRIMOVF))
\r
2707 /* CRS SYNC Error */
\r
2708 crsstatus |= RCC_CRS_TRIMOVF;
\r
2710 /* Clear CRS Error bit */
\r
2711 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_TRIMOVF);
\r
2714 /* Check CRS Error flag */
\r
2715 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCERR))
\r
2717 /* CRS SYNC Error */
\r
2718 crsstatus |= RCC_CRS_SYNCERR;
\r
2720 /* Clear CRS Error bit */
\r
2721 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCERR);
\r
2724 /* Check CRS SYNC Missed flag */
\r
2725 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCMISS))
\r
2727 /* CRS SYNC Missed */
\r
2728 crsstatus |= RCC_CRS_SYNCMISS;
\r
2730 /* Clear CRS SYNC Missed bit */
\r
2731 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCMISS);
\r
2734 /* Check CRS Expected SYNC flag */
\r
2735 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_ESYNC))
\r
2737 /* frequency error counter reached a zero value */
\r
2738 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_ESYNC);
\r
2740 } while(RCC_CRS_NONE == crsstatus);
\r
2746 * @brief Handle the Clock Recovery System interrupt request.
\r
2749 void HAL_RCCEx_CRS_IRQHandler(void)
\r
2751 uint32_t crserror = RCC_CRS_NONE;
\r
2752 /* Get current IT flags and IT sources values */
\r
2753 uint32_t itflags = READ_REG(CRS->ISR);
\r
2754 uint32_t itsources = READ_REG(CRS->CR);
\r
2756 /* Check CRS SYNCOK flag */
\r
2757 if(((itflags & RCC_CRS_FLAG_SYNCOK) != 0U) && ((itsources & RCC_CRS_IT_SYNCOK) != 0U))
\r
2759 /* Clear CRS SYNC event OK flag */
\r
2760 WRITE_REG(CRS->ICR, CRS_ICR_SYNCOKC);
\r
2762 /* user callback */
\r
2763 HAL_RCCEx_CRS_SyncOkCallback();
\r
2765 /* Check CRS SYNCWARN flag */
\r
2766 else if(((itflags & RCC_CRS_FLAG_SYNCWARN) != 0U) && ((itsources & RCC_CRS_IT_SYNCWARN) != 0U))
\r
2768 /* Clear CRS SYNCWARN flag */
\r
2769 WRITE_REG(CRS->ICR, CRS_ICR_SYNCWARNC);
\r
2771 /* user callback */
\r
2772 HAL_RCCEx_CRS_SyncWarnCallback();
\r
2774 /* Check CRS Expected SYNC flag */
\r
2775 else if(((itflags & RCC_CRS_FLAG_ESYNC) != 0U) && ((itsources & RCC_CRS_IT_ESYNC) != 0U))
\r
2777 /* frequency error counter reached a zero value */
\r
2778 WRITE_REG(CRS->ICR, CRS_ICR_ESYNCC);
\r
2780 /* user callback */
\r
2781 HAL_RCCEx_CRS_ExpectedSyncCallback();
\r
2783 /* Check CRS Error flags */
\r
2786 if(((itflags & RCC_CRS_FLAG_ERR) != 0U) && ((itsources & RCC_CRS_IT_ERR) != 0U))
\r
2788 if((itflags & RCC_CRS_FLAG_SYNCERR) != 0U)
\r
2790 crserror |= RCC_CRS_SYNCERR;
\r
2792 if((itflags & RCC_CRS_FLAG_SYNCMISS) != 0U)
\r
2794 crserror |= RCC_CRS_SYNCMISS;
\r
2796 if((itflags & RCC_CRS_FLAG_TRIMOVF) != 0U)
\r
2798 crserror |= RCC_CRS_TRIMOVF;
\r
2801 /* Clear CRS Error flags */
\r
2802 WRITE_REG(CRS->ICR, CRS_ICR_ERRC);
\r
2804 /* user error callback */
\r
2805 HAL_RCCEx_CRS_ErrorCallback(crserror);
\r
2811 * @brief RCCEx Clock Recovery System SYNCOK interrupt callback.
\r
2814 __weak void HAL_RCCEx_CRS_SyncOkCallback(void)
\r
2816 /* NOTE : This function should not be modified, when the callback is needed,
\r
2817 the @ref HAL_RCCEx_CRS_SyncOkCallback should be implemented in the user file
\r
2822 * @brief RCCEx Clock Recovery System SYNCWARN interrupt callback.
\r
2825 __weak void HAL_RCCEx_CRS_SyncWarnCallback(void)
\r
2827 /* NOTE : This function should not be modified, when the callback is needed,
\r
2828 the @ref HAL_RCCEx_CRS_SyncWarnCallback should be implemented in the user file
\r
2833 * @brief RCCEx Clock Recovery System Expected SYNC interrupt callback.
\r
2836 __weak void HAL_RCCEx_CRS_ExpectedSyncCallback(void)
\r
2838 /* NOTE : This function should not be modified, when the callback is needed,
\r
2839 the @ref HAL_RCCEx_CRS_ExpectedSyncCallback should be implemented in the user file
\r
2844 * @brief RCCEx Clock Recovery System Error interrupt callback.
\r
2845 * @param Error Combination of Error status.
\r
2846 * This parameter can be a combination of the following values:
\r
2847 * @arg @ref RCC_CRS_SYNCERR
\r
2848 * @arg @ref RCC_CRS_SYNCMISS
\r
2849 * @arg @ref RCC_CRS_TRIMOVF
\r
2852 __weak void HAL_RCCEx_CRS_ErrorCallback(uint32_t Error)
\r
2854 /* Prevent unused argument(s) compilation warning */
\r
2857 /* NOTE : This function should not be modified, when the callback is needed,
\r
2858 the @ref HAL_RCCEx_CRS_ErrorCallback should be implemented in the user file
\r
2872 /** @addtogroup RCCEx_Private_Functions
\r
2876 #if defined(RCC_PLLSAI1_SUPPORT)
\r
2879 * @brief Configure the parameters N & P & optionally M of PLLSAI1 and enable PLLSAI1 output clock(s).
\r
2880 * @param PllSai1 pointer to an RCC_PLLSAI1InitTypeDef structure that
\r
2881 * contains the configuration parameters N & P & optionally M as well as PLLSAI1 output clock(s)
\r
2882 * @param Divider divider parameter to be updated
\r
2884 * @note PLLSAI1 is temporary disable to apply new parameters
\r
2886 * @retval HAL status
\r
2888 static HAL_StatusTypeDef RCCEx_PLLSAI1_Config(RCC_PLLSAI1InitTypeDef *PllSai1, uint32_t Divider)
\r
2890 uint32_t tickstart;
\r
2891 HAL_StatusTypeDef status = HAL_OK;
\r
2893 /* check for PLLSAI1 Parameters used to output PLLSAI1CLK */
\r
2894 /* P, Q and R dividers are verified in each specific divider case below */
\r
2895 assert_param(IS_RCC_PLLSAI1SOURCE(PllSai1->PLLSAI1Source));
\r
2896 assert_param(IS_RCC_PLLSAI1M_VALUE(PllSai1->PLLSAI1M));
\r
2897 assert_param(IS_RCC_PLLSAI1N_VALUE(PllSai1->PLLSAI1N));
\r
2898 assert_param(IS_RCC_PLLSAI1CLOCKOUT_VALUE(PllSai1->PLLSAI1ClockOut));
\r
2900 /* Check that PLLSAI1 clock source and divider M can be applied */
\r
2901 if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_NONE)
\r
2903 /* PLL clock source and divider M already set, check that no request for change */
\r
2904 if((__HAL_RCC_GET_PLL_OSCSOURCE() != PllSai1->PLLSAI1Source)
\r
2906 (PllSai1->PLLSAI1Source == RCC_PLLSOURCE_NONE)
\r
2907 #if !defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
2909 (((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U) != PllSai1->PLLSAI1M)
\r
2913 status = HAL_ERROR;
\r
2918 /* Check PLLSAI1 clock source availability */
\r
2919 switch(PllSai1->PLLSAI1Source)
\r
2921 case RCC_PLLSOURCE_MSI:
\r
2922 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_MSIRDY))
\r
2924 status = HAL_ERROR;
\r
2927 case RCC_PLLSOURCE_HSI:
\r
2928 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSIRDY))
\r
2930 status = HAL_ERROR;
\r
2933 case RCC_PLLSOURCE_HSE:
\r
2934 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSERDY))
\r
2936 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSEBYP))
\r
2938 status = HAL_ERROR;
\r
2943 status = HAL_ERROR;
\r
2947 if(status == HAL_OK)
\r
2949 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
2950 /* Set PLLSAI1 clock source */
\r
2951 MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PllSai1->PLLSAI1Source);
\r
2953 /* Set PLLSAI1 clock source and divider M */
\r
2954 MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM, PllSai1->PLLSAI1Source | (PllSai1->PLLSAI1M - 1U) << RCC_PLLCFGR_PLLM_Pos);
\r
2959 if(status == HAL_OK)
\r
2961 /* Disable the PLLSAI1 */
\r
2962 __HAL_RCC_PLLSAI1_DISABLE();
\r
2964 /* Get Start Tick*/
\r
2965 tickstart = HAL_GetTick();
\r
2967 /* Wait till PLLSAI1 is ready to be updated */
\r
2968 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) != 0U)
\r
2970 if((HAL_GetTick() - tickstart) > PLLSAI1_TIMEOUT_VALUE)
\r
2972 status = HAL_TIMEOUT;
\r
2977 if(status == HAL_OK)
\r
2979 if(Divider == DIVIDER_P_UPDATE)
\r
2981 assert_param(IS_RCC_PLLSAI1P_VALUE(PllSai1->PLLSAI1P));
\r
2982 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
2984 /* Configure the PLLSAI1 Division factor M, P and Multiplication factor N*/
\r
2985 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
\r
2986 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
2987 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1PDIV | RCC_PLLSAI1CFGR_PLLSAI1M,
\r
2988 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
2989 (PllSai1->PLLSAI1P << RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos) |
\r
2990 ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
\r
2992 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
2993 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1P | RCC_PLLSAI1CFGR_PLLSAI1M,
\r
2994 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
2995 ((PllSai1->PLLSAI1P >> 4U) << RCC_PLLSAI1CFGR_PLLSAI1P_Pos) |
\r
2996 ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
\r
2997 #endif /* RCC_PLLSAI1P_DIV_2_31_SUPPORT */
\r
3000 /* Configure the PLLSAI1 Division factor P and Multiplication factor N*/
\r
3001 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
\r
3002 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
3003 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1PDIV,
\r
3004 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
3005 (PllSai1->PLLSAI1P << RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos));
\r
3007 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
3008 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1P,
\r
3009 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
3010 ((PllSai1->PLLSAI1P >> 4U) << RCC_PLLSAI1CFGR_PLLSAI1P_Pos));
\r
3011 #endif /* RCC_PLLSAI1P_DIV_2_31_SUPPORT */
\r
3013 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
\r
3015 else if(Divider == DIVIDER_Q_UPDATE)
\r
3017 assert_param(IS_RCC_PLLSAI1Q_VALUE(PllSai1->PLLSAI1Q));
\r
3018 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
3019 /* Configure the PLLSAI1 Division factor M, Q and Multiplication factor N*/
\r
3020 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
3021 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1Q | RCC_PLLSAI1CFGR_PLLSAI1M,
\r
3022 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
3023 (((PllSai1->PLLSAI1Q >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1Q_Pos) |
\r
3024 ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
\r
3026 /* Configure the PLLSAI1 Division factor Q and Multiplication factor N*/
\r
3027 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
3028 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1Q,
\r
3029 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
3030 (((PllSai1->PLLSAI1Q >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1Q_Pos));
\r
3031 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
\r
3035 assert_param(IS_RCC_PLLSAI1R_VALUE(PllSai1->PLLSAI1R));
\r
3036 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
3037 /* Configure the PLLSAI1 Division factor M, R and Multiplication factor N*/
\r
3038 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
3039 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1R | RCC_PLLSAI1CFGR_PLLSAI1M,
\r
3040 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
3041 (((PllSai1->PLLSAI1R >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1R_Pos) |
\r
3042 ((PllSai1->PLLSAI1M - 1U) << RCC_PLLSAI1CFGR_PLLSAI1M_Pos));
\r
3044 /* Configure the PLLSAI1 Division factor R and Multiplication factor N*/
\r
3045 MODIFY_REG(RCC->PLLSAI1CFGR,
\r
3046 RCC_PLLSAI1CFGR_PLLSAI1N | RCC_PLLSAI1CFGR_PLLSAI1R,
\r
3047 (PllSai1->PLLSAI1N << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) |
\r
3048 (((PllSai1->PLLSAI1R >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1R_Pos));
\r
3049 #endif /* RCC_PLLSAI1M_DIV_1_16_SUPPORT */
\r
3052 /* Enable the PLLSAI1 again by setting PLLSAI1ON to 1*/
\r
3053 __HAL_RCC_PLLSAI1_ENABLE();
\r
3055 /* Get Start Tick*/
\r
3056 tickstart = HAL_GetTick();
\r
3058 /* Wait till PLLSAI1 is ready */
\r
3059 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) == 0U)
\r
3061 if((HAL_GetTick() - tickstart) > PLLSAI1_TIMEOUT_VALUE)
\r
3063 status = HAL_TIMEOUT;
\r
3068 if(status == HAL_OK)
\r
3070 /* Configure the PLLSAI1 Clock output(s) */
\r
3071 __HAL_RCC_PLLSAI1CLKOUT_ENABLE(PllSai1->PLLSAI1ClockOut);
\r
3079 #endif /* RCC_PLLSAI1_SUPPORT */
\r
3081 #if defined(RCC_PLLSAI2_SUPPORT)
\r
3084 * @brief Configure the parameters N & P & optionally M of PLLSAI2 and enable PLLSAI2 output clock(s).
\r
3085 * @param PllSai2 pointer to an RCC_PLLSAI2InitTypeDef structure that
\r
3086 * contains the configuration parameters N & P & optionally M as well as PLLSAI2 output clock(s)
\r
3087 * @param Divider divider parameter to be updated
\r
3089 * @note PLLSAI2 is temporary disable to apply new parameters
\r
3091 * @retval HAL status
\r
3093 static HAL_StatusTypeDef RCCEx_PLLSAI2_Config(RCC_PLLSAI2InitTypeDef *PllSai2, uint32_t Divider)
\r
3095 uint32_t tickstart;
\r
3096 HAL_StatusTypeDef status = HAL_OK;
\r
3098 /* check for PLLSAI2 Parameters used to output PLLSAI2CLK */
\r
3099 /* P, Q and R dividers are verified in each specific divider case below */
\r
3100 assert_param(IS_RCC_PLLSAI2SOURCE(PllSai2->PLLSAI2Source));
\r
3101 assert_param(IS_RCC_PLLSAI2M_VALUE(PllSai2->PLLSAI2M));
\r
3102 assert_param(IS_RCC_PLLSAI2N_VALUE(PllSai2->PLLSAI2N));
\r
3103 assert_param(IS_RCC_PLLSAI2CLOCKOUT_VALUE(PllSai2->PLLSAI2ClockOut));
\r
3105 /* Check that PLLSAI2 clock source and divider M can be applied */
\r
3106 if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_NONE)
\r
3108 /* PLL clock source and divider M already set, check that no request for change */
\r
3109 if((__HAL_RCC_GET_PLL_OSCSOURCE() != PllSai2->PLLSAI2Source)
\r
3111 (PllSai2->PLLSAI2Source == RCC_PLLSOURCE_NONE)
\r
3112 #if !defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
3114 (((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U) != PllSai2->PLLSAI2M)
\r
3118 status = HAL_ERROR;
\r
3123 /* Check PLLSAI2 clock source availability */
\r
3124 switch(PllSai2->PLLSAI2Source)
\r
3126 case RCC_PLLSOURCE_MSI:
\r
3127 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_MSIRDY))
\r
3129 status = HAL_ERROR;
\r
3132 case RCC_PLLSOURCE_HSI:
\r
3133 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSIRDY))
\r
3135 status = HAL_ERROR;
\r
3138 case RCC_PLLSOURCE_HSE:
\r
3139 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSERDY))
\r
3141 if(HAL_IS_BIT_CLR(RCC->CR, RCC_CR_HSEBYP))
\r
3143 status = HAL_ERROR;
\r
3148 status = HAL_ERROR;
\r
3152 if(status == HAL_OK)
\r
3154 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
3155 /* Set PLLSAI2 clock source */
\r
3156 MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PllSai2->PLLSAI2Source);
\r
3158 /* Set PLLSAI2 clock source and divider M */
\r
3159 MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM, PllSai2->PLLSAI2Source | (PllSai2->PLLSAI2M - 1U) << RCC_PLLCFGR_PLLM_Pos);
\r
3164 if(status == HAL_OK)
\r
3166 /* Disable the PLLSAI2 */
\r
3167 __HAL_RCC_PLLSAI2_DISABLE();
\r
3169 /* Get Start Tick*/
\r
3170 tickstart = HAL_GetTick();
\r
3172 /* Wait till PLLSAI2 is ready to be updated */
\r
3173 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) != 0U)
\r
3175 if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
\r
3177 status = HAL_TIMEOUT;
\r
3182 if(status == HAL_OK)
\r
3184 if(Divider == DIVIDER_P_UPDATE)
\r
3186 assert_param(IS_RCC_PLLSAI2P_VALUE(PllSai2->PLLSAI2P));
\r
3187 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
3189 /* Configure the PLLSAI2 Division factor M, P and Multiplication factor N*/
\r
3190 #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
\r
3191 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3192 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2PDIV | RCC_PLLSAI2CFGR_PLLSAI2M,
\r
3193 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3194 (PllSai2->PLLSAI2P << RCC_PLLSAI2CFGR_PLLSAI2PDIV_Pos) |
\r
3195 ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
\r
3197 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3198 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2P | RCC_PLLSAI2CFGR_PLLSAI2M,
\r
3199 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3200 ((PllSai2->PLLSAI2P >> 4U) << RCC_PLLSAI2CFGR_PLLSAI2P_Pos) |
\r
3201 ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
\r
3202 #endif /* RCC_PLLSAI2P_DIV_2_31_SUPPORT */
\r
3205 /* Configure the PLLSAI2 Division factor P and Multiplication factor N*/
\r
3206 #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
\r
3207 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3208 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2PDIV,
\r
3209 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3210 (PllSai2->PLLSAI2P << RCC_PLLSAI2CFGR_PLLSAI2PDIV_Pos));
\r
3212 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3213 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2P,
\r
3214 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3215 ((PllSai2->PLLSAI2P >> 4U) << RCC_PLLSAI2CFGR_PLLSAI2P_Pos));
\r
3216 #endif /* RCC_PLLSAI2P_DIV_2_31_SUPPORT */
\r
3218 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT */
\r
3220 #if defined(RCC_PLLSAI2Q_DIV_SUPPORT)
\r
3221 else if(Divider == DIVIDER_Q_UPDATE)
\r
3223 assert_param(IS_RCC_PLLSAI2Q_VALUE(PllSai2->PLLSAI2Q));
\r
3224 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
3225 /* Configure the PLLSAI2 Division factor M, Q and Multiplication factor N*/
\r
3226 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3227 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2Q | RCC_PLLSAI2CFGR_PLLSAI2M,
\r
3228 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3229 (((PllSai2->PLLSAI2Q >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2Q_Pos) |
\r
3230 ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
\r
3232 /* Configure the PLLSAI2 Division factor Q and Multiplication factor N*/
\r
3233 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3234 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2Q,
\r
3235 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3236 (((PllSai2->PLLSAI2Q >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2Q_Pos));
\r
3237 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT */
\r
3239 #endif /* RCC_PLLSAI2Q_DIV_SUPPORT */
\r
3242 assert_param(IS_RCC_PLLSAI2R_VALUE(PllSai2->PLLSAI2R));
\r
3243 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
3244 /* Configure the PLLSAI2 Division factor M, R and Multiplication factor N*/
\r
3245 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3246 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2R | RCC_PLLSAI2CFGR_PLLSAI2M,
\r
3247 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3248 (((PllSai2->PLLSAI2R >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2R_Pos) |
\r
3249 ((PllSai2->PLLSAI2M - 1U) << RCC_PLLSAI2CFGR_PLLSAI2M_Pos));
\r
3251 /* Configure the PLLSAI2 Division factor R and Multiplication factor N*/
\r
3252 MODIFY_REG(RCC->PLLSAI2CFGR,
\r
3253 RCC_PLLSAI2CFGR_PLLSAI2N | RCC_PLLSAI2CFGR_PLLSAI2R,
\r
3254 (PllSai2->PLLSAI2N << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) |
\r
3255 (((PllSai2->PLLSAI2R >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2R_Pos));
\r
3256 #endif /* RCC_PLLSAI2M_DIV_1_16_SUPPORT */
\r
3259 /* Enable the PLLSAI2 again by setting PLLSAI2ON to 1*/
\r
3260 __HAL_RCC_PLLSAI2_ENABLE();
\r
3262 /* Get Start Tick*/
\r
3263 tickstart = HAL_GetTick();
\r
3265 /* Wait till PLLSAI2 is ready */
\r
3266 while(READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) == 0U)
\r
3268 if((HAL_GetTick() - tickstart) > PLLSAI2_TIMEOUT_VALUE)
\r
3270 status = HAL_TIMEOUT;
\r
3275 if(status == HAL_OK)
\r
3277 /* Configure the PLLSAI2 Clock output(s) */
\r
3278 __HAL_RCC_PLLSAI2CLKOUT_ENABLE(PllSai2->PLLSAI2ClockOut);
\r
3286 #endif /* RCC_PLLSAI2_SUPPORT */
\r
3290 static uint32_t RCCEx_GetSAIxPeriphCLKFreq(uint32_t PeriphClk, uint32_t InputFrequency)
\r
3292 uint32_t frequency = 0U;
\r
3293 uint32_t srcclk = 0U;
\r
3294 uint32_t pllvco, plln; /* no init needed */
\r
3295 #if defined(RCC_PLLP_SUPPORT)
\r
3296 uint32_t pllp = 0U;
\r
3297 #endif /* RCC_PLLP_SUPPORT */
\r
3300 if(PeriphClk == RCC_PERIPHCLK_SAI1)
\r
3302 srcclk = __HAL_RCC_GET_SAI1_SOURCE();
\r
3303 if(srcclk == RCC_SAI1CLKSOURCE_PIN)
\r
3305 frequency = EXTERNAL_SAI1_CLOCK_VALUE;
\r
3307 /* Else, PLL clock output to check below */
\r
3312 if(PeriphClk == RCC_PERIPHCLK_SAI2)
\r
3314 srcclk = __HAL_RCC_GET_SAI2_SOURCE();
\r
3315 if(srcclk == RCC_SAI2CLKSOURCE_PIN)
\r
3317 frequency = EXTERNAL_SAI2_CLOCK_VALUE;
\r
3319 /* Else, PLL clock output to check below */
\r
3324 if(frequency == 0U)
\r
3326 pllvco = InputFrequency;
\r
3329 if((srcclk == RCC_SAI1CLKSOURCE_PLL) || (srcclk == RCC_SAI2CLKSOURCE_PLL))
\r
3331 if(__HAL_RCC_GET_PLLCLKOUT_CONFIG(RCC_PLL_SAI3CLK) != 0U)
\r
3333 /* f(PLL Source) / PLLM */
\r
3334 pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
3335 /* f(PLLSAI3CLK) = f(VCO input) * PLLN / PLLP */
\r
3336 plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
\r
3337 #if defined(RCC_PLLP_DIV_2_31_SUPPORT)
\r
3338 pllp = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLPDIV) >> RCC_PLLCFGR_PLLPDIV_Pos;
\r
3342 if(READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) != 0U)
\r
3351 frequency = (pllvco * plln) / pllp;
\r
3354 else if(srcclk == 0U) /* RCC_SAI1CLKSOURCE_PLLSAI1 || RCC_SAI2CLKSOURCE_PLLSAI1 */
\r
3356 if(__HAL_RCC_GET_PLLSAI1CLKOUT_CONFIG(RCC_PLLSAI1_SAI1CLK) != 0U)
\r
3358 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
3359 /* PLLSAI1M exists: apply PLLSAI1M divider for PLLSAI1 output computation */
\r
3360 /* f(PLLSAI1 Source) / PLLSAI1M */
\r
3361 pllvco = (pllvco / ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U));
\r
3363 /* f(PLL Source) / PLLM */
\r
3364 pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
3366 /* f(PLLSAI1CLK) = f(VCOSAI1 input) * PLLSAI1N / PLLSAI1P */
\r
3367 plln = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
\r
3368 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
\r
3369 pllp = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1PDIV) >> RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos;
\r
3373 if(READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1P) != 0U)
\r
3382 frequency = (pllvco * plln) / pllp;
\r
3385 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
3386 else if((srcclk == RCC_SAI1CLKSOURCE_HSI) || (srcclk == RCC_SAI2CLKSOURCE_HSI))
\r
3388 if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
3390 frequency = HSI_VALUE;
\r
3393 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
3396 if(srcclk == RCC_SAI1CLKSOURCE_PLL)
\r
3398 if(__HAL_RCC_GET_PLLCLKOUT_CONFIG(RCC_PLL_SAI2CLK) != 0U)
\r
3400 /* f(PLL Source) / PLLM */
\r
3401 pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
3402 /* f(PLLSAI2CLK) = f(VCO input) * PLLN / PLLP */
\r
3403 plln = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos;
\r
3404 #if defined(RCC_PLLP_DIV_2_31_SUPPORT)
\r
3405 pllp = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLPDIV) >> RCC_PLLCFGR_PLLPDIV_Pos;
\r
3409 if(READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) != 0U)
\r
3418 frequency = (pllvco * plln) / pllp;
\r
3420 else if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
3422 /* HSI automatically selected as clock source if PLLs not enabled */
\r
3423 frequency = HSI_VALUE;
\r
3427 /* No clock source, frequency default init at 0 */
\r
3430 else if(srcclk == RCC_SAI1CLKSOURCE_PLLSAI1)
\r
3432 if(__HAL_RCC_GET_PLLSAI1CLKOUT_CONFIG(RCC_PLLSAI1_SAI1CLK) != 0U)
\r
3434 #if defined(RCC_PLLSAI1M_DIV_1_16_SUPPORT)
\r
3435 /* PLLSAI1M exists: apply PLLSAI1M divider for PLLSAI1 output computation */
\r
3436 /* f(PLLSAI1 Source) / PLLSAI1M */
\r
3437 pllvco = (pllvco / ((READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1M) >> RCC_PLLSAI1CFGR_PLLSAI1M_Pos) + 1U));
\r
3439 /* f(PLL Source) / PLLM */
\r
3440 pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
3442 /* f(PLLSAI1CLK) = f(VCOSAI1 input) * PLLSAI1N / PLLSAI1P */
\r
3443 plln = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N) >> RCC_PLLSAI1CFGR_PLLSAI1N_Pos;
\r
3444 #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
\r
3445 pllp = READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1PDIV) >> RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos;
\r
3449 if(READ_BIT(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1P) != 0U)
\r
3458 frequency = (pllvco * plln) / pllp;
\r
3460 else if(HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
\r
3462 /* HSI automatically selected as clock source if PLLs not enabled */
\r
3463 frequency = HSI_VALUE;
\r
3467 /* No clock source, frequency default init at 0 */
\r
3472 #if defined(RCC_PLLSAI2_SUPPORT)
\r
3474 else if((srcclk == RCC_SAI1CLKSOURCE_PLLSAI2) || (srcclk == RCC_SAI2CLKSOURCE_PLLSAI2))
\r
3476 if(__HAL_RCC_GET_PLLSAI2CLKOUT_CONFIG(RCC_PLLSAI2_SAI2CLK) != 0U)
\r
3478 #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
\r
3479 /* PLLSAI2M exists: apply PLLSAI2M divider for PLLSAI2 output computation */
\r
3480 /* f(PLLSAI2 Source) / PLLSAI2M */
\r
3481 pllvco = (pllvco / ((READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2M) >> RCC_PLLSAI2CFGR_PLLSAI2M_Pos) + 1U));
\r
3483 /* f(PLL Source) / PLLM */
\r
3484 pllvco = (pllvco / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1U));
\r
3486 /* f(PLLSAI2CLK) = f(VCOSAI2 input) * PLLSAI2N / PLLSAI2P */
\r
3487 plln = READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2N) >> RCC_PLLSAI2CFGR_PLLSAI2N_Pos;
\r
3488 #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
\r
3489 pllp = READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2PDIV) >> RCC_PLLSAI2CFGR_PLLSAI2PDIV_Pos;
\r
3493 if(READ_BIT(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2P) != 0U)
\r
3502 frequency = (pllvco * plln) / pllp;
\r
3506 #endif /* RCC_PLLSAI2_SUPPORT */
\r
3510 /* No clock source, frequency default init at 0 */
\r
3528 #endif /* HAL_RCC_MODULE_ENABLED */
\r
3537 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r