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