|
22 | 22 | ******************************************************************************
|
23 | 23 | * @attention
|
24 | 24 | *
|
25 |
| - * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
| 25 | + * <h2><center>© Copyright(c) 2016 STMicroelectronics. |
| 26 | + * All rights reserved.</center></h2> |
26 | 27 | *
|
27 |
| - * Redistribution and use in source and binary forms, with or without modification, |
28 |
| - * are permitted provided that the following conditions are met: |
29 |
| - * 1. Redistributions of source code must retain the above copyright notice, |
30 |
| - * this list of conditions and the following disclaimer. |
31 |
| - * 2. Redistributions in binary form must reproduce the above copyright notice, |
32 |
| - * this list of conditions and the following disclaimer in the documentation |
33 |
| - * and/or other materials provided with the distribution. |
34 |
| - * 3. Neither the name of STMicroelectronics nor the names of its contributors |
35 |
| - * may be used to endorse or promote products derived from this software |
36 |
| - * without specific prior written permission. |
37 |
| - * |
38 |
| - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
39 |
| - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
40 |
| - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
41 |
| - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
42 |
| - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
43 |
| - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
44 |
| - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
45 |
| - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
46 |
| - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
47 |
| - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + * This software component is licensed by ST under BSD 3-Clause license, |
| 29 | + * the "License"; You may not use this file except in compliance with the |
| 30 | + * License. You may obtain a copy of the License at: |
| 31 | + * opensource.org/licenses/BSD-3-Clause |
48 | 32 | *
|
49 | 33 | ******************************************************************************
|
50 | 34 | */
|
|
68 | 52 | #endif /* HSE_VALUE */
|
69 | 53 |
|
70 | 54 | #if !defined (MSI_VALUE)
|
71 |
| - #define MSI_VALUE ((uint32_t)2000000U) /*!< Value of the Internal oscillator in Hz*/ |
| 55 | + #define MSI_VALUE ((uint32_t)2097152U) /*!< Value of the Internal oscillator in Hz*/ |
72 | 56 | #endif /* MSI_VALUE */
|
73 | 57 |
|
74 | 58 | #if !defined (HSI_VALUE)
|
|
98 | 82 | /* #define VECT_TAB_SRAM */
|
99 | 83 | #ifndef VECT_TAB_OFFSET
|
100 | 84 | #define VECT_TAB_OFFSET 0x00U /*!< Vector Table base offset field.
|
101 |
| - This value must be a multiple of 0x200. */ |
| 85 | + This value must be a multiple of 0x100. */ |
102 | 86 | #endif
|
103 | 87 | /******************************************************************************/
|
104 | 88 | /**
|
|
124 | 108 | is no need to call the 2 first functions listed above, since SystemCoreClock
|
125 | 109 | variable is updated automatically.
|
126 | 110 | */
|
127 |
| - uint32_t SystemCoreClock = 2000000U; |
| 111 | + uint32_t SystemCoreClock = 2097152U; /* 32.768 kHz * 2^6 */ |
128 | 112 | const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
|
129 | 113 | const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
|
130 | 114 | const uint8_t PLLMulTable[9] = {3U, 4U, 6U, 8U, 12U, 16U, 24U, 32U, 48U};
|
@@ -229,43 +213,53 @@ void SystemCoreClockUpdate (void)
|
229 | 213 | switch (tmp)
|
230 | 214 | {
|
231 | 215 | case 0x00U: /* MSI used as system clock */
|
232 |
| - msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U; |
| 216 | + msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> RCC_ICSCR_MSIRANGE_Pos; |
233 | 217 | SystemCoreClock = (32768U * (1U << (msirange + 1U)));
|
234 | 218 | break;
|
235 | 219 | case 0x04U: /* HSI used as system clock */
|
| 220 | + if ((RCC->CR & RCC_CR_HSIDIVF) != 0U) |
| 221 | + { |
| 222 | + SystemCoreClock = HSI_VALUE / 4U; |
| 223 | + } |
| 224 | + else |
| 225 | + { |
236 | 226 | SystemCoreClock = HSI_VALUE;
|
| 227 | + } |
237 | 228 | break;
|
238 | 229 | case 0x08U: /* HSE used as system clock */
|
239 | 230 | SystemCoreClock = HSE_VALUE;
|
240 | 231 | break;
|
241 |
| - case 0x0CU: /* PLL used as system clock */ |
| 232 | + default: /* PLL used as system clock */ |
242 | 233 | /* Get PLL clock source and multiplication factor ----------------------*/
|
243 | 234 | pllmul = RCC->CFGR & RCC_CFGR_PLLMUL;
|
244 | 235 | plldiv = RCC->CFGR & RCC_CFGR_PLLDIV;
|
245 |
| - pllmul = PLLMulTable[(pllmul >> 18U)]; |
246 |
| - plldiv = (plldiv >> 22U) + 1U; |
| 236 | + pllmul = PLLMulTable[(pllmul >> RCC_CFGR_PLLMUL_Pos)]; |
| 237 | + plldiv = (plldiv >> RCC_CFGR_PLLDIV_Pos) + 1U; |
247 | 238 |
|
248 | 239 | pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
249 | 240 |
|
250 | 241 | if (pllsource == 0x00U)
|
251 | 242 | {
|
252 | 243 | /* HSI oscillator clock selected as PLL clock entry */
|
| 244 | + if ((RCC->CR & RCC_CR_HSIDIVF) != 0U) |
| 245 | + { |
| 246 | + SystemCoreClock = (((HSI_VALUE / 4U) * pllmul) / plldiv); |
| 247 | + } |
| 248 | + else |
| 249 | + { |
253 | 250 | SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv);
|
254 | 251 | }
|
| 252 | + } |
255 | 253 | else
|
256 | 254 | {
|
257 | 255 | /* HSE selected as PLL clock entry */
|
258 | 256 | SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv);
|
259 | 257 | }
|
260 | 258 | break;
|
261 |
| - default: /* MSI used as system clock */ |
262 |
| - msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U; |
263 |
| - SystemCoreClock = (32768U * (1U << (msirange + 1U))); |
264 |
| - break; |
265 | 259 | }
|
266 | 260 | /* Compute HCLK clock frequency --------------------------------------------*/
|
267 | 261 | /* Get HCLK prescaler */
|
268 |
| - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; |
| 262 | + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)]; |
269 | 263 | /* HCLK clock frequency */
|
270 | 264 | SystemCoreClock >>= tmp;
|
271 | 265 | }
|
|
0 commit comments