mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
186:707f6e361f3e
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 158:b23ee177fd68 1 /**
Kojto 158:b23ee177fd68 2 ******************************************************************************
Kojto 158:b23ee177fd68 3 * @file stm32l0xx_ll_rcc.c
Kojto 158:b23ee177fd68 4 * @author MCD Application Team
Kojto 158:b23ee177fd68 5 * @brief RCC LL module driver.
Kojto 158:b23ee177fd68 6 ******************************************************************************
Kojto 158:b23ee177fd68 7 * @attention
Kojto 158:b23ee177fd68 8 *
Kojto 158:b23ee177fd68 9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
Kojto 158:b23ee177fd68 10 *
Kojto 158:b23ee177fd68 11 * Redistribution and use in source and binary forms, with or without modification,
Kojto 158:b23ee177fd68 12 * are permitted provided that the following conditions are met:
Kojto 158:b23ee177fd68 13 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 158:b23ee177fd68 14 * this list of conditions and the following disclaimer.
Kojto 158:b23ee177fd68 15 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 158:b23ee177fd68 16 * this list of conditions and the following disclaimer in the documentation
Kojto 158:b23ee177fd68 17 * and/or other materials provided with the distribution.
Kojto 158:b23ee177fd68 18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 158:b23ee177fd68 19 * may be used to endorse or promote products derived from this software
Kojto 158:b23ee177fd68 20 * without specific prior written permission.
Kojto 158:b23ee177fd68 21 *
Kojto 158:b23ee177fd68 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 158:b23ee177fd68 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 158:b23ee177fd68 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 158:b23ee177fd68 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 158:b23ee177fd68 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 158:b23ee177fd68 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 158:b23ee177fd68 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 158:b23ee177fd68 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 158:b23ee177fd68 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 158:b23ee177fd68 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 158:b23ee177fd68 32 *
Kojto 158:b23ee177fd68 33 ******************************************************************************
Kojto 158:b23ee177fd68 34 */
Kojto 158:b23ee177fd68 35 #if defined(USE_FULL_LL_DRIVER)
Kojto 158:b23ee177fd68 36
Kojto 158:b23ee177fd68 37 /* Includes ------------------------------------------------------------------*/
Kojto 158:b23ee177fd68 38 #include "stm32l0xx_ll_rcc.h"
Kojto 158:b23ee177fd68 39 #ifdef USE_FULL_ASSERT
Kojto 158:b23ee177fd68 40 #include "stm32_assert.h"
Kojto 158:b23ee177fd68 41 #else
Kojto 158:b23ee177fd68 42 #define assert_param(expr) ((void)0U)
Kojto 158:b23ee177fd68 43 #endif /* USE_FULL_ASSERT */
Kojto 158:b23ee177fd68 44 /** @addtogroup STM32L0xx_LL_Driver
Kojto 158:b23ee177fd68 45 * @{
Kojto 158:b23ee177fd68 46 */
Kojto 158:b23ee177fd68 47
Kojto 158:b23ee177fd68 48 #if defined(RCC)
Kojto 158:b23ee177fd68 49
Kojto 158:b23ee177fd68 50 /** @defgroup RCC_LL RCC
Kojto 158:b23ee177fd68 51 * @{
Kojto 158:b23ee177fd68 52 */
Kojto 158:b23ee177fd68 53
Kojto 158:b23ee177fd68 54 /* Private types -------------------------------------------------------------*/
Kojto 158:b23ee177fd68 55 /* Private variables ---------------------------------------------------------*/
Kojto 158:b23ee177fd68 56
Kojto 158:b23ee177fd68 57 /* Private constants ---------------------------------------------------------*/
Kojto 158:b23ee177fd68 58 /* Private macros ------------------------------------------------------------*/
Kojto 158:b23ee177fd68 59 /** @addtogroup RCC_LL_Private_Macros
Kojto 158:b23ee177fd68 60 * @{
Kojto 158:b23ee177fd68 61 */
Kojto 158:b23ee177fd68 62 #if defined(RCC_CCIPR_USART1SEL) && defined(RCC_CCIPR_USART2SEL)
Kojto 158:b23ee177fd68 63 #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \
Kojto 158:b23ee177fd68 64 || ((__VALUE__) == LL_RCC_USART2_CLKSOURCE))
Kojto 158:b23ee177fd68 65 #elif defined(RCC_CCIPR_USART1SEL) && !defined(RCC_CCIPR_USART2SEL)
Kojto 158:b23ee177fd68 66 #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE))
Kojto 158:b23ee177fd68 67 #else
Kojto 158:b23ee177fd68 68 #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART2_CLKSOURCE))
Kojto 158:b23ee177fd68 69 #endif /* RCC_CCIPR_USART1SEL && RCC_CCIPR_USART2SEL */
Kojto 158:b23ee177fd68 70
Kojto 158:b23ee177fd68 71 #define IS_LL_RCC_LPUART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPUART1_CLKSOURCE))
Kojto 158:b23ee177fd68 72
Kojto 158:b23ee177fd68 73 #if defined(RCC_CCIPR_I2C3SEL)
Kojto 158:b23ee177fd68 74 #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \
Kojto 158:b23ee177fd68 75 || ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE))
Kojto 158:b23ee177fd68 76 #else
Kojto 158:b23ee177fd68 77 #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_I2C1_CLKSOURCE)
Kojto 158:b23ee177fd68 78 #endif /* RCC_CCIPR_I2C3SEL */
Kojto 158:b23ee177fd68 79
Kojto 158:b23ee177fd68 80 #define IS_LL_RCC_LPTIM_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_LPTIM1_CLKSOURCE)
Kojto 158:b23ee177fd68 81
Kojto 158:b23ee177fd68 82 #if defined(USB)
Kojto 158:b23ee177fd68 83 #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE))
Kojto 158:b23ee177fd68 84 #endif /* USB */
Kojto 158:b23ee177fd68 85
Kojto 158:b23ee177fd68 86 /**
Kojto 158:b23ee177fd68 87 * @}
Kojto 158:b23ee177fd68 88 */
Kojto 158:b23ee177fd68 89
Kojto 158:b23ee177fd68 90 /* Private function prototypes -----------------------------------------------*/
Kojto 158:b23ee177fd68 91 /** @defgroup RCC_LL_Private_Functions RCC Private functions
Kojto 158:b23ee177fd68 92 * @{
Kojto 158:b23ee177fd68 93 */
Kojto 158:b23ee177fd68 94 uint32_t RCC_GetSystemClockFreq(void);
Kojto 158:b23ee177fd68 95 uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency);
Kojto 158:b23ee177fd68 96 uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency);
Kojto 158:b23ee177fd68 97 uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency);
Kojto 158:b23ee177fd68 98 uint32_t RCC_PLL_GetFreqDomain_SYS(void);
Kojto 158:b23ee177fd68 99 /**
Kojto 158:b23ee177fd68 100 * @}
Kojto 158:b23ee177fd68 101 */
Kojto 158:b23ee177fd68 102
Kojto 158:b23ee177fd68 103
Kojto 158:b23ee177fd68 104 /* Exported functions --------------------------------------------------------*/
Kojto 158:b23ee177fd68 105 /** @addtogroup RCC_LL_Exported_Functions
Kojto 158:b23ee177fd68 106 * @{
Kojto 158:b23ee177fd68 107 */
Kojto 158:b23ee177fd68 108
Kojto 158:b23ee177fd68 109 /** @addtogroup RCC_LL_EF_Init
Kojto 158:b23ee177fd68 110 * @{
Kojto 158:b23ee177fd68 111 */
Kojto 158:b23ee177fd68 112
Kojto 158:b23ee177fd68 113 /**
Kojto 158:b23ee177fd68 114 * @brief Reset the RCC clock configuration to the default reset state.
Kojto 158:b23ee177fd68 115 * @note The default reset state of the clock configuration is given below:
Kojto 158:b23ee177fd68 116 * - MSI ON and used as system clock source
Kojto 158:b23ee177fd68 117 * - HSE, HSI and PLL OFF
Kojto 158:b23ee177fd68 118 * - AHB, APB1 and APB2 prescaler set to 1.
Kojto 158:b23ee177fd68 119 * - CSS, MCO OFF
Kojto 158:b23ee177fd68 120 * - All interrupts disabled
Kojto 158:b23ee177fd68 121 * @note This function doesn't modify the configuration of the
Kojto 158:b23ee177fd68 122 * - Peripheral clocks
Kojto 158:b23ee177fd68 123 * - LSI, LSE and RTC clocks
Kojto 158:b23ee177fd68 124 * @retval An ErrorStatus enumeration value:
Kojto 158:b23ee177fd68 125 * - SUCCESS: RCC registers are de-initialized
Kojto 158:b23ee177fd68 126 * - ERROR: not applicable
Kojto 158:b23ee177fd68 127 */
Kojto 158:b23ee177fd68 128 ErrorStatus LL_RCC_DeInit(void)
Kojto 158:b23ee177fd68 129 {
Kojto 158:b23ee177fd68 130 uint32_t vl_mask = 0U;
Kojto 158:b23ee177fd68 131
Kojto 158:b23ee177fd68 132 /* Set MSION bit */
Kojto 158:b23ee177fd68 133 LL_RCC_MSI_Enable();
Kojto 158:b23ee177fd68 134
Kojto 158:b23ee177fd68 135 /* Insure MSIRDY bit is set before writing default MSIRANGE value */
Kojto 158:b23ee177fd68 136 while (LL_RCC_MSI_IsReady() == 0U)
Kojto 158:b23ee177fd68 137 {
Kojto 158:b23ee177fd68 138 __NOP();
Kojto 158:b23ee177fd68 139 }
Kojto 158:b23ee177fd68 140
Kojto 158:b23ee177fd68 141 /* Set MSIRANGE default value */
Kojto 158:b23ee177fd68 142 LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_5);
Kojto 158:b23ee177fd68 143 /* Set MSITRIM bits to the reset value*/
Kojto 158:b23ee177fd68 144 LL_RCC_MSI_SetCalibTrimming(0U);
Kojto 158:b23ee177fd68 145
Kojto 158:b23ee177fd68 146 /* Set HSITRIM bits to the reset value*/
Kojto 158:b23ee177fd68 147 LL_RCC_HSI_SetCalibTrimming(0x10U);
Kojto 158:b23ee177fd68 148
Kojto 158:b23ee177fd68 149 /* Reset SW, HPRE, PPRE and MCOSEL bits */
Kojto 158:b23ee177fd68 150 vl_mask = 0xFFFFFFFFU;
Kojto 158:b23ee177fd68 151 CLEAR_BIT(vl_mask, (RCC_CFGR_SW | RCC_CFGR_HPRE | RCC_CFGR_PPRE1 | RCC_CFGR_PPRE2 | RCC_CFGR_MCOSEL));
Kojto 158:b23ee177fd68 152 LL_RCC_WriteReg(CFGR, vl_mask);
Kojto 158:b23ee177fd68 153
Kojto 158:b23ee177fd68 154 /* Reset HSI, HSE, PLL */
Kojto 158:b23ee177fd68 155 vl_mask = LL_RCC_ReadReg(CR);
Kojto 158:b23ee177fd68 156 #if defined(RCC_CR_HSIOUTEN)
Kojto 158:b23ee177fd68 157 CLEAR_BIT(vl_mask, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | RCC_CR_HSIOUTEN | \
Kojto 158:b23ee177fd68 158 RCC_CR_HSEON | RCC_CR_PLLON);
Kojto 158:b23ee177fd68 159 #else
Kojto 158:b23ee177fd68 160 CLEAR_BIT(vl_mask, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | \
Kojto 158:b23ee177fd68 161 RCC_CR_HSEON | RCC_CR_PLLON);
Kojto 158:b23ee177fd68 162 #endif
Kojto 158:b23ee177fd68 163 LL_RCC_WriteReg(CR, vl_mask);
Kojto 158:b23ee177fd68 164 /* Delay after an RCC peripheral clock */
Kojto 158:b23ee177fd68 165 vl_mask = LL_RCC_ReadReg(CR);
Kojto 158:b23ee177fd68 166
Kojto 158:b23ee177fd68 167 /* Reset HSEBYP bit */
Kojto 158:b23ee177fd68 168 LL_RCC_HSE_DisableBypass();
Kojto 158:b23ee177fd68 169
Kojto 158:b23ee177fd68 170 /* Set RCC_CR_RTCPRE to 0b00*/
Kojto 158:b23ee177fd68 171 CLEAR_BIT(vl_mask, RCC_CR_RTCPRE);
Kojto 158:b23ee177fd68 172 LL_RCC_WriteReg(CR, vl_mask);
Anna Bridge 186:707f6e361f3e 173
Kojto 158:b23ee177fd68 174 /* Reset CFGR register */
Kojto 158:b23ee177fd68 175 LL_RCC_WriteReg(CFGR, 0x00000000U);
Kojto 158:b23ee177fd68 176
Kojto 158:b23ee177fd68 177 #if defined(RCC_HSI48_SUPPORT)
Kojto 158:b23ee177fd68 178 /* Reset CRRCR register */
Kojto 158:b23ee177fd68 179 LL_RCC_WriteReg(CRRCR, 0x00000000U);
Kojto 158:b23ee177fd68 180
Kojto 158:b23ee177fd68 181 /* Disable HSI48 */
Kojto 158:b23ee177fd68 182 LL_RCC_HSI48_Disable();
Kojto 158:b23ee177fd68 183
Kojto 158:b23ee177fd68 184 #endif /*RCC_HSI48_SUPPORT*/
Kojto 158:b23ee177fd68 185
Kojto 158:b23ee177fd68 186 /* Disable all interrupts */
Kojto 158:b23ee177fd68 187 LL_RCC_WriteReg(CIER, 0x00000000U);
Kojto 158:b23ee177fd68 188
Kojto 158:b23ee177fd68 189 return SUCCESS;
Kojto 158:b23ee177fd68 190 }
Kojto 158:b23ee177fd68 191
Kojto 158:b23ee177fd68 192 /**
Kojto 158:b23ee177fd68 193 * @}
Kojto 158:b23ee177fd68 194 */
Kojto 158:b23ee177fd68 195
Kojto 158:b23ee177fd68 196 /** @addtogroup RCC_LL_EF_Get_Freq
Kojto 158:b23ee177fd68 197 * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks
Kojto 158:b23ee177fd68 198 * and different peripheral clocks available on the device.
Kojto 158:b23ee177fd68 199 * @note If SYSCLK source is MSI, function returns values based on MSI clock(*)
Kojto 158:b23ee177fd68 200 * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**)
Kojto 158:b23ee177fd68 201 * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***)
Kojto 158:b23ee177fd68 202 * @note If SYSCLK source is PLL, function returns values based on
Kojto 158:b23ee177fd68 203 * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
Kojto 158:b23ee177fd68 204 * @note (*) MSI clock depends on the selected MSI range but the real value
Kojto 158:b23ee177fd68 205 * may vary depending on the variations in voltage and temperature.
Kojto 158:b23ee177fd68 206 * @note (**) HSI_VALUE is a defined constant but the real value may vary
Kojto 158:b23ee177fd68 207 * depending on the variations in voltage and temperature.
Kojto 158:b23ee177fd68 208 * @note (***) HSE_VALUE is a defined constant, user has to ensure that
Kojto 158:b23ee177fd68 209 * HSE_VALUE is same as the real frequency of the crystal used.
Kojto 158:b23ee177fd68 210 * Otherwise, this function may have wrong result.
Kojto 158:b23ee177fd68 211 * @note The result of this function could be incorrect when using fractional
Kojto 158:b23ee177fd68 212 * value for HSE crystal.
Kojto 158:b23ee177fd68 213 * @note This function can be used by the user application to compute the
Kojto 158:b23ee177fd68 214 * baud-rate for the communication peripherals or configure other parameters.
Kojto 158:b23ee177fd68 215 * @{
Kojto 158:b23ee177fd68 216 */
Kojto 158:b23ee177fd68 217
Kojto 158:b23ee177fd68 218 /**
Kojto 158:b23ee177fd68 219 * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks
Kojto 158:b23ee177fd68 220 * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function
Kojto 158:b23ee177fd68 221 * must be called to update structure fields. Otherwise, any
Kojto 158:b23ee177fd68 222 * configuration based on this function will be incorrect.
Kojto 158:b23ee177fd68 223 * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies
Kojto 158:b23ee177fd68 224 * @retval None
Kojto 158:b23ee177fd68 225 */
Kojto 158:b23ee177fd68 226 void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks)
Kojto 158:b23ee177fd68 227 {
Kojto 158:b23ee177fd68 228 /* Get SYSCLK frequency */
Kojto 158:b23ee177fd68 229 RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq();
Kojto 158:b23ee177fd68 230
Kojto 158:b23ee177fd68 231 /* HCLK clock frequency */
Kojto 158:b23ee177fd68 232 RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency);
Kojto 158:b23ee177fd68 233
Kojto 158:b23ee177fd68 234 /* PCLK1 clock frequency */
Kojto 158:b23ee177fd68 235 RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency);
Kojto 158:b23ee177fd68 236
Kojto 158:b23ee177fd68 237 /* PCLK2 clock frequency */
Kojto 158:b23ee177fd68 238 RCC_Clocks->PCLK2_Frequency = RCC_GetPCLK2ClockFreq(RCC_Clocks->HCLK_Frequency);
Kojto 158:b23ee177fd68 239 }
Kojto 158:b23ee177fd68 240
Kojto 158:b23ee177fd68 241 /**
Kojto 158:b23ee177fd68 242 * @brief Return USARTx clock frequency
Kojto 158:b23ee177fd68 243 * @param USARTxSource This parameter can be one of the following values:
Kojto 158:b23ee177fd68 244 * @arg @ref LL_RCC_USART1_CLKSOURCE
Kojto 158:b23ee177fd68 245 * @arg @ref LL_RCC_USART2_CLKSOURCE (*)
Kojto 158:b23ee177fd68 246 *
Kojto 158:b23ee177fd68 247 * (*) value not defined in all devices.
Kojto 158:b23ee177fd68 248 * @retval USART clock frequency (in Hz)
Kojto 158:b23ee177fd68 249 * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
Kojto 158:b23ee177fd68 250 */
Kojto 158:b23ee177fd68 251 uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource)
Kojto 158:b23ee177fd68 252 {
Kojto 158:b23ee177fd68 253 uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
Kojto 158:b23ee177fd68 254
Kojto 158:b23ee177fd68 255 /* Check parameter */
Kojto 158:b23ee177fd68 256 assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource));
Kojto 158:b23ee177fd68 257 #if defined(RCC_CCIPR_USART1SEL)
Kojto 158:b23ee177fd68 258 if (USARTxSource == LL_RCC_USART1_CLKSOURCE)
Kojto 158:b23ee177fd68 259 {
Kojto 158:b23ee177fd68 260 /* USART1CLK clock frequency */
Kojto 158:b23ee177fd68 261 switch (LL_RCC_GetUSARTClockSource(USARTxSource))
Kojto 158:b23ee177fd68 262 {
Kojto 158:b23ee177fd68 263 case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */
Kojto 158:b23ee177fd68 264 usart_frequency = RCC_GetSystemClockFreq();
Kojto 158:b23ee177fd68 265 break;
Kojto 158:b23ee177fd68 266
Kojto 158:b23ee177fd68 267 case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */
Kojto 158:b23ee177fd68 268 if (LL_RCC_HSI_IsReady())
Kojto 158:b23ee177fd68 269 {
Kojto 158:b23ee177fd68 270 usart_frequency = HSI_VALUE;
Kojto 158:b23ee177fd68 271 }
Kojto 158:b23ee177fd68 272 break;
Kojto 158:b23ee177fd68 273
Kojto 158:b23ee177fd68 274 case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */
Kojto 158:b23ee177fd68 275 if (LL_RCC_LSE_IsReady())
Kojto 158:b23ee177fd68 276 {
Kojto 158:b23ee177fd68 277 usart_frequency = LSE_VALUE;
Kojto 158:b23ee177fd68 278 }
Kojto 158:b23ee177fd68 279 break;
Kojto 158:b23ee177fd68 280
Kojto 158:b23ee177fd68 281 case LL_RCC_USART1_CLKSOURCE_PCLK2: /* USART1 Clock is PCLK2 */
Kojto 158:b23ee177fd68 282 default:
Kojto 158:b23ee177fd68 283 usart_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
Kojto 158:b23ee177fd68 284 break;
Kojto 158:b23ee177fd68 285 }
Kojto 158:b23ee177fd68 286 }
Kojto 158:b23ee177fd68 287 #endif /* RCC_CCIPR_USART1SEL */
Kojto 158:b23ee177fd68 288
Kojto 158:b23ee177fd68 289 #if defined(RCC_CCIPR_USART2SEL)
Kojto 158:b23ee177fd68 290 if (USARTxSource == LL_RCC_USART2_CLKSOURCE)
Kojto 158:b23ee177fd68 291 {
Kojto 158:b23ee177fd68 292 /* USART2CLK clock frequency */
Kojto 158:b23ee177fd68 293 switch (LL_RCC_GetUSARTClockSource(USARTxSource))
Kojto 158:b23ee177fd68 294 {
Kojto 158:b23ee177fd68 295 case LL_RCC_USART2_CLKSOURCE_SYSCLK: /* USART2 Clock is System Clock */
Kojto 158:b23ee177fd68 296 usart_frequency = RCC_GetSystemClockFreq();
Kojto 158:b23ee177fd68 297 break;
Kojto 158:b23ee177fd68 298
Kojto 158:b23ee177fd68 299 case LL_RCC_USART2_CLKSOURCE_HSI: /* USART2 Clock is HSI Osc. */
Kojto 158:b23ee177fd68 300 if (LL_RCC_HSI_IsReady())
Kojto 158:b23ee177fd68 301 {
Kojto 158:b23ee177fd68 302 usart_frequency = HSI_VALUE;
Kojto 158:b23ee177fd68 303 }
Kojto 158:b23ee177fd68 304 break;
Kojto 158:b23ee177fd68 305
Kojto 158:b23ee177fd68 306 case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */
Kojto 158:b23ee177fd68 307 if (LL_RCC_LSE_IsReady())
Kojto 158:b23ee177fd68 308 {
Kojto 158:b23ee177fd68 309 usart_frequency = LSE_VALUE;
Kojto 158:b23ee177fd68 310 }
Kojto 158:b23ee177fd68 311 break;
Kojto 158:b23ee177fd68 312
Kojto 158:b23ee177fd68 313 case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */
Kojto 158:b23ee177fd68 314 default:
Kojto 158:b23ee177fd68 315 usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
Kojto 158:b23ee177fd68 316 break;
Kojto 158:b23ee177fd68 317 }
Kojto 158:b23ee177fd68 318 }
Kojto 158:b23ee177fd68 319 #endif /* RCC_CCIPR_USART2SEL */
Kojto 158:b23ee177fd68 320
Kojto 158:b23ee177fd68 321 return usart_frequency;
Kojto 158:b23ee177fd68 322 }
Kojto 158:b23ee177fd68 323
Kojto 158:b23ee177fd68 324 /**
Kojto 158:b23ee177fd68 325 * @brief Return I2Cx clock frequency
Kojto 158:b23ee177fd68 326 * @param I2CxSource This parameter can be one of the following values:
Kojto 158:b23ee177fd68 327 * @arg @ref LL_RCC_I2C1_CLKSOURCE
Kojto 158:b23ee177fd68 328 * @arg @ref LL_RCC_I2C3_CLKSOURCE (*)
Kojto 158:b23ee177fd68 329 *
Kojto 158:b23ee177fd68 330 * (*) value not defined in all devices
Kojto 158:b23ee177fd68 331 * @retval I2C clock frequency (in Hz)
Kojto 158:b23ee177fd68 332 * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready
Kojto 158:b23ee177fd68 333 */
Kojto 158:b23ee177fd68 334 uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource)
Kojto 158:b23ee177fd68 335 {
Kojto 158:b23ee177fd68 336 uint32_t i2c_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
Kojto 158:b23ee177fd68 337
Kojto 158:b23ee177fd68 338 /* Check parameter */
Kojto 158:b23ee177fd68 339 assert_param(IS_LL_RCC_I2C_CLKSOURCE(I2CxSource));
Kojto 158:b23ee177fd68 340
Kojto 158:b23ee177fd68 341 /* I2C1 CLK clock frequency */
Kojto 158:b23ee177fd68 342 if (I2CxSource == LL_RCC_I2C1_CLKSOURCE)
Kojto 158:b23ee177fd68 343 {
Kojto 158:b23ee177fd68 344 switch (LL_RCC_GetI2CClockSource(I2CxSource))
Kojto 158:b23ee177fd68 345 {
Kojto 158:b23ee177fd68 346 case LL_RCC_I2C1_CLKSOURCE_SYSCLK: /* I2C1 Clock is System Clock */
Kojto 158:b23ee177fd68 347 i2c_frequency = RCC_GetSystemClockFreq();
Kojto 158:b23ee177fd68 348 break;
Kojto 158:b23ee177fd68 349
Kojto 158:b23ee177fd68 350 case LL_RCC_I2C1_CLKSOURCE_HSI: /* I2C1 Clock is HSI Osc. */
Kojto 158:b23ee177fd68 351 if (LL_RCC_HSI_IsReady())
Kojto 158:b23ee177fd68 352 {
Kojto 158:b23ee177fd68 353 i2c_frequency = HSI_VALUE;
Kojto 158:b23ee177fd68 354 }
Kojto 158:b23ee177fd68 355 break;
Kojto 158:b23ee177fd68 356
Kojto 158:b23ee177fd68 357 case LL_RCC_I2C1_CLKSOURCE_PCLK1: /* I2C1 Clock is PCLK1 */
Kojto 158:b23ee177fd68 358 default:
Kojto 158:b23ee177fd68 359 i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
Kojto 158:b23ee177fd68 360 break;
Kojto 158:b23ee177fd68 361 }
Kojto 158:b23ee177fd68 362 }
Kojto 158:b23ee177fd68 363
Kojto 158:b23ee177fd68 364 #if defined(RCC_CCIPR_I2C3SEL)
Kojto 158:b23ee177fd68 365 /* I2C3 CLK clock frequency */
Kojto 158:b23ee177fd68 366 if (I2CxSource == LL_RCC_I2C3_CLKSOURCE)
Kojto 158:b23ee177fd68 367 {
Kojto 158:b23ee177fd68 368 switch (LL_RCC_GetI2CClockSource(I2CxSource))
Kojto 158:b23ee177fd68 369 {
Kojto 158:b23ee177fd68 370 case LL_RCC_I2C3_CLKSOURCE_SYSCLK: /* I2C3 Clock is System Clock */
Kojto 158:b23ee177fd68 371 i2c_frequency = RCC_GetSystemClockFreq();
Kojto 158:b23ee177fd68 372 break;
Kojto 158:b23ee177fd68 373
Kojto 158:b23ee177fd68 374 case LL_RCC_I2C3_CLKSOURCE_HSI: /* I2C3 Clock is HSI Osc. */
Kojto 158:b23ee177fd68 375 if (LL_RCC_HSI_IsReady())
Kojto 158:b23ee177fd68 376 {
Kojto 158:b23ee177fd68 377 i2c_frequency = HSI_VALUE;
Kojto 158:b23ee177fd68 378 }
Kojto 158:b23ee177fd68 379 break;
Kojto 158:b23ee177fd68 380
Kojto 158:b23ee177fd68 381 case LL_RCC_I2C3_CLKSOURCE_PCLK1: /* I2C3 Clock is PCLK1 */
Kojto 158:b23ee177fd68 382 default:
Kojto 158:b23ee177fd68 383 i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
Kojto 158:b23ee177fd68 384 break;
Kojto 158:b23ee177fd68 385 }
Kojto 158:b23ee177fd68 386 }
Kojto 158:b23ee177fd68 387 #endif /*RCC_CCIPR_I2C3SEL*/
Kojto 158:b23ee177fd68 388
Kojto 158:b23ee177fd68 389 return i2c_frequency;
Kojto 158:b23ee177fd68 390 }
Kojto 158:b23ee177fd68 391
Kojto 158:b23ee177fd68 392 /**
Kojto 158:b23ee177fd68 393 * @brief Return LPUARTx clock frequency
Kojto 158:b23ee177fd68 394 * @param LPUARTxSource This parameter can be one of the following values:
Kojto 158:b23ee177fd68 395 * @arg @ref LL_RCC_LPUART1_CLKSOURCE
Kojto 158:b23ee177fd68 396 * @retval LPUART clock frequency (in Hz)
Kojto 158:b23ee177fd68 397 * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
Kojto 158:b23ee177fd68 398 */
Kojto 158:b23ee177fd68 399 uint32_t LL_RCC_GetLPUARTClockFreq(uint32_t LPUARTxSource)
Kojto 158:b23ee177fd68 400 {
Kojto 158:b23ee177fd68 401 uint32_t lpuart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
Kojto 158:b23ee177fd68 402
Kojto 158:b23ee177fd68 403 /* Check parameter */
Kojto 158:b23ee177fd68 404 assert_param(IS_LL_RCC_LPUART_CLKSOURCE(LPUARTxSource));
Kojto 158:b23ee177fd68 405
Kojto 158:b23ee177fd68 406 /* LPUART1CLK clock frequency */
Kojto 158:b23ee177fd68 407 switch (LL_RCC_GetLPUARTClockSource(LPUARTxSource))
Kojto 158:b23ee177fd68 408 {
Kojto 158:b23ee177fd68 409 case LL_RCC_LPUART1_CLKSOURCE_SYSCLK: /* LPUART1 Clock is System Clock */
Kojto 158:b23ee177fd68 410 lpuart_frequency = RCC_GetSystemClockFreq();
Kojto 158:b23ee177fd68 411 break;
Kojto 158:b23ee177fd68 412
Kojto 158:b23ee177fd68 413 case LL_RCC_LPUART1_CLKSOURCE_HSI: /* LPUART1 Clock is HSI Osc. */
Kojto 158:b23ee177fd68 414 if (LL_RCC_HSI_IsReady())
Kojto 158:b23ee177fd68 415 {
Kojto 158:b23ee177fd68 416 lpuart_frequency = HSI_VALUE;
Kojto 158:b23ee177fd68 417 }
Kojto 158:b23ee177fd68 418 break;
Kojto 158:b23ee177fd68 419
Kojto 158:b23ee177fd68 420 case LL_RCC_LPUART1_CLKSOURCE_LSE: /* LPUART1 Clock is LSE Osc. */
Kojto 158:b23ee177fd68 421 if (LL_RCC_LSE_IsReady())
Kojto 158:b23ee177fd68 422 {
Kojto 158:b23ee177fd68 423 lpuart_frequency = LSE_VALUE;
Kojto 158:b23ee177fd68 424 }
Kojto 158:b23ee177fd68 425 break;
Kojto 158:b23ee177fd68 426
Kojto 158:b23ee177fd68 427 case LL_RCC_LPUART1_CLKSOURCE_PCLK1: /* LPUART1 Clock is PCLK1 */
Kojto 158:b23ee177fd68 428 default:
Kojto 158:b23ee177fd68 429 lpuart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
Kojto 158:b23ee177fd68 430 break;
Kojto 158:b23ee177fd68 431 }
Kojto 158:b23ee177fd68 432
Kojto 158:b23ee177fd68 433 return lpuart_frequency;
Kojto 158:b23ee177fd68 434 }
Kojto 158:b23ee177fd68 435
Kojto 158:b23ee177fd68 436 /**
Kojto 158:b23ee177fd68 437 * @brief Return LPTIMx clock frequency
Kojto 158:b23ee177fd68 438 * @param LPTIMxSource This parameter can be one of the following values:
Kojto 158:b23ee177fd68 439 * @arg @ref LL_RCC_LPTIM1_CLKSOURCE
Kojto 158:b23ee177fd68 440 * @retval LPTIM clock frequency (in Hz)
Kojto 158:b23ee177fd68 441 * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
Kojto 158:b23ee177fd68 442 */
Kojto 158:b23ee177fd68 443 uint32_t LL_RCC_GetLPTIMClockFreq(uint32_t LPTIMxSource)
Kojto 158:b23ee177fd68 444 {
Kojto 158:b23ee177fd68 445 uint32_t lptim_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
Kojto 158:b23ee177fd68 446
Kojto 158:b23ee177fd68 447 /* Check parameter */
Kojto 158:b23ee177fd68 448 assert_param(IS_LL_RCC_LPTIM_CLKSOURCE(LPTIMxSource));
Kojto 158:b23ee177fd68 449
Kojto 158:b23ee177fd68 450 if (LPTIMxSource == LL_RCC_LPTIM1_CLKSOURCE)
Kojto 158:b23ee177fd68 451 {
Kojto 158:b23ee177fd68 452 /* LPTIM1CLK clock frequency */
Kojto 158:b23ee177fd68 453 switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource))
Kojto 158:b23ee177fd68 454 {
Kojto 158:b23ee177fd68 455 case LL_RCC_LPTIM1_CLKSOURCE_LSI: /* LPTIM1 Clock is LSI Osc. */
Kojto 158:b23ee177fd68 456 if (LL_RCC_LSI_IsReady())
Kojto 158:b23ee177fd68 457 {
Kojto 158:b23ee177fd68 458 lptim_frequency = LSI_VALUE;
Kojto 158:b23ee177fd68 459 }
Kojto 158:b23ee177fd68 460 break;
Kojto 158:b23ee177fd68 461
Kojto 158:b23ee177fd68 462 case LL_RCC_LPTIM1_CLKSOURCE_HSI: /* LPTIM1 Clock is HSI Osc. */
Kojto 158:b23ee177fd68 463 if (LL_RCC_HSI_IsReady())
Kojto 158:b23ee177fd68 464 {
Kojto 158:b23ee177fd68 465 lptim_frequency = HSI_VALUE;
Kojto 158:b23ee177fd68 466 }
Kojto 158:b23ee177fd68 467 break;
Kojto 158:b23ee177fd68 468
Kojto 158:b23ee177fd68 469 case LL_RCC_LPTIM1_CLKSOURCE_LSE: /* LPTIM1 Clock is LSE Osc. */
Kojto 158:b23ee177fd68 470 if (LL_RCC_LSE_IsReady())
Kojto 158:b23ee177fd68 471 {
Kojto 158:b23ee177fd68 472 lptim_frequency = LSE_VALUE;
Kojto 158:b23ee177fd68 473 }
Kojto 158:b23ee177fd68 474 break;
Kojto 158:b23ee177fd68 475
Kojto 158:b23ee177fd68 476 case LL_RCC_LPTIM1_CLKSOURCE_PCLK1: /* LPTIM1 Clock is PCLK1 */
Kojto 158:b23ee177fd68 477 default:
Kojto 158:b23ee177fd68 478 lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
Kojto 158:b23ee177fd68 479 break;
Kojto 158:b23ee177fd68 480 }
Kojto 158:b23ee177fd68 481 }
Kojto 158:b23ee177fd68 482
Kojto 158:b23ee177fd68 483 return lptim_frequency;
Kojto 158:b23ee177fd68 484 }
Kojto 158:b23ee177fd68 485
Kojto 158:b23ee177fd68 486 #if defined(USB)
Kojto 158:b23ee177fd68 487 /**
Kojto 158:b23ee177fd68 488 * @brief Return USBx clock frequency
Kojto 158:b23ee177fd68 489 * @param USBxSource This parameter can be one of the following values:
Kojto 158:b23ee177fd68 490 * @arg @ref LL_RCC_USB_CLKSOURCE
Kojto 158:b23ee177fd68 491 * @retval USB clock frequency (in Hz)
Kojto 158:b23ee177fd68 492 * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI48) or PLL is not ready
Kojto 158:b23ee177fd68 493 * @arg @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
Kojto 158:b23ee177fd68 494 */
Kojto 158:b23ee177fd68 495 uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource)
Kojto 158:b23ee177fd68 496 {
Kojto 158:b23ee177fd68 497 uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
Kojto 158:b23ee177fd68 498
Kojto 158:b23ee177fd68 499 /* Check parameter */
Kojto 158:b23ee177fd68 500 assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource));
Kojto 158:b23ee177fd68 501
Kojto 158:b23ee177fd68 502 /* USBCLK clock frequency */
Kojto 158:b23ee177fd68 503 switch (LL_RCC_GetUSBClockSource(USBxSource))
Kojto 158:b23ee177fd68 504 {
Kojto 158:b23ee177fd68 505 case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */
Kojto 158:b23ee177fd68 506 if (LL_RCC_PLL_IsReady())
Kojto 158:b23ee177fd68 507 {
Kojto 158:b23ee177fd68 508 usb_frequency = RCC_PLL_GetFreqDomain_SYS();
Kojto 158:b23ee177fd68 509 }
Kojto 158:b23ee177fd68 510 break;
Kojto 158:b23ee177fd68 511
Kojto 158:b23ee177fd68 512 case LL_RCC_USB_CLKSOURCE_HSI48: /* HSI48 clock used as USB clock source */
Kojto 158:b23ee177fd68 513 default:
Kojto 158:b23ee177fd68 514 if (LL_RCC_HSI48_IsReady())
Kojto 158:b23ee177fd68 515 {
Kojto 158:b23ee177fd68 516 usb_frequency = HSI48_VALUE;
Kojto 158:b23ee177fd68 517 }
Kojto 158:b23ee177fd68 518 break;
Kojto 158:b23ee177fd68 519 }
Kojto 158:b23ee177fd68 520
Kojto 158:b23ee177fd68 521 return usb_frequency;
Kojto 158:b23ee177fd68 522 }
Kojto 158:b23ee177fd68 523 #endif /* USB */
Kojto 158:b23ee177fd68 524
Kojto 158:b23ee177fd68 525 /**
Kojto 158:b23ee177fd68 526 * @}
Kojto 158:b23ee177fd68 527 */
Kojto 158:b23ee177fd68 528
Kojto 158:b23ee177fd68 529 /**
Kojto 158:b23ee177fd68 530 * @}
Kojto 158:b23ee177fd68 531 */
Kojto 158:b23ee177fd68 532
Kojto 158:b23ee177fd68 533 /** @addtogroup RCC_LL_Private_Functions
Kojto 158:b23ee177fd68 534 * @{
Kojto 158:b23ee177fd68 535 */
Kojto 158:b23ee177fd68 536
Kojto 158:b23ee177fd68 537 /**
Kojto 158:b23ee177fd68 538 * @brief Return SYSTEM clock frequency
Kojto 158:b23ee177fd68 539 * @retval SYSTEM clock frequency (in Hz)
Kojto 158:b23ee177fd68 540 */
Kojto 158:b23ee177fd68 541 uint32_t RCC_GetSystemClockFreq(void)
Kojto 158:b23ee177fd68 542 {
Kojto 158:b23ee177fd68 543 uint32_t frequency = 0U;
Kojto 158:b23ee177fd68 544
Kojto 158:b23ee177fd68 545 /* Get SYSCLK source -------------------------------------------------------*/
Kojto 158:b23ee177fd68 546 switch (LL_RCC_GetSysClkSource())
Kojto 158:b23ee177fd68 547 {
Kojto 158:b23ee177fd68 548 case LL_RCC_SYS_CLKSOURCE_STATUS_MSI: /* MSI used as system clock source */
Kojto 158:b23ee177fd68 549 frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
Kojto 158:b23ee177fd68 550 break;
Kojto 158:b23ee177fd68 551
Kojto 158:b23ee177fd68 552 case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
Kojto 158:b23ee177fd68 553 frequency = HSI_VALUE;
Kojto 158:b23ee177fd68 554 break;
Kojto 158:b23ee177fd68 555
Kojto 158:b23ee177fd68 556 case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */
Kojto 158:b23ee177fd68 557 frequency = HSE_VALUE;
Kojto 158:b23ee177fd68 558 break;
Kojto 158:b23ee177fd68 559
Kojto 158:b23ee177fd68 560 case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */
Kojto 158:b23ee177fd68 561 frequency = RCC_PLL_GetFreqDomain_SYS();
Kojto 158:b23ee177fd68 562 break;
Kojto 158:b23ee177fd68 563
Kojto 158:b23ee177fd68 564 default:
Kojto 158:b23ee177fd68 565 frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
Kojto 158:b23ee177fd68 566 break;
Kojto 158:b23ee177fd68 567 }
Kojto 158:b23ee177fd68 568
Kojto 158:b23ee177fd68 569 return frequency;
Kojto 158:b23ee177fd68 570 }
Kojto 158:b23ee177fd68 571
Kojto 158:b23ee177fd68 572 /**
Kojto 158:b23ee177fd68 573 * @brief Return HCLK clock frequency
Kojto 158:b23ee177fd68 574 * @param SYSCLK_Frequency SYSCLK clock frequency
Kojto 158:b23ee177fd68 575 * @retval HCLK clock frequency (in Hz)
Kojto 158:b23ee177fd68 576 */
Kojto 158:b23ee177fd68 577 uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency)
Kojto 158:b23ee177fd68 578 {
Kojto 158:b23ee177fd68 579 /* HCLK clock frequency */
Kojto 158:b23ee177fd68 580 return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler());
Kojto 158:b23ee177fd68 581 }
Kojto 158:b23ee177fd68 582
Kojto 158:b23ee177fd68 583 /**
Kojto 158:b23ee177fd68 584 * @brief Return PCLK1 clock frequency
Kojto 158:b23ee177fd68 585 * @param HCLK_Frequency HCLK clock frequency
Kojto 158:b23ee177fd68 586 * @retval PCLK1 clock frequency (in Hz)
Kojto 158:b23ee177fd68 587 */
Kojto 158:b23ee177fd68 588 uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency)
Kojto 158:b23ee177fd68 589 {
Kojto 158:b23ee177fd68 590 /* PCLK1 clock frequency */
Kojto 158:b23ee177fd68 591 return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler());
Kojto 158:b23ee177fd68 592 }
Kojto 158:b23ee177fd68 593
Kojto 158:b23ee177fd68 594 /**
Kojto 158:b23ee177fd68 595 * @brief Return PCLK2 clock frequency
Kojto 158:b23ee177fd68 596 * @param HCLK_Frequency HCLK clock frequency
Kojto 158:b23ee177fd68 597 * @retval PCLK2 clock frequency (in Hz)
Kojto 158:b23ee177fd68 598 */
Kojto 158:b23ee177fd68 599 uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency)
Kojto 158:b23ee177fd68 600 {
Kojto 158:b23ee177fd68 601 /* PCLK2 clock frequency */
Kojto 158:b23ee177fd68 602 return __LL_RCC_CALC_PCLK2_FREQ(HCLK_Frequency, LL_RCC_GetAPB2Prescaler());
Kojto 158:b23ee177fd68 603 }
Kojto 158:b23ee177fd68 604
Kojto 158:b23ee177fd68 605 /**
Kojto 158:b23ee177fd68 606 * @brief Return PLL clock frequency used for system domain
Kojto 158:b23ee177fd68 607 * @retval PLL clock frequency (in Hz)
Kojto 158:b23ee177fd68 608 */
Kojto 158:b23ee177fd68 609 uint32_t RCC_PLL_GetFreqDomain_SYS(void)
Kojto 158:b23ee177fd68 610 {
Kojto 158:b23ee177fd68 611 uint32_t pllinputfreq = 0U, pllsource = 0U;
Kojto 158:b23ee177fd68 612
Kojto 158:b23ee177fd68 613 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL divider) * PLL Multiplicator */
Kojto 158:b23ee177fd68 614
Kojto 158:b23ee177fd68 615 /* Get PLL source */
Kojto 158:b23ee177fd68 616 pllsource = LL_RCC_PLL_GetMainSource();
Kojto 158:b23ee177fd68 617
Kojto 158:b23ee177fd68 618 switch (pllsource)
Kojto 158:b23ee177fd68 619 {
Kojto 158:b23ee177fd68 620 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
Kojto 158:b23ee177fd68 621 pllinputfreq = HSI_VALUE;
Kojto 158:b23ee177fd68 622 break;
Kojto 158:b23ee177fd68 623
Kojto 158:b23ee177fd68 624 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
Kojto 158:b23ee177fd68 625 pllinputfreq = HSE_VALUE;
Kojto 158:b23ee177fd68 626 break;
Kojto 158:b23ee177fd68 627
Kojto 158:b23ee177fd68 628 default:
Kojto 158:b23ee177fd68 629 pllinputfreq = HSI_VALUE;
Kojto 158:b23ee177fd68 630 break;
Kojto 158:b23ee177fd68 631 }
Kojto 158:b23ee177fd68 632 return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetMultiplicator(), LL_RCC_PLL_GetDivider());
Kojto 158:b23ee177fd68 633 }
Kojto 158:b23ee177fd68 634 /**
Kojto 158:b23ee177fd68 635 * @}
Kojto 158:b23ee177fd68 636 */
Kojto 158:b23ee177fd68 637
Kojto 158:b23ee177fd68 638 /**
Kojto 158:b23ee177fd68 639 * @}
Kojto 158:b23ee177fd68 640 */
Kojto 158:b23ee177fd68 641
Kojto 158:b23ee177fd68 642 #endif /* defined(RCC) */
Kojto 158:b23ee177fd68 643
Kojto 158:b23ee177fd68 644 /**
Kojto 158:b23ee177fd68 645 * @}
Kojto 158:b23ee177fd68 646 */
Kojto 158:b23ee177fd68 647
Kojto 158:b23ee177fd68 648 #endif /* USE_FULL_LL_DRIVER */
Kojto 158:b23ee177fd68 649
Kojto 158:b23ee177fd68 650 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/