stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c
Go to the documentation of this file.
1 
64 #include "stm32f4xx.h"
65 
66 #if !defined (HSE_VALUE)
67  #define HSE_VALUE ((uint32_t)8000000)
68 #endif /* HSE_VALUE */
69 
70 #if !defined (HSI_VALUE)
71  #define HSI_VALUE ((uint32_t)16000000)
72 #endif /* HSI_VALUE */
73 
90 /************************* Miscellaneous Configuration ************************/
91 
94 /* #define VECT_TAB_SRAM */
95 #define VECT_TAB_OFFSET 0x00
97 /******************************************************************************/
98 
114  /* This variable is updated in three ways:
115  1) by calling CMSIS function SystemCoreClockUpdate()
116  2) by calling HAL API function HAL_RCC_GetHCLKFreq()
117  3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
118  Note: If you use this function to configure the system clock; then there
119  is no need to call the 2 first functions listed above, since SystemCoreClock
120  variable is updated automatically.
121  */
122 uint32_t SystemCoreClock = 16000000;
123 const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
124 const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
148 void SystemInit(void)
149 {
150  /* FPU settings ------------------------------------------------------------*/
151  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
152  SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
153  #endif
154  /* Reset the RCC clock configuration to the default reset state ------------*/
155  /* Set HSION bit */
156  RCC->CR |= (uint32_t)0x00000001;
157 
158  /* Reset CFGR register */
159  RCC->CFGR = 0x00000000;
160 
161  /* Reset HSEON, CSSON and PLLON bits */
162  RCC->CR &= (uint32_t)0xFEF6FFFF;
163 
164  /* Reset PLLCFGR register */
165  RCC->PLLCFGR = 0x24003010;
166 
167  /* Reset HSEBYP bit */
168  RCC->CR &= (uint32_t)0xFFFBFFFF;
169 
170  /* Disable all interrupts */
171  RCC->CIR = 0x00000000;
172 
173  /* Configure the Vector Table location add offset address ------------------*/
174 #ifdef VECT_TAB_SRAM
175  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
176 #else
177  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
178 #endif
179 }
180 
218 {
219  uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
220 
221  /* Get SYSCLK source -------------------------------------------------------*/
222  tmp = RCC->CFGR & RCC_CFGR_SWS;
223 
224  switch (tmp)
225  {
226  case 0x00: /* HSI used as system clock source */
228  break;
229  case 0x04: /* HSE used as system clock source */
231  break;
232  case 0x08: /* PLL used as system clock source */
233 
234  /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
235  SYSCLK = PLL_VCO / PLL_P
236  */
237  pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
238  pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
239 
240  if (pllsource != 0)
241  {
242  /* HSE used as PLL clock source */
243  pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
244  }
245  else
246  {
247  /* HSI used as PLL clock source */
248  pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
249  }
250 
251  pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
252  SystemCoreClock = pllvco/pllp;
253  break;
254  default:
256  break;
257  }
258  /* Compute HCLK frequency --------------------------------------------------*/
259  /* Get HCLK prescaler */
260  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
261  /* HCLK frequency */
262  SystemCoreClock >>= tmp;
263 }
264 
276 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
SCB
#define SCB
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:1778
FLASH_BASE
#define FLASH_BASE
Definition: stm32f407xx.h:907
SystemInit
void SystemInit(void)
Setup the microcontroller system Initialize the FPU setting, vector table location and External memor...
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:148
APBPrescTable
const uint8_t APBPrescTable[8]
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:124
SRAM_BASE
#define SRAM_BASE
Definition: stm32f407xx.h:924
RCC_CFGR_HPRE
#define RCC_CFGR_HPRE
Definition: stm32f407xx.h:9557
RCC_PLLCFGR_PLLSRC
#define RCC_PLLCFGR_PLLSRC
Definition: stm32f407xx.h:9516
HSE_VALUE
#define HSE_VALUE
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:67
RCC_PLLCFGR_PLLM
#define RCC_PLLCFGR_PLLM
Definition: stm32f407xx.h:9487
RCC_CFGR_SWS
#define RCC_CFGR_SWS
Definition: stm32f407xx.h:9546
SystemCoreClock
uint32_t SystemCoreClock
System clock frequency (core clock)
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:122
RCC
#define RCC
Definition: stm32f407xx.h:1113
SystemCoreClockUpdate
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:217
VECT_TAB_OFFSET
#define VECT_TAB_OFFSET
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:95
AHBPrescTable
const uint8_t AHBPrescTable[16]
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:123
RCC_PLLCFGR_PLLN
#define RCC_PLLCFGR_PLLN
Definition: stm32f407xx.h:9497
RCC_PLLCFGR_PLLP
#define RCC_PLLCFGR_PLLP
Definition: stm32f407xx.h:9510
HSI_VALUE
#define HSI_VALUE
Definition: stm32f407/stm32f407g-disc1/Src/system_stm32f4xx.c:71


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:55