annotate Discovery/Src/system_stm32f4xx_special_plus_256k.c @ 925:79c888f5d8d2 Evo_2_23

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