annotate Small_CPU/Src/system_stm32f4xx.c @ 264:b3685fbada3b IPC_Sync_Improvment_2

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