annotate OtherSources/system_stm32f4xx_special_plus_256k.c @ 6:b355f462c952

... more clean
author JeanDo
date Fri, 15 Dec 2017 02:06:18 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
1 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
2 ******************************************************************************
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
3 * @file system_stm32f4xx.c
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
4 * @author MCD Application Team
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
5 * @version V1.1.0
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
6 * @date 17-February-2017
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
7 * @brief - CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
8 * - This file is dedicated only for STM32F29 NUCLEO 144 boards.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
9 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
10 * This file provides two functions and one global variable to be called from
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
11 * user application:
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
12 * - SystemInit(): This function is called at startup just after reset and
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
13 * before branch to main program. This call is made inside
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
14 * the "startup_stm32f4xx.s" file.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
15 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
16 * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
17 * by the user application to setup the SysTick
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
18 * timer or configure other parameters.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
19 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
20 * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
21 * be called whenever the core clock is changed
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
22 * during program execution.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
23 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
24 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
25 ******************************************************************************
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
26 * @attention
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
27 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
28 * <h2><center>&copy; COPYRIGHT 2017 STMicroelectronics</center></h2>
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
29 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
30 * Redistribution and use in source and binary forms, with or without modification,
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
31 * are permitted provided that the following conditions are met:
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
32 * 1. Redistributions of source code must retain the above copyright notice,
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
33 * this list of conditions and the following disclaimer.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
35 * this list of conditions and the following disclaimer in the documentation
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
36 * and/or other materials provided with the distribution.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
37 * 3. Neither the name of STMicroelectronics nor the names of its contributors
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
38 * may be used to endorse or promote products derived from this software
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
39 * without specific prior written permission.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
40 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
42 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
44 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
47 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
48 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
51 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
52 ******************************************************************************
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
53 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
54
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
55 /** @addtogroup CMSIS
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
56 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
57 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
58
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
59 /** @addtogroup stm32f4xx_system
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
60 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
61 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
62
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
63 /** @addtogroup STM32F4xx_System_Private_Includes
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
64 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
65 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
66
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
67
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
68 #include "stm32f4xx.h"
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
69
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
70 #if !defined (HSE_VALUE)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
71 #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
72 #endif /* HSE_VALUE */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
73
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
74 #if !defined (HSI_VALUE)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
75 #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
76 #endif /* HSI_VALUE */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
77
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
78 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
79 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
80 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
81
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
82 /** @addtogroup STM32F4xx_System_Private_TypesDefinitions
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
83 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
84 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
85
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
86 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
87 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
88 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
89
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
90 /** @addtogroup STM32F4xx_System_Private_Defines
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
91 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
92 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
93
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
94 /************************* Miscellaneous Configuration ************************/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
95 /*!< Uncomment the following line if you need to relocate your vector Table in
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
96 Internal SRAM. */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
97 /* #define VECT_TAB_SRAM */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
98 #define VECT_TAB_OFFSET 0x40000 /*!< Vector Table base offset field.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
99 This value must be a multiple of 0x200. */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
100 /******************************************************************************/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
101
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
102 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
103 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
104 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
105
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
106 /** @addtogroup STM32F4xx_System_Private_Macros
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
107 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
108 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
109
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
110 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
111 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
112 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
113
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
114 /** @addtogroup STM32F4xx_System_Private_Variables
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
115 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
116 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
117 /* This variable is updated in three ways:
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
118 1) by calling CMSIS function SystemCoreClockUpdate()
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
119 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
120 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
121 Note: If you use this function to configure the system clock; then there
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
122 is no need to call the 2 first functions listed above, since SystemCoreClock
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
123 variable is updated automatically.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
124 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
125 uint32_t SystemCoreClock = 16000000;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
126 const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
127 const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
128 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
129 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
130 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
131
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
132
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
133 /** @addtogroup STM32F4xx_System_Private_Functions
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
134 * @{
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
135 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
136
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
137 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
138 * @brief Setup the microcontroller system
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
139 * Initialize the FPU setting, vector table location and External memory
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
140 * configuration.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
141 * @param None
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
142 * @retval None
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
143 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
144 void SystemInit(void)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
145 {
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
146 /* FPU settings ------------------------------------------------------------*/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
147 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
148 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
149 #endif
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
150 /* Reset the RCC clock configuration to the default reset state ------------*/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
151 /* Set HSION bit */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
152 RCC->CR |= (uint32_t)0x00000001;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
153
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
154 /* Reset CFGR register */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
155 RCC->CFGR = 0x00000000;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
156
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
157 /* Reset HSEON, CSSON and PLLON bits */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
158 RCC->CR &= (uint32_t)0xFEF6FFFF;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
159
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
160 /* Reset PLLCFGR register */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
161 RCC->PLLCFGR = 0x24003010;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
162
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
163 /* Reset HSEBYP bit */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
164 RCC->CR &= (uint32_t)0xFFFBFFFF;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
165
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
166 /* Disable all interrupts */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
167 RCC->CIR = 0x00000000;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
168
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
169
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
170 /* Configure the Vector Table location add offset address ------------------*/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
171 #ifdef VECT_TAB_SRAM
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
172 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
173 #else
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
174 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
175 #endif
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
176 }
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
177
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
178 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
179 * @brief Update SystemCoreClock variable according to Clock Register Values.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
180 * The SystemCoreClock variable contains the core clock (HCLK), it can
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
181 * be used by the user application to setup the SysTick timer or configure
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
182 * other parameters.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
183 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
184 * @note Each time the core clock (HCLK) changes, this function must be called
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
185 * to update SystemCoreClock variable value. Otherwise, any configuration
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
186 * based on this variable will be incorrect.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
187 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
188 * @note - The system frequency computed by this function is not the real
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
189 * frequency in the chip. It is calculated based on the predefined
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
190 * constant and the selected clock source:
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
191 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
192 * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
193 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
194 * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
195 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
196 * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
197 * or HSI_VALUE(*) multiplied/divided by the PLL factors.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
198 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
199 * (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
200 * 16 MHz) but the real value may vary depending on the variations
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
201 * in voltage and temperature.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
202 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
203 * (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (its value
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
204 * depends on the application requirements), user has to ensure that HSE_VALUE
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
205 * is same as the real frequency of the crystal used. Otherwise, this function
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
206 * may have wrong result.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
207 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
208 * - The result of this function could be not correct when using fractional
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
209 * value for HSE crystal.
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
210 *
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
211 * @param None
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
212 * @retval None
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
213 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
214 void SystemCoreClockUpdate(void)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
215 {
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
216 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
217
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
218 /* Get SYSCLK source -------------------------------------------------------*/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
219 tmp = RCC->CFGR & RCC_CFGR_SWS;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
220
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
221 switch (tmp)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
222 {
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
223 case 0x00: /* HSI used as system clock source */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
224 SystemCoreClock = HSI_VALUE;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
225 break;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
226 case 0x04: /* HSE used as system clock source */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
227 SystemCoreClock = HSE_VALUE;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
228 break;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
229 case 0x08: /* PLL used as system clock source */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
230
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
231 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
232 SYSCLK = PLL_VCO / PLL_P
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
233 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
234 pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
235 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
236
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
237 if (pllsource != 0)
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
238 {
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
239 /* HSE used as PLL clock source */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
240 pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
241 }
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
242 else
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
243 {
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
244 /* HSI used as PLL clock source */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
245 pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
246 }
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
247
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
248 pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
249 SystemCoreClock = pllvco/pllp;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
250 break;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
251 default:
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
252 SystemCoreClock = HSI_VALUE;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
253 break;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
254 }
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
255 /* Compute HCLK frequency --------------------------------------------------*/
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
256 /* Get HCLK prescaler */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
257 tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
258 /* HCLK frequency */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
259 SystemCoreClock >>= tmp;
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
260 }
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
261
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
262 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
263 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
264 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
265
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
266 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
267 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
268 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
269
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
270 /**
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
271 * @}
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
272 */
b355f462c952 ... more clean
JeanDo
parents:
diff changeset
273 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/