SAKURA Internet / mbed-dev

Fork of mbed-dev by mbed official

Committer:
misodengaku
Date:
Wed Nov 29 06:30:35 2017 +0000
Revision:
178:7b4eb50f6890
Parent:
158:b23ee177fd68
sco-evb-01 patch

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