stm32f469/stm32f469i-disco/Src/system_stm32f4xx.c
Go to the documentation of this file.
1 
65 #include "stm32f4xx.h"
66 
67 #if !defined (HSE_VALUE)
68 #if defined(USE_STM32469I_DISCO_REVA)
69  #define HSE_VALUE ((uint32_t)25000000)
70 #else
71  #define HSE_VALUE ((uint32_t)8000000)
72 #endif /* USE_STM32469I_DISCO_REVA */
73 #endif /* HSE_VALUE */
74 
75 #if !defined (HSI_VALUE)
76  #define HSI_VALUE ((uint32_t)16000000)
77 #endif /* HSI_VALUE */
78 
95 /************************* Miscellaneous Configuration ************************/
98 /* #define DATA_IN_ExtSDRAM */
99 
102 /* #define VECT_TAB_SRAM */
103 #define VECT_TAB_OFFSET 0x00
105 /******************************************************************************/
106 
122  /* This variable is updated in three ways:
123  1) by calling CMSIS function SystemCoreClockUpdate()
124  2) by calling HAL API function HAL_RCC_GetHCLKFreq()
125  3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
126  Note: If you use this function to configure the system clock; then there
127  is no need to call the 2 first functions listed above, since SystemCoreClock
128  variable is updated automatically.
129  */
130 uint32_t SystemCoreClock = 16000000;
131 const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
132 const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
141 #if defined (DATA_IN_ExtSDRAM)
142  static void SystemInit_ExtMemCtl(void);
143 #endif /* DATA_IN_ExtSDRAM */
144 
160 void SystemInit(void)
161 {
162  /* FPU settings ------------------------------------------------------------*/
163  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
164  SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
165  #endif
166  /* Reset the RCC clock configuration to the default reset state ------------*/
167  /* Set HSION bit */
168  RCC->CR |= (uint32_t)0x00000001;
169 
170  /* Reset CFGR register */
171  RCC->CFGR = 0x00000000;
172 
173  /* Reset HSEON, CSSON and PLLON bits */
174  RCC->CR &= (uint32_t)0xFEF6FFFF;
175 
176  /* Reset PLLCFGR register */
177  RCC->PLLCFGR = 0x24003010;
178 
179  /* Reset HSEBYP bit */
180  RCC->CR &= (uint32_t)0xFFFBFFFF;
181 
182  /* Disable all interrupts */
183  RCC->CIR = 0x00000000;
184 
185 #if defined (DATA_IN_ExtSDRAM)
186  SystemInit_ExtMemCtl();
187 #endif /* DATA_IN_ExtSDRAM */
188 
189  /* Configure the Vector Table location add offset address ------------------*/
190 #ifdef VECT_TAB_SRAM
191  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
192 #else
193  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
194 #endif
195 }
196 
233 void SystemCoreClockUpdate(void)
234 {
235  uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
236 
237  /* Get SYSCLK source -------------------------------------------------------*/
238  tmp = RCC->CFGR & RCC_CFGR_SWS;
239 
240  switch (tmp)
241  {
242  case 0x00: /* HSI used as system clock source */
244  break;
245  case 0x04: /* HSE used as system clock source */
247  break;
248  case 0x08: /* PLL used as system clock source */
249 
250  /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
251  SYSCLK = PLL_VCO / PLL_P
252  */
253  pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
254  pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
255 
256  if (pllsource != 0)
257  {
258  /* HSE used as PLL clock source */
259  pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
260  }
261  else
262  {
263  /* HSI used as PLL clock source */
264  pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
265  }
266 
267  pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
268  SystemCoreClock = pllvco/pllp;
269  break;
270  default:
272  break;
273  }
274  /* Compute HCLK frequency --------------------------------------------------*/
275  /* Get HCLK prescaler */
276  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
277  /* HCLK frequency */
278  SystemCoreClock >>= tmp;
279 }
280 
281 #if defined (DATA_IN_ExtSDRAM)
282 
290 void SystemInit_ExtMemCtl(void)
291 {
292  register uint32_t tmpreg = 0, timeout = 0xFFFF;
293  register __IO uint32_t index;
294 
295  /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH, and GPIOI interface
296  clock */
297  RCC->AHB1ENR |= 0x000001FC;
298 
299  /* Connect PCx pins to FMC Alternate function */
300  GPIOC->AFR[0] = 0x0000000C;
301  GPIOC->AFR[1] = 0x00000000;
302  /* Configure PCx pins in Alternate function mode */
303  GPIOC->MODER = 0x00000002;
304  /* Configure PCx pins speed to 100 MHz */
305  GPIOC->OSPEEDR = 0x00000003;
306  /* Configure PCx pins Output type to push-pull */
307  GPIOC->OTYPER = 0x00000000;
308  /* No pull-up, pull-down for PCx pins */
309  GPIOC->PUPDR = 0x00000000;
310 
311  /* Connect PDx pins to FMC Alternate function */
312  GPIOD->AFR[0] = 0x000000CC;
313  GPIOD->AFR[1] = 0xCC000CCC;
314  /* Configure PDx pins in Alternate function mode */
315  GPIOD->MODER = 0xA02A000A;
316  /* Configure PDx pins speed to 100 MHz */
317  GPIOD->OSPEEDR = 0xF03F000F;
318  /* Configure PDx pins Output type to push-pull */
319  GPIOD->OTYPER = 0x00000000;
320  /* No pull-up, pull-down for PDx pins */
321  GPIOD->PUPDR = 0x00000000;
322 
323  /* Connect PEx pins to FMC Alternate function */
324  GPIOE->AFR[0] = 0xC00000CC;
325  GPIOE->AFR[1] = 0xCCCCCCCC;
326  /* Configure PEx pins in Alternate function mode */
327  GPIOE->MODER = 0xAAAA800A;
328  /* Configure PEx pins speed to 100 MHz */
329  GPIOE->OSPEEDR = 0xFFFFC00F;
330  /* Configure PEx pins Output type to push-pull */
331  GPIOE->OTYPER = 0x00000000;
332  /* No pull-up, pull-down for PEx pins */
333  GPIOE->PUPDR = 0x00000000;
334 
335  /* Connect PFx pins to FMC Alternate function */
336  GPIOF->AFR[0] = 0x00CCCCCC;
337  GPIOF->AFR[1] = 0xCCCCC000;
338  /* Configure PFx pins in Alternate function mode */
339  GPIOF->MODER = 0xAA800AAA;
340  /* Configure PFx pins speed to 100 MHz */
341  GPIOF->OSPEEDR = 0xFFC00FFF;
342  /* Configure PFx pins Output type to push-pull */
343  GPIOF->OTYPER = 0x00000000;
344  /* No pull-up, pull-down for PFx pins */
345  GPIOF->PUPDR = 0x00000000;
346 
347  /* Connect PGx pins to FMC Alternate function */
348  GPIOG->AFR[0] = 0x00CC00CC;
349  GPIOG->AFR[1] = 0xC000000C;
350  /* Configure PGx pins in Alternate function mode */
351  GPIOG->MODER = 0x80020A0A;
352  /* Configure PGx pins speed to 100 MHz */
353  GPIOG->OSPEEDR = 0xC0030F0F;
354  /* Configure PGx pins Output type to push-pull */
355  GPIOG->OTYPER = 0x00000000;
356  /* No pull-up, pull-down for PGx pins */
357  GPIOG->PUPDR = 0x00000000;
358 
359  /* Connect PHx pins to FMC Alternate function */
360  GPIOH->AFR[0] = 0x0000CC00;
361  GPIOH->AFR[1] = 0xCCCCCCCC;
362  /* Configure PHx pins in Alternate function mode */
363  GPIOH->MODER = 0xAAAA00A0;
364  /* Configure PHx pins speed to 100 MHz */
365  GPIOH->OSPEEDR = 0xFFFF00F0;
366  /* Configure PHx pins Output type to push-pull */
367  GPIOH->OTYPER = 0x00000000;
368  /* No pull-up, pull-down for PHx pins */
369  GPIOH->PUPDR = 0x00000000;
370 
371  /* Connect PIx pins to FMC Alternate function */
372  GPIOI->AFR[0] = 0xCCCCCCCC;
373  GPIOI->AFR[1] = 0x00000CC0;
374  /* Configure PIx pins in Alternate function mode */
375  GPIOI->MODER = 0x0028AAAA;
376  /* Configure PIx pins speed to 100 MHz */
377  GPIOI->OSPEEDR = 0x003CFFFF;
378  /* Configure PIx pins Output type to push-pull */
379  GPIOI->OTYPER = 0x00000000;
380  /* No pull-up, pull-down for PIx pins */
381  GPIOI->PUPDR = 0x00000000;
382 
383  /* FMC Configuration */
384  /* Enable the FMC interface clock */
385  RCC->AHB3ENR |= 0x00000001;
386 
387  /* Configure and enable SDRAM bank2 */
388  FMC_Bank5_6->SDCR[0] = 0x000019E4;
389  FMC_Bank5_6->SDTR[0] = 0x01115351;
390 
391  /* SDRAM initialization sequence */
392  /* Clock enable command */
393  FMC_Bank5_6->SDCMR = 0x00000011;
394  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
395  while((tmpreg != 0) && (timeout-- > 0))
396  {
397  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
398  }
399 
400  /* Delay */
401  for (index = 0; index<1000; index++);
402 
403  /* PALL command */
404  FMC_Bank5_6->SDCMR = 0x00000012;
405  timeout = 0xFFFF;
406  while((tmpreg != 0) && (timeout-- > 0))
407  {
408  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
409  }
410 
411  /* Auto refresh command */
412  FMC_Bank5_6->SDCMR = 0x000000F3;
413  timeout = 0xFFFF;
414  while((tmpreg != 0) && (timeout-- > 0))
415  {
416  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
417  }
418 
419  /* MRD register program */
420  FMC_Bank5_6->SDCMR = 0x00046014;
421  timeout = 0xFFFF;
422  while((tmpreg != 0) && (timeout-- > 0))
423  {
424  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
425  }
426 
427  /* Set refresh count */
428  tmpreg = FMC_Bank5_6->SDRTR;
429  FMC_Bank5_6->SDRTR = (tmpreg | (0x0000056A<<1));
430 
431  /* Disable write protection */
432  tmpreg = FMC_Bank5_6->SDCR[0];
433  FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
434 }
435 #endif /* DATA_IN_ExtSDRAM */
436 
448 /************************ (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
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
SystemCoreClockUpdate
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
Definition: system_MIMXRT1052.c:138
APBPrescTable
const uint8_t APBPrescTable[8]
Definition: stm32f469/stm32f469i-disco/Src/system_stm32f4xx.c:132
GPIOE
#define GPIOE
Definition: stm32f407xx.h:1107
SRAM_BASE
#define SRAM_BASE
Definition: stm32f407xx.h:924
RCC_CFGR_HPRE
#define RCC_CFGR_HPRE
Definition: stm32f407xx.h:9557
SystemInit
void SystemInit(void)
Setup the microcontroller system Initialize the FPU setting, vector table location and External memor...
Definition: system_MIMXRT1052.c:75
RCC_PLLCFGR_PLLSRC
#define RCC_PLLCFGR_PLLSRC
Definition: stm32f407xx.h:9516
HSE_VALUE
#define HSE_VALUE
Definition: stm32f469/stm32f469i-disco/Src/system_stm32f4xx.c:71
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: stm32f469/stm32f469i-disco/Src/system_stm32f4xx.c:130
FMC_Bank5_6
#define FMC_Bank5_6
Definition: stm32f469xx.h:1379
GPIOH
#define GPIOH
Definition: stm32f407xx.h:1110
GPIOI
#define GPIOI
Definition: stm32f407xx.h:1111
RCC
#define RCC
Definition: stm32f407xx.h:1113
VECT_TAB_OFFSET
#define VECT_TAB_OFFSET
Definition: stm32f469/stm32f469i-disco/Src/system_stm32f4xx.c:103
AHBPrescTable
const uint8_t AHBPrescTable[16]
Definition: stm32f469/stm32f469i-disco/Src/system_stm32f4xx.c:131
RCC_PLLCFGR_PLLN
#define RCC_PLLCFGR_PLLN
Definition: stm32f407xx.h:9497
GPIOG
#define GPIOG
Definition: stm32f407xx.h:1109
GPIOD
#define GPIOD
Definition: stm32f407xx.h:1106
GPIOF
#define GPIOF
Definition: stm32f407xx.h:1108
RCC_PLLCFGR_PLLP
#define RCC_PLLCFGR_PLLP
Definition: stm32f407xx.h:9510
GPIOC
#define GPIOC
Definition: stm32f407xx.h:1105
HSI_VALUE
#define HSI_VALUE
Definition: stm32f469/stm32f469i-disco/Src/system_stm32f4xx.c:76


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