xref: /btstack/port/stm32-l476rg-nucleo-sx1280/Src/system_stm32l4xx.c (revision 6b8177c56d8d42c688f52897394f8b5eac7ee972)
1*6b8177c5SMatthias Ringwald /**
2*6b8177c5SMatthias Ringwald   ******************************************************************************
3*6b8177c5SMatthias Ringwald   * @file    system_stm32l4xx.c
4*6b8177c5SMatthias Ringwald   * @author  MCD Application Team
5*6b8177c5SMatthias Ringwald   * @brief   CMSIS Cortex-M4 Device Peripheral Access Layer System Source File
6*6b8177c5SMatthias Ringwald   *
7*6b8177c5SMatthias Ringwald   *   This file provides two functions and one global variable to be called from
8*6b8177c5SMatthias Ringwald   *   user application:
9*6b8177c5SMatthias Ringwald   *      - SystemInit(): This function is called at startup just after reset and
10*6b8177c5SMatthias Ringwald   *                      before branch to main program. This call is made inside
11*6b8177c5SMatthias Ringwald   *                      the "startup_stm32l4xx.s" file.
12*6b8177c5SMatthias Ringwald   *
13*6b8177c5SMatthias Ringwald   *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
14*6b8177c5SMatthias Ringwald   *                                  by the user application to setup the SysTick
15*6b8177c5SMatthias Ringwald   *                                  timer or configure other parameters.
16*6b8177c5SMatthias Ringwald   *
17*6b8177c5SMatthias Ringwald   *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
18*6b8177c5SMatthias Ringwald   *                                 be called whenever the core clock is changed
19*6b8177c5SMatthias Ringwald   *                                 during program execution.
20*6b8177c5SMatthias Ringwald   *
21*6b8177c5SMatthias Ringwald   *   After each device reset the MSI (4 MHz) is used as system clock source.
22*6b8177c5SMatthias Ringwald   *   Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to
23*6b8177c5SMatthias Ringwald   *   configure the system clock before to branch to main program.
24*6b8177c5SMatthias Ringwald   *
25*6b8177c5SMatthias Ringwald   *   This file configures the system clock as follows:
26*6b8177c5SMatthias Ringwald   *=============================================================================
27*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
28*6b8177c5SMatthias Ringwald   *        System Clock source                    | MSI
29*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
30*6b8177c5SMatthias Ringwald   *        SYSCLK(Hz)                             | 4000000
31*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
32*6b8177c5SMatthias Ringwald   *        HCLK(Hz)                               | 4000000
33*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
34*6b8177c5SMatthias Ringwald   *        AHB Prescaler                          | 1
35*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
36*6b8177c5SMatthias Ringwald   *        APB1 Prescaler                         | 1
37*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
38*6b8177c5SMatthias Ringwald   *        APB2 Prescaler                         | 1
39*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
40*6b8177c5SMatthias Ringwald   *        PLL_M                                  | 1
41*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
42*6b8177c5SMatthias Ringwald   *        PLL_N                                  | 8
43*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
44*6b8177c5SMatthias Ringwald   *        PLL_P                                  | 7
45*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
46*6b8177c5SMatthias Ringwald   *        PLL_Q                                  | 2
47*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
48*6b8177c5SMatthias Ringwald   *        PLL_R                                  | 2
49*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
50*6b8177c5SMatthias Ringwald   *        PLLSAI1_P                              | NA
51*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
52*6b8177c5SMatthias Ringwald   *        PLLSAI1_Q                              | NA
53*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
54*6b8177c5SMatthias Ringwald   *        PLLSAI1_R                              | NA
55*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
56*6b8177c5SMatthias Ringwald   *        PLLSAI2_P                              | NA
57*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
58*6b8177c5SMatthias Ringwald   *        PLLSAI2_Q                              | NA
59*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
60*6b8177c5SMatthias Ringwald   *        PLLSAI2_R                              | NA
61*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
62*6b8177c5SMatthias Ringwald   *        Require 48MHz for USB OTG FS,          | Disabled
63*6b8177c5SMatthias Ringwald   *        SDIO and RNG clock                     |
64*6b8177c5SMatthias Ringwald   *-----------------------------------------------------------------------------
65*6b8177c5SMatthias Ringwald   *=============================================================================
66*6b8177c5SMatthias Ringwald   ******************************************************************************
67*6b8177c5SMatthias Ringwald   * @attention
68*6b8177c5SMatthias Ringwald   *
69*6b8177c5SMatthias Ringwald   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
70*6b8177c5SMatthias Ringwald   * All rights reserved.</center></h2>
71*6b8177c5SMatthias Ringwald   *
72*6b8177c5SMatthias Ringwald   * This software component is licensed by ST under BSD 3-Clause license,
73*6b8177c5SMatthias Ringwald   * the "License"; You may not use this file except in compliance with the
74*6b8177c5SMatthias Ringwald   * License. You may obtain a copy of the License at:
75*6b8177c5SMatthias Ringwald   *                        opensource.org/licenses/BSD-3-Clause
76*6b8177c5SMatthias Ringwald   *
77*6b8177c5SMatthias Ringwald   ******************************************************************************
78*6b8177c5SMatthias Ringwald   */
79*6b8177c5SMatthias Ringwald 
80*6b8177c5SMatthias Ringwald /** @addtogroup CMSIS
81*6b8177c5SMatthias Ringwald   * @{
82*6b8177c5SMatthias Ringwald   */
83*6b8177c5SMatthias Ringwald 
84*6b8177c5SMatthias Ringwald /** @addtogroup stm32l4xx_system
85*6b8177c5SMatthias Ringwald   * @{
86*6b8177c5SMatthias Ringwald   */
87*6b8177c5SMatthias Ringwald 
88*6b8177c5SMatthias Ringwald /** @addtogroup STM32L4xx_System_Private_Includes
89*6b8177c5SMatthias Ringwald   * @{
90*6b8177c5SMatthias Ringwald   */
91*6b8177c5SMatthias Ringwald 
92*6b8177c5SMatthias Ringwald #include "stm32l4xx.h"
93*6b8177c5SMatthias Ringwald 
94*6b8177c5SMatthias Ringwald #if !defined  (HSE_VALUE)
95*6b8177c5SMatthias Ringwald   #define HSE_VALUE    8000000U  /*!< Value of the External oscillator in Hz */
96*6b8177c5SMatthias Ringwald #endif /* HSE_VALUE */
97*6b8177c5SMatthias Ringwald 
98*6b8177c5SMatthias Ringwald #if !defined  (MSI_VALUE)
99*6b8177c5SMatthias Ringwald   #define MSI_VALUE    4000000U  /*!< Value of the Internal oscillator in Hz*/
100*6b8177c5SMatthias Ringwald #endif /* MSI_VALUE */
101*6b8177c5SMatthias Ringwald 
102*6b8177c5SMatthias Ringwald #if !defined  (HSI_VALUE)
103*6b8177c5SMatthias Ringwald   #define HSI_VALUE    16000000U /*!< Value of the Internal oscillator in Hz*/
104*6b8177c5SMatthias Ringwald #endif /* HSI_VALUE */
105*6b8177c5SMatthias Ringwald 
106*6b8177c5SMatthias Ringwald /**
107*6b8177c5SMatthias Ringwald   * @}
108*6b8177c5SMatthias Ringwald   */
109*6b8177c5SMatthias Ringwald 
110*6b8177c5SMatthias Ringwald /** @addtogroup STM32L4xx_System_Private_TypesDefinitions
111*6b8177c5SMatthias Ringwald   * @{
112*6b8177c5SMatthias Ringwald   */
113*6b8177c5SMatthias Ringwald 
114*6b8177c5SMatthias Ringwald /**
115*6b8177c5SMatthias Ringwald   * @}
116*6b8177c5SMatthias Ringwald   */
117*6b8177c5SMatthias Ringwald 
118*6b8177c5SMatthias Ringwald /** @addtogroup STM32L4xx_System_Private_Defines
119*6b8177c5SMatthias Ringwald   * @{
120*6b8177c5SMatthias Ringwald   */
121*6b8177c5SMatthias Ringwald 
122*6b8177c5SMatthias Ringwald /************************* Miscellaneous Configuration ************************/
123*6b8177c5SMatthias Ringwald /*!< Uncomment the following line if you need to relocate your vector Table in
124*6b8177c5SMatthias Ringwald      Internal SRAM. */
125*6b8177c5SMatthias Ringwald /* #define VECT_TAB_SRAM */
126*6b8177c5SMatthias Ringwald #define VECT_TAB_OFFSET  0x00 /*!< Vector Table base offset field.
127*6b8177c5SMatthias Ringwald                                    This value must be a multiple of 0x200. */
128*6b8177c5SMatthias Ringwald /******************************************************************************/
129*6b8177c5SMatthias Ringwald /**
130*6b8177c5SMatthias Ringwald   * @}
131*6b8177c5SMatthias Ringwald   */
132*6b8177c5SMatthias Ringwald 
133*6b8177c5SMatthias Ringwald /** @addtogroup STM32L4xx_System_Private_Macros
134*6b8177c5SMatthias Ringwald   * @{
135*6b8177c5SMatthias Ringwald   */
136*6b8177c5SMatthias Ringwald 
137*6b8177c5SMatthias Ringwald /**
138*6b8177c5SMatthias Ringwald   * @}
139*6b8177c5SMatthias Ringwald   */
140*6b8177c5SMatthias Ringwald 
141*6b8177c5SMatthias Ringwald /** @addtogroup STM32L4xx_System_Private_Variables
142*6b8177c5SMatthias Ringwald   * @{
143*6b8177c5SMatthias Ringwald   */
144*6b8177c5SMatthias Ringwald   /* The SystemCoreClock variable is updated in three ways:
145*6b8177c5SMatthias Ringwald       1) by calling CMSIS function SystemCoreClockUpdate()
146*6b8177c5SMatthias Ringwald       2) by calling HAL API function HAL_RCC_GetHCLKFreq()
147*6b8177c5SMatthias Ringwald       3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
148*6b8177c5SMatthias Ringwald          Note: If you use this function to configure the system clock; then there
149*6b8177c5SMatthias Ringwald                is no need to call the 2 first functions listed above, since SystemCoreClock
150*6b8177c5SMatthias Ringwald                variable is updated automatically.
151*6b8177c5SMatthias Ringwald   */
152*6b8177c5SMatthias Ringwald   uint32_t SystemCoreClock = 4000000U;
153*6b8177c5SMatthias Ringwald 
154*6b8177c5SMatthias Ringwald   const uint8_t  AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
155*6b8177c5SMatthias Ringwald   const uint8_t  APBPrescTable[8] =  {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
156*6b8177c5SMatthias Ringwald   const uint32_t MSIRangeTable[12] = {100000U,   200000U,   400000U,   800000U,  1000000U,  2000000U, \
157*6b8177c5SMatthias Ringwald                                       4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U};
158*6b8177c5SMatthias Ringwald /**
159*6b8177c5SMatthias Ringwald   * @}
160*6b8177c5SMatthias Ringwald   */
161*6b8177c5SMatthias Ringwald 
162*6b8177c5SMatthias Ringwald /** @addtogroup STM32L4xx_System_Private_FunctionPrototypes
163*6b8177c5SMatthias Ringwald   * @{
164*6b8177c5SMatthias Ringwald   */
165*6b8177c5SMatthias Ringwald 
166*6b8177c5SMatthias Ringwald /**
167*6b8177c5SMatthias Ringwald   * @}
168*6b8177c5SMatthias Ringwald   */
169*6b8177c5SMatthias Ringwald 
170*6b8177c5SMatthias Ringwald /** @addtogroup STM32L4xx_System_Private_Functions
171*6b8177c5SMatthias Ringwald   * @{
172*6b8177c5SMatthias Ringwald   */
173*6b8177c5SMatthias Ringwald 
174*6b8177c5SMatthias Ringwald /**
175*6b8177c5SMatthias Ringwald   * @brief  Setup the microcontroller system.
176*6b8177c5SMatthias Ringwald   * @param  None
177*6b8177c5SMatthias Ringwald   * @retval None
178*6b8177c5SMatthias Ringwald   */
179*6b8177c5SMatthias Ringwald 
SystemInit(void)180*6b8177c5SMatthias Ringwald void SystemInit(void)
181*6b8177c5SMatthias Ringwald {
182*6b8177c5SMatthias Ringwald   /* FPU settings ------------------------------------------------------------*/
183*6b8177c5SMatthias Ringwald   #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
184*6b8177c5SMatthias Ringwald     SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
185*6b8177c5SMatthias Ringwald   #endif
186*6b8177c5SMatthias Ringwald 
187*6b8177c5SMatthias Ringwald   /* Reset the RCC clock configuration to the default reset state ------------*/
188*6b8177c5SMatthias Ringwald   /* Set MSION bit */
189*6b8177c5SMatthias Ringwald   RCC->CR |= RCC_CR_MSION;
190*6b8177c5SMatthias Ringwald 
191*6b8177c5SMatthias Ringwald   /* Reset CFGR register */
192*6b8177c5SMatthias Ringwald   RCC->CFGR = 0x00000000U;
193*6b8177c5SMatthias Ringwald 
194*6b8177c5SMatthias Ringwald   /* Reset HSEON, CSSON , HSION, and PLLON bits */
195*6b8177c5SMatthias Ringwald   RCC->CR &= 0xEAF6FFFFU;
196*6b8177c5SMatthias Ringwald 
197*6b8177c5SMatthias Ringwald   /* Reset PLLCFGR register */
198*6b8177c5SMatthias Ringwald   RCC->PLLCFGR = 0x00001000U;
199*6b8177c5SMatthias Ringwald 
200*6b8177c5SMatthias Ringwald   /* Reset HSEBYP bit */
201*6b8177c5SMatthias Ringwald   RCC->CR &= 0xFFFBFFFFU;
202*6b8177c5SMatthias Ringwald 
203*6b8177c5SMatthias Ringwald   /* Disable all interrupts */
204*6b8177c5SMatthias Ringwald   RCC->CIER = 0x00000000U;
205*6b8177c5SMatthias Ringwald 
206*6b8177c5SMatthias Ringwald   /* Configure the Vector Table location add offset address ------------------*/
207*6b8177c5SMatthias Ringwald #ifdef VECT_TAB_SRAM
208*6b8177c5SMatthias Ringwald   SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
209*6b8177c5SMatthias Ringwald #else
210*6b8177c5SMatthias Ringwald   SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
211*6b8177c5SMatthias Ringwald #endif
212*6b8177c5SMatthias Ringwald }
213*6b8177c5SMatthias Ringwald 
214*6b8177c5SMatthias Ringwald /**
215*6b8177c5SMatthias Ringwald   * @brief  Update SystemCoreClock variable according to Clock Register Values.
216*6b8177c5SMatthias Ringwald   *         The SystemCoreClock variable contains the core clock (HCLK), it can
217*6b8177c5SMatthias Ringwald   *         be used by the user application to setup the SysTick timer or configure
218*6b8177c5SMatthias Ringwald   *         other parameters.
219*6b8177c5SMatthias Ringwald   *
220*6b8177c5SMatthias Ringwald   * @note   Each time the core clock (HCLK) changes, this function must be called
221*6b8177c5SMatthias Ringwald   *         to update SystemCoreClock variable value. Otherwise, any configuration
222*6b8177c5SMatthias Ringwald   *         based on this variable will be incorrect.
223*6b8177c5SMatthias Ringwald   *
224*6b8177c5SMatthias Ringwald   * @note   - The system frequency computed by this function is not the real
225*6b8177c5SMatthias Ringwald   *           frequency in the chip. It is calculated based on the predefined
226*6b8177c5SMatthias Ringwald   *           constant and the selected clock source:
227*6b8177c5SMatthias Ringwald   *
228*6b8177c5SMatthias Ringwald   *           - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
229*6b8177c5SMatthias Ringwald   *
230*6b8177c5SMatthias Ringwald   *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
231*6b8177c5SMatthias Ringwald   *
232*6b8177c5SMatthias Ringwald   *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
233*6b8177c5SMatthias Ringwald   *
234*6b8177c5SMatthias Ringwald   *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
235*6b8177c5SMatthias Ringwald   *             or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
236*6b8177c5SMatthias Ringwald   *
237*6b8177c5SMatthias Ringwald   *         (*) MSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
238*6b8177c5SMatthias Ringwald   *             4 MHz) but the real value may vary depending on the variations
239*6b8177c5SMatthias Ringwald   *             in voltage and temperature.
240*6b8177c5SMatthias Ringwald   *
241*6b8177c5SMatthias Ringwald   *         (**) HSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
242*6b8177c5SMatthias Ringwald   *              16 MHz) but the real value may vary depending on the variations
243*6b8177c5SMatthias Ringwald   *              in voltage and temperature.
244*6b8177c5SMatthias Ringwald   *
245*6b8177c5SMatthias Ringwald   *         (***) HSE_VALUE is a constant defined in stm32l4xx_hal.h file (default value
246*6b8177c5SMatthias Ringwald   *              8 MHz), user has to ensure that HSE_VALUE is same as the real
247*6b8177c5SMatthias Ringwald   *              frequency of the crystal used. Otherwise, this function may
248*6b8177c5SMatthias Ringwald   *              have wrong result.
249*6b8177c5SMatthias Ringwald   *
250*6b8177c5SMatthias Ringwald   *         - The result of this function could be not correct when using fractional
251*6b8177c5SMatthias Ringwald   *           value for HSE crystal.
252*6b8177c5SMatthias Ringwald   *
253*6b8177c5SMatthias Ringwald   * @param  None
254*6b8177c5SMatthias Ringwald   * @retval None
255*6b8177c5SMatthias Ringwald   */
SystemCoreClockUpdate(void)256*6b8177c5SMatthias Ringwald void SystemCoreClockUpdate(void)
257*6b8177c5SMatthias Ringwald {
258*6b8177c5SMatthias Ringwald   uint32_t tmp = 0U, msirange = 0U, pllvco = 0U, pllr = 2U, pllsource = 0U, pllm = 2U;
259*6b8177c5SMatthias Ringwald 
260*6b8177c5SMatthias Ringwald   /* Get MSI Range frequency--------------------------------------------------*/
261*6b8177c5SMatthias Ringwald   if((RCC->CR & RCC_CR_MSIRGSEL) == RESET)
262*6b8177c5SMatthias Ringwald   { /* MSISRANGE from RCC_CSR applies */
263*6b8177c5SMatthias Ringwald     msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
264*6b8177c5SMatthias Ringwald   }
265*6b8177c5SMatthias Ringwald   else
266*6b8177c5SMatthias Ringwald   { /* MSIRANGE from RCC_CR applies */
267*6b8177c5SMatthias Ringwald     msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
268*6b8177c5SMatthias Ringwald   }
269*6b8177c5SMatthias Ringwald   /*MSI frequency range in HZ*/
270*6b8177c5SMatthias Ringwald   msirange = MSIRangeTable[msirange];
271*6b8177c5SMatthias Ringwald 
272*6b8177c5SMatthias Ringwald   /* Get SYSCLK source -------------------------------------------------------*/
273*6b8177c5SMatthias Ringwald   switch (RCC->CFGR & RCC_CFGR_SWS)
274*6b8177c5SMatthias Ringwald   {
275*6b8177c5SMatthias Ringwald     case 0x00:  /* MSI used as system clock source */
276*6b8177c5SMatthias Ringwald       SystemCoreClock = msirange;
277*6b8177c5SMatthias Ringwald       break;
278*6b8177c5SMatthias Ringwald 
279*6b8177c5SMatthias Ringwald     case 0x04:  /* HSI used as system clock source */
280*6b8177c5SMatthias Ringwald       SystemCoreClock = HSI_VALUE;
281*6b8177c5SMatthias Ringwald       break;
282*6b8177c5SMatthias Ringwald 
283*6b8177c5SMatthias Ringwald     case 0x08:  /* HSE used as system clock source */
284*6b8177c5SMatthias Ringwald       SystemCoreClock = HSE_VALUE;
285*6b8177c5SMatthias Ringwald       break;
286*6b8177c5SMatthias Ringwald 
287*6b8177c5SMatthias Ringwald     case 0x0C:  /* PLL used as system clock  source */
288*6b8177c5SMatthias Ringwald       /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
289*6b8177c5SMatthias Ringwald          SYSCLK = PLL_VCO / PLLR
290*6b8177c5SMatthias Ringwald          */
291*6b8177c5SMatthias Ringwald       pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
292*6b8177c5SMatthias Ringwald       pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U ;
293*6b8177c5SMatthias Ringwald 
294*6b8177c5SMatthias Ringwald       switch (pllsource)
295*6b8177c5SMatthias Ringwald       {
296*6b8177c5SMatthias Ringwald         case 0x02:  /* HSI used as PLL clock source */
297*6b8177c5SMatthias Ringwald           pllvco = (HSI_VALUE / pllm);
298*6b8177c5SMatthias Ringwald           break;
299*6b8177c5SMatthias Ringwald 
300*6b8177c5SMatthias Ringwald         case 0x03:  /* HSE used as PLL clock source */
301*6b8177c5SMatthias Ringwald           pllvco = (HSE_VALUE / pllm);
302*6b8177c5SMatthias Ringwald           break;
303*6b8177c5SMatthias Ringwald 
304*6b8177c5SMatthias Ringwald         default:    /* MSI used as PLL clock source */
305*6b8177c5SMatthias Ringwald           pllvco = (msirange / pllm);
306*6b8177c5SMatthias Ringwald           break;
307*6b8177c5SMatthias Ringwald       }
308*6b8177c5SMatthias Ringwald       pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U);
309*6b8177c5SMatthias Ringwald       pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U;
310*6b8177c5SMatthias Ringwald       SystemCoreClock = pllvco/pllr;
311*6b8177c5SMatthias Ringwald       break;
312*6b8177c5SMatthias Ringwald 
313*6b8177c5SMatthias Ringwald     default:
314*6b8177c5SMatthias Ringwald       SystemCoreClock = msirange;
315*6b8177c5SMatthias Ringwald       break;
316*6b8177c5SMatthias Ringwald   }
317*6b8177c5SMatthias Ringwald   /* Compute HCLK clock frequency --------------------------------------------*/
318*6b8177c5SMatthias Ringwald   /* Get HCLK prescaler */
319*6b8177c5SMatthias Ringwald   tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
320*6b8177c5SMatthias Ringwald   /* HCLK clock frequency */
321*6b8177c5SMatthias Ringwald   SystemCoreClock >>= tmp;
322*6b8177c5SMatthias Ringwald }
323*6b8177c5SMatthias Ringwald 
324*6b8177c5SMatthias Ringwald 
325*6b8177c5SMatthias Ringwald /**
326*6b8177c5SMatthias Ringwald   * @}
327*6b8177c5SMatthias Ringwald   */
328*6b8177c5SMatthias Ringwald 
329*6b8177c5SMatthias Ringwald /**
330*6b8177c5SMatthias Ringwald   * @}
331*6b8177c5SMatthias Ringwald   */
332*6b8177c5SMatthias Ringwald 
333*6b8177c5SMatthias Ringwald /**
334*6b8177c5SMatthias Ringwald   * @}
335*6b8177c5SMatthias Ringwald   */
336*6b8177c5SMatthias Ringwald 
337*6b8177c5SMatthias Ringwald /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
338