mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F030R8/system_stm32f0xx.c@106:ced8cbb51063, 2014-02-26 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Feb 26 09:45:12 2014 +0000
- Revision:
- 106:ced8cbb51063
- Parent:
- 76:aeb1df146756
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd
Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/
[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 76:aeb1df146756 | 1 | /** |
mbed_official | 76:aeb1df146756 | 2 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 3 | * @file system_stm32f0xx.c |
mbed_official | 76:aeb1df146756 | 4 | * @author MCD Application Team |
mbed_official | 76:aeb1df146756 | 5 | * @version V1.0.1 |
mbed_official | 76:aeb1df146756 | 6 | * @date 12-January-2014 |
mbed_official | 76:aeb1df146756 | 7 | * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File. |
mbed_official | 76:aeb1df146756 | 8 | * This file contains the system clock configuration for STM32F0xx devices, |
mbed_official | 76:aeb1df146756 | 9 | * and is generated by the clock configuration tool |
mbed_official | 76:aeb1df146756 | 10 | * STM32F0xx_Clock_Configuration_V1.0.1.xls |
mbed_official | 76:aeb1df146756 | 11 | * |
mbed_official | 76:aeb1df146756 | 12 | * 1. This file provides two functions and one global variable to be called from |
mbed_official | 76:aeb1df146756 | 13 | * user application: |
mbed_official | 76:aeb1df146756 | 14 | * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier |
mbed_official | 76:aeb1df146756 | 15 | * and Divider factors, AHB/APBx prescalers and Flash settings), |
mbed_official | 76:aeb1df146756 | 16 | * depending on the configuration made in the clock xls tool. |
mbed_official | 76:aeb1df146756 | 17 | * This function is called at startup just after reset and |
mbed_official | 76:aeb1df146756 | 18 | * before branch to main program. This call is made inside |
mbed_official | 76:aeb1df146756 | 19 | * the "startup_stm32f0xx.s" file. |
mbed_official | 76:aeb1df146756 | 20 | * |
mbed_official | 76:aeb1df146756 | 21 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used |
mbed_official | 76:aeb1df146756 | 22 | * by the user application to setup the SysTick |
mbed_official | 76:aeb1df146756 | 23 | * timer or configure other parameters. |
mbed_official | 76:aeb1df146756 | 24 | * |
mbed_official | 76:aeb1df146756 | 25 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must |
mbed_official | 76:aeb1df146756 | 26 | * be called whenever the core clock is changed |
mbed_official | 76:aeb1df146756 | 27 | * during program execution. |
mbed_official | 76:aeb1df146756 | 28 | * |
mbed_official | 76:aeb1df146756 | 29 | * 2. After each device reset the HSI (8 MHz Range) is used as system clock source. |
mbed_official | 76:aeb1df146756 | 30 | * Then SystemInit() function is called, in "startup_stm32f0xx.s" file, to |
mbed_official | 76:aeb1df146756 | 31 | * configure the system clock before to branch to main program. |
mbed_official | 76:aeb1df146756 | 32 | * |
mbed_official | 76:aeb1df146756 | 33 | * 3. If the system clock source selected by user fails to startup, the SystemInit() |
mbed_official | 76:aeb1df146756 | 34 | * function will do nothing and HSI still used as system clock source. User can |
mbed_official | 76:aeb1df146756 | 35 | * add some code to deal with this issue inside the SetSysClock() function. |
mbed_official | 76:aeb1df146756 | 36 | * |
mbed_official | 76:aeb1df146756 | 37 | * 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define |
mbed_official | 76:aeb1df146756 | 38 | * in "stm32f0xx.h" file. When HSE is used as system clock source, directly or |
mbed_official | 76:aeb1df146756 | 39 | * through PLL, and you are using different crystal you have to adapt the HSE |
mbed_official | 76:aeb1df146756 | 40 | * value to your own configuration. |
mbed_official | 76:aeb1df146756 | 41 | * |
mbed_official | 76:aeb1df146756 | 42 | * 5. This file configures the system clock as follows: |
mbed_official | 76:aeb1df146756 | 43 | *============================================================================= |
mbed_official | 76:aeb1df146756 | 44 | *============================================================================= |
mbed_official | 76:aeb1df146756 | 45 | * System Clock source | HSI |
mbed_official | 76:aeb1df146756 | 46 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 47 | * SYSCLK(Hz) | 8000000 |
mbed_official | 76:aeb1df146756 | 48 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 49 | * HCLK(Hz) | 8000000 |
mbed_official | 76:aeb1df146756 | 50 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 51 | * AHB Prescaler | 1 |
mbed_official | 76:aeb1df146756 | 52 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 53 | * APB Prescaler | 1 |
mbed_official | 76:aeb1df146756 | 54 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 55 | * HSE Frequency(Hz) | NA |
mbed_official | 76:aeb1df146756 | 56 | *---------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 57 | * PLLMUL | NA |
mbed_official | 76:aeb1df146756 | 58 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 59 | * PREDIV | NA |
mbed_official | 76:aeb1df146756 | 60 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 61 | * Flash Latency(WS) | 0 |
mbed_official | 76:aeb1df146756 | 62 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 63 | * Prefetch Buffer | ON |
mbed_official | 76:aeb1df146756 | 64 | *----------------------------------------------------------------------------- |
mbed_official | 76:aeb1df146756 | 65 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 66 | * @attention |
mbed_official | 76:aeb1df146756 | 67 | * |
mbed_official | 106:ced8cbb51063 | 68 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 69 | * |
mbed_official | 106:ced8cbb51063 | 70 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 106:ced8cbb51063 | 71 | * are permitted provided that the following conditions are met: |
mbed_official | 106:ced8cbb51063 | 72 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 73 | * this list of conditions and the following disclaimer. |
mbed_official | 106:ced8cbb51063 | 74 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 75 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 106:ced8cbb51063 | 76 | * and/or other materials provided with the distribution. |
mbed_official | 106:ced8cbb51063 | 77 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 106:ced8cbb51063 | 78 | * may be used to endorse or promote products derived from this software |
mbed_official | 106:ced8cbb51063 | 79 | * without specific prior written permission. |
mbed_official | 76:aeb1df146756 | 80 | * |
mbed_official | 106:ced8cbb51063 | 81 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 106:ced8cbb51063 | 82 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 106:ced8cbb51063 | 83 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 106:ced8cbb51063 | 84 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 106:ced8cbb51063 | 85 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 106:ced8cbb51063 | 86 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 106:ced8cbb51063 | 87 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 106:ced8cbb51063 | 88 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 106:ced8cbb51063 | 89 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 106:ced8cbb51063 | 90 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 76:aeb1df146756 | 91 | * |
mbed_official | 76:aeb1df146756 | 92 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 93 | */ |
mbed_official | 76:aeb1df146756 | 94 | |
mbed_official | 76:aeb1df146756 | 95 | /** @addtogroup CMSIS |
mbed_official | 76:aeb1df146756 | 96 | * @{ |
mbed_official | 76:aeb1df146756 | 97 | */ |
mbed_official | 76:aeb1df146756 | 98 | |
mbed_official | 76:aeb1df146756 | 99 | /** @addtogroup stm32f0xx_system |
mbed_official | 76:aeb1df146756 | 100 | * @{ |
mbed_official | 76:aeb1df146756 | 101 | */ |
mbed_official | 76:aeb1df146756 | 102 | |
mbed_official | 76:aeb1df146756 | 103 | /** @addtogroup STM32F0xx_System_Private_Includes |
mbed_official | 76:aeb1df146756 | 104 | * @{ |
mbed_official | 76:aeb1df146756 | 105 | */ |
mbed_official | 76:aeb1df146756 | 106 | |
mbed_official | 76:aeb1df146756 | 107 | #include "stm32f0xx.h" |
mbed_official | 76:aeb1df146756 | 108 | |
mbed_official | 76:aeb1df146756 | 109 | /** |
mbed_official | 76:aeb1df146756 | 110 | * @} |
mbed_official | 76:aeb1df146756 | 111 | */ |
mbed_official | 76:aeb1df146756 | 112 | |
mbed_official | 76:aeb1df146756 | 113 | /** @addtogroup STM32F0xx_System_Private_TypesDefinitions |
mbed_official | 76:aeb1df146756 | 114 | * @{ |
mbed_official | 76:aeb1df146756 | 115 | */ |
mbed_official | 76:aeb1df146756 | 116 | |
mbed_official | 76:aeb1df146756 | 117 | /** |
mbed_official | 76:aeb1df146756 | 118 | * @} |
mbed_official | 76:aeb1df146756 | 119 | */ |
mbed_official | 76:aeb1df146756 | 120 | |
mbed_official | 76:aeb1df146756 | 121 | /** @addtogroup STM32F0xx_System_Private_Defines |
mbed_official | 76:aeb1df146756 | 122 | * @{ |
mbed_official | 76:aeb1df146756 | 123 | */ |
mbed_official | 76:aeb1df146756 | 124 | /** |
mbed_official | 76:aeb1df146756 | 125 | * @} |
mbed_official | 76:aeb1df146756 | 126 | */ |
mbed_official | 76:aeb1df146756 | 127 | |
mbed_official | 76:aeb1df146756 | 128 | /** @addtogroup STM32F0xx_System_Private_Macros |
mbed_official | 76:aeb1df146756 | 129 | * @{ |
mbed_official | 76:aeb1df146756 | 130 | */ |
mbed_official | 76:aeb1df146756 | 131 | |
mbed_official | 76:aeb1df146756 | 132 | /** |
mbed_official | 76:aeb1df146756 | 133 | * @} |
mbed_official | 76:aeb1df146756 | 134 | */ |
mbed_official | 76:aeb1df146756 | 135 | |
mbed_official | 76:aeb1df146756 | 136 | /** @addtogroup STM32F0xx_System_Private_Variables |
mbed_official | 76:aeb1df146756 | 137 | * @{ |
mbed_official | 76:aeb1df146756 | 138 | */ |
mbed_official | 76:aeb1df146756 | 139 | uint32_t SystemCoreClock = 8000000; |
mbed_official | 76:aeb1df146756 | 140 | __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; |
mbed_official | 76:aeb1df146756 | 141 | |
mbed_official | 76:aeb1df146756 | 142 | /** |
mbed_official | 76:aeb1df146756 | 143 | * @} |
mbed_official | 76:aeb1df146756 | 144 | */ |
mbed_official | 76:aeb1df146756 | 145 | |
mbed_official | 76:aeb1df146756 | 146 | /** @addtogroup STM32F0xx_System_Private_FunctionPrototypes |
mbed_official | 76:aeb1df146756 | 147 | * @{ |
mbed_official | 76:aeb1df146756 | 148 | */ |
mbed_official | 76:aeb1df146756 | 149 | |
mbed_official | 76:aeb1df146756 | 150 | static void SetSysClock(void); |
mbed_official | 76:aeb1df146756 | 151 | |
mbed_official | 76:aeb1df146756 | 152 | /** |
mbed_official | 76:aeb1df146756 | 153 | * @} |
mbed_official | 76:aeb1df146756 | 154 | */ |
mbed_official | 76:aeb1df146756 | 155 | |
mbed_official | 76:aeb1df146756 | 156 | /** @addtogroup STM32F0xx_System_Private_Functions |
mbed_official | 76:aeb1df146756 | 157 | * @{ |
mbed_official | 76:aeb1df146756 | 158 | */ |
mbed_official | 76:aeb1df146756 | 159 | |
mbed_official | 76:aeb1df146756 | 160 | /** |
mbed_official | 76:aeb1df146756 | 161 | * @brief Setup the microcontroller system. |
mbed_official | 76:aeb1df146756 | 162 | * Initialize the Embedded Flash Interface, the PLL and update the |
mbed_official | 76:aeb1df146756 | 163 | * SystemCoreClock variable. |
mbed_official | 76:aeb1df146756 | 164 | * @param None |
mbed_official | 76:aeb1df146756 | 165 | * @retval None |
mbed_official | 76:aeb1df146756 | 166 | */ |
mbed_official | 76:aeb1df146756 | 167 | void SystemInit (void) |
mbed_official | 76:aeb1df146756 | 168 | { |
mbed_official | 76:aeb1df146756 | 169 | /* Set HSION bit */ |
mbed_official | 76:aeb1df146756 | 170 | RCC->CR |= (uint32_t)0x00000001; |
mbed_official | 76:aeb1df146756 | 171 | |
mbed_official | 76:aeb1df146756 | 172 | /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE and MCOSEL[2:0] bits */ |
mbed_official | 76:aeb1df146756 | 173 | RCC->CFGR &= (uint32_t)0xF8FFB80C; |
mbed_official | 76:aeb1df146756 | 174 | |
mbed_official | 76:aeb1df146756 | 175 | /* Reset HSEON, CSSON and PLLON bits */ |
mbed_official | 76:aeb1df146756 | 176 | RCC->CR &= (uint32_t)0xFEF6FFFF; |
mbed_official | 76:aeb1df146756 | 177 | |
mbed_official | 76:aeb1df146756 | 178 | /* Reset HSEBYP bit */ |
mbed_official | 76:aeb1df146756 | 179 | RCC->CR &= (uint32_t)0xFFFBFFFF; |
mbed_official | 76:aeb1df146756 | 180 | |
mbed_official | 76:aeb1df146756 | 181 | /* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */ |
mbed_official | 76:aeb1df146756 | 182 | RCC->CFGR &= (uint32_t)0xFFC0FFFF; |
mbed_official | 76:aeb1df146756 | 183 | |
mbed_official | 76:aeb1df146756 | 184 | /* Reset PREDIV1[3:0] bits */ |
mbed_official | 76:aeb1df146756 | 185 | RCC->CFGR2 &= (uint32_t)0xFFFFFFF0; |
mbed_official | 76:aeb1df146756 | 186 | |
mbed_official | 76:aeb1df146756 | 187 | /* Reset USARTSW[1:0], I2CSW, CECSW and ADCSW bits */ |
mbed_official | 76:aeb1df146756 | 188 | RCC->CFGR3 &= (uint32_t)0xFFFFFEAC; |
mbed_official | 76:aeb1df146756 | 189 | |
mbed_official | 76:aeb1df146756 | 190 | /* Reset HSI14 bit */ |
mbed_official | 76:aeb1df146756 | 191 | RCC->CR2 &= (uint32_t)0xFFFFFFFE; |
mbed_official | 76:aeb1df146756 | 192 | |
mbed_official | 76:aeb1df146756 | 193 | /* Disable all interrupts */ |
mbed_official | 76:aeb1df146756 | 194 | RCC->CIR = 0x00000000; |
mbed_official | 76:aeb1df146756 | 195 | |
mbed_official | 76:aeb1df146756 | 196 | /* Configure the System clock frequency, AHB/APBx prescalers and Flash settings */ |
mbed_official | 76:aeb1df146756 | 197 | SetSysClock(); |
mbed_official | 76:aeb1df146756 | 198 | } |
mbed_official | 76:aeb1df146756 | 199 | |
mbed_official | 76:aeb1df146756 | 200 | /** |
mbed_official | 76:aeb1df146756 | 201 | * @brief Update SystemCoreClock according to Clock Register Values |
mbed_official | 76:aeb1df146756 | 202 | * The SystemCoreClock variable contains the core clock (HCLK), it can |
mbed_official | 76:aeb1df146756 | 203 | * be used by the user application to setup the SysTick timer or configure |
mbed_official | 76:aeb1df146756 | 204 | * other parameters. |
mbed_official | 76:aeb1df146756 | 205 | * |
mbed_official | 76:aeb1df146756 | 206 | * @note Each time the core clock (HCLK) changes, this function must be called |
mbed_official | 76:aeb1df146756 | 207 | * to update SystemCoreClock variable value. Otherwise, any configuration |
mbed_official | 76:aeb1df146756 | 208 | * based on this variable will be incorrect. |
mbed_official | 76:aeb1df146756 | 209 | * |
mbed_official | 76:aeb1df146756 | 210 | * @note - The system frequency computed by this function is not the real |
mbed_official | 76:aeb1df146756 | 211 | * frequency in the chip. It is calculated based on the predefined |
mbed_official | 76:aeb1df146756 | 212 | * constant and the selected clock source: |
mbed_official | 76:aeb1df146756 | 213 | * |
mbed_official | 76:aeb1df146756 | 214 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) |
mbed_official | 76:aeb1df146756 | 215 | * |
mbed_official | 76:aeb1df146756 | 216 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) |
mbed_official | 76:aeb1df146756 | 217 | * |
mbed_official | 76:aeb1df146756 | 218 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) |
mbed_official | 76:aeb1df146756 | 219 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. |
mbed_official | 76:aeb1df146756 | 220 | * |
mbed_official | 76:aeb1df146756 | 221 | * (*) HSI_VALUE is a constant defined in stm32f0xx.h file (default value |
mbed_official | 76:aeb1df146756 | 222 | * 8 MHz) but the real value may vary depending on the variations |
mbed_official | 76:aeb1df146756 | 223 | * in voltage and temperature. |
mbed_official | 76:aeb1df146756 | 224 | * |
mbed_official | 76:aeb1df146756 | 225 | * (**) HSE_VALUE is a constant defined in stm32f0xx.h file (default value |
mbed_official | 76:aeb1df146756 | 226 | * 8 MHz), user has to ensure that HSE_VALUE is same as the real |
mbed_official | 76:aeb1df146756 | 227 | * frequency of the crystal used. Otherwise, this function may |
mbed_official | 76:aeb1df146756 | 228 | * have wrong result. |
mbed_official | 76:aeb1df146756 | 229 | * |
mbed_official | 76:aeb1df146756 | 230 | * - The result of this function could be not correct when using fractional |
mbed_official | 76:aeb1df146756 | 231 | * value for HSE crystal. |
mbed_official | 76:aeb1df146756 | 232 | * @param None |
mbed_official | 76:aeb1df146756 | 233 | * @retval None |
mbed_official | 76:aeb1df146756 | 234 | */ |
mbed_official | 76:aeb1df146756 | 235 | void SystemCoreClockUpdate (void) |
mbed_official | 76:aeb1df146756 | 236 | { |
mbed_official | 76:aeb1df146756 | 237 | uint32_t tmp = 0, pllmull = 0, pllsource = 0, prediv1factor = 0; |
mbed_official | 76:aeb1df146756 | 238 | |
mbed_official | 76:aeb1df146756 | 239 | /* Get SYSCLK source -------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 240 | tmp = RCC->CFGR & RCC_CFGR_SWS; |
mbed_official | 76:aeb1df146756 | 241 | |
mbed_official | 76:aeb1df146756 | 242 | switch (tmp) |
mbed_official | 76:aeb1df146756 | 243 | { |
mbed_official | 76:aeb1df146756 | 244 | case 0x00: /* HSI used as system clock */ |
mbed_official | 76:aeb1df146756 | 245 | SystemCoreClock = HSI_VALUE; |
mbed_official | 76:aeb1df146756 | 246 | break; |
mbed_official | 76:aeb1df146756 | 247 | case 0x04: /* HSE used as system clock */ |
mbed_official | 76:aeb1df146756 | 248 | SystemCoreClock = HSE_VALUE; |
mbed_official | 76:aeb1df146756 | 249 | break; |
mbed_official | 76:aeb1df146756 | 250 | case 0x08: /* PLL used as system clock */ |
mbed_official | 76:aeb1df146756 | 251 | /* Get PLL clock source and multiplication factor ----------------------*/ |
mbed_official | 76:aeb1df146756 | 252 | pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; |
mbed_official | 76:aeb1df146756 | 253 | pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; |
mbed_official | 76:aeb1df146756 | 254 | pllmull = ( pllmull >> 18) + 2; |
mbed_official | 76:aeb1df146756 | 255 | |
mbed_official | 76:aeb1df146756 | 256 | if (pllsource == 0x00) |
mbed_official | 76:aeb1df146756 | 257 | { |
mbed_official | 76:aeb1df146756 | 258 | /* HSI oscillator clock divided by 2 selected as PLL clock entry */ |
mbed_official | 76:aeb1df146756 | 259 | SystemCoreClock = (HSI_VALUE >> 1) * pllmull; |
mbed_official | 76:aeb1df146756 | 260 | } |
mbed_official | 76:aeb1df146756 | 261 | else |
mbed_official | 76:aeb1df146756 | 262 | { |
mbed_official | 76:aeb1df146756 | 263 | prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; |
mbed_official | 76:aeb1df146756 | 264 | /* HSE oscillator clock selected as PREDIV1 clock entry */ |
mbed_official | 76:aeb1df146756 | 265 | SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; |
mbed_official | 76:aeb1df146756 | 266 | } |
mbed_official | 76:aeb1df146756 | 267 | break; |
mbed_official | 76:aeb1df146756 | 268 | default: /* HSI used as system clock */ |
mbed_official | 76:aeb1df146756 | 269 | SystemCoreClock = HSI_VALUE; |
mbed_official | 76:aeb1df146756 | 270 | break; |
mbed_official | 76:aeb1df146756 | 271 | } |
mbed_official | 76:aeb1df146756 | 272 | /* Compute HCLK clock frequency ----------------*/ |
mbed_official | 76:aeb1df146756 | 273 | /* Get HCLK prescaler */ |
mbed_official | 76:aeb1df146756 | 274 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; |
mbed_official | 76:aeb1df146756 | 275 | /* HCLK clock frequency */ |
mbed_official | 76:aeb1df146756 | 276 | SystemCoreClock >>= tmp; |
mbed_official | 76:aeb1df146756 | 277 | } |
mbed_official | 76:aeb1df146756 | 278 | |
mbed_official | 76:aeb1df146756 | 279 | /** |
mbed_official | 76:aeb1df146756 | 280 | * @brief Configures the System clock frequency, AHB/APBx prescalers and Flash |
mbed_official | 76:aeb1df146756 | 281 | * settings. |
mbed_official | 76:aeb1df146756 | 282 | * @note This function should be called only once the RCC clock configuration |
mbed_official | 76:aeb1df146756 | 283 | * is reset to the default reset state (done in SystemInit() function). |
mbed_official | 76:aeb1df146756 | 284 | * @param None |
mbed_official | 76:aeb1df146756 | 285 | * @retval None |
mbed_official | 76:aeb1df146756 | 286 | */ |
mbed_official | 76:aeb1df146756 | 287 | static void SetSysClock(void) |
mbed_official | 76:aeb1df146756 | 288 | { |
mbed_official | 76:aeb1df146756 | 289 | /******************************************************************************/ |
mbed_official | 76:aeb1df146756 | 290 | /* HSI used as System clock source */ |
mbed_official | 76:aeb1df146756 | 291 | /******************************************************************************/ |
mbed_official | 76:aeb1df146756 | 292 | |
mbed_official | 76:aeb1df146756 | 293 | /* At this stage the HSI is already enabled and used as System clock source */ |
mbed_official | 76:aeb1df146756 | 294 | |
mbed_official | 76:aeb1df146756 | 295 | /* Enable Prefetch Buffer and Flash 0 wait state */ |
mbed_official | 76:aeb1df146756 | 296 | FLASH->ACR = FLASH_ACR_PRFTBE; |
mbed_official | 76:aeb1df146756 | 297 | |
mbed_official | 76:aeb1df146756 | 298 | /* HCLK = SYSCLK / 1 */ |
mbed_official | 76:aeb1df146756 | 299 | RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; |
mbed_official | 76:aeb1df146756 | 300 | |
mbed_official | 76:aeb1df146756 | 301 | /* PCLK = HCLK / 1 */ |
mbed_official | 76:aeb1df146756 | 302 | RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1; |
mbed_official | 76:aeb1df146756 | 303 | |
mbed_official | 76:aeb1df146756 | 304 | } |
mbed_official | 76:aeb1df146756 | 305 | |
mbed_official | 76:aeb1df146756 | 306 | /** |
mbed_official | 76:aeb1df146756 | 307 | * @} |
mbed_official | 76:aeb1df146756 | 308 | */ |
mbed_official | 76:aeb1df146756 | 309 | |
mbed_official | 76:aeb1df146756 | 310 | /** |
mbed_official | 76:aeb1df146756 | 311 | * @} |
mbed_official | 76:aeb1df146756 | 312 | */ |
mbed_official | 76:aeb1df146756 | 313 | |
mbed_official | 76:aeb1df146756 | 314 | /** |
mbed_official | 76:aeb1df146756 | 315 | * @} |
mbed_official | 76:aeb1df146756 | 316 | */ |
mbed_official | 76:aeb1df146756 | 317 | |
mbed_official | 76:aeb1df146756 | 318 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
mbed_official | 76:aeb1df146756 | 319 |