Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
system_stm32f7xx.c
Go to the documentation of this file.
1
47#include "stm32f7xx.h"
48
49#if !defined (HSE_VALUE)
50 #define HSE_VALUE ((uint32_t)25000000)
51#endif /* HSE_VALUE */
52
53#if !defined (HSI_VALUE)
54 #define HSI_VALUE ((uint32_t)16000000)
55#endif /* HSI_VALUE */
56
73/************************* Miscellaneous Configuration ************************/
74
75/* Note: Following vector table addresses must be defined in line with linker
76 configuration. */
80/* #define USER_VECT_TAB_ADDRESS */
81
82#if defined(USER_VECT_TAB_ADDRESS)
85/* #define VECT_TAB_SRAM */
86#if defined(VECT_TAB_SRAM)
87#define VECT_TAB_BASE_ADDRESS RAMDTCM_BASE
89#define VECT_TAB_OFFSET 0x00000000U
91#else
92#define VECT_TAB_BASE_ADDRESS FLASH_BASE
94#define VECT_TAB_OFFSET 0x00000000U
96#endif /* VECT_TAB_SRAM */
97#endif /* USER_VECT_TAB_ADDRESS */
98/******************************************************************************/
99
116 /* This variable is updated in three ways:
117 1) by calling CMSIS function SystemCoreClockUpdate()
118 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
119 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
120 Note: If you use this function to configure the system clock; then there
121 is no need to call the 2 first functions listed above, since SystemCoreClock
122 variable is updated automatically.
123 */
124 uint32_t SystemCoreClock = 16000000;
125 const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
126 const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
127
151void SystemInit(void)
152{
153 /* FPU settings ------------------------------------------------------------*/
154#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
155 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
156#endif
157
158 /* Configure the Vector Table location -------------------------------------*/
159#if defined(USER_VECT_TAB_ADDRESS)
160 SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
161#endif /* USER_VECT_TAB_ADDRESS */
162}
163
201{
202 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
203
204 /* Get SYSCLK source -------------------------------------------------------*/
205 tmp = RCC->CFGR & RCC_CFGR_SWS;
206
207 switch (tmp)
208 {
209 case 0x00: /* HSI used as system clock source */
211 break;
212 case 0x04: /* HSE used as system clock source */
214 break;
215 case 0x08: /* PLL used as system clock source */
216
217 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
218 SYSCLK = PLL_VCO / PLL_P
219 */
220 pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
221 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
222
223 if (pllsource != 0)
224 {
225 /* HSE used as PLL clock source */
226 pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
227 }
228 else
229 {
230 /* HSI used as PLL clock source */
231 pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
232 }
233
234 pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
235 SystemCoreClock = pllvco/pllp;
236 break;
237 default:
239 break;
240 }
241 /* Compute HCLK frequency --------------------------------------------------*/
242 /* Get HCLK prescaler */
243 tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
244 /* HCLK frequency */
245 SystemCoreClock >>= tmp;
246}
247
259/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void SystemInit(void)
Setup the microcontroller system Initialize the Embedded Flash Interface, the PLL and update the Syst...
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
#define HSI_VALUE
#define HSE_VALUE
const uint8_t APBPrescTable[8]
const uint8_t AHBPrescTable[16]
uint32_t SystemCoreClock