system_stm32f7xx.c
Go to the documentation of this file.
1 
48 #include "stm32f7xx.h"
49 
50 #if !defined (HSE_VALUE)
51  #define HSE_VALUE ((uint32_t)25000000)
52 #endif /* HSE_VALUE */
53 
54 #if !defined (HSI_VALUE)
55  #define HSI_VALUE ((uint32_t)16000000)
56 #endif /* HSI_VALUE */
57 
74 /************************* Miscellaneous Configuration ************************/
77 /* #define DATA_IN_ExtSDRAM */
78 
81 /* #define VECT_TAB_SRAM */
82 #define VECT_TAB_OFFSET 0x00
84 /******************************************************************************/
85 
102  /* This variable is updated in three ways:
103  1) by calling CMSIS function SystemCoreClockUpdate()
104  2) by calling HAL API function HAL_RCC_GetHCLKFreq()
105  3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
106  Note: If you use this function to configure the system clock; then there
107  is no need to call the 2 first functions listed above, since SystemCoreClock
108  variable is updated automatically.
109  */
110  uint32_t SystemCoreClock = 16000000;
111  const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
112  const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
113 
121 #if defined (DATA_IN_ExtSDRAM)
122  static void SystemInit_ExtMemCtl(void);
123 #endif /* DATA_IN_ExtSDRAM */
124 
140 void SystemInit(void)
141 {
142  /* FPU settings ------------------------------------------------------------*/
143  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
144  SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
145  #endif
146  /* Reset the RCC clock configuration to the default reset state ------------*/
147  /* Set HSION bit */
148  RCC->CR |= (uint32_t)0x00000001;
149 
150  /* Reset CFGR register */
151  RCC->CFGR = 0x00000000;
152 
153  /* Reset HSEON, CSSON and PLLON bits */
154  RCC->CR &= (uint32_t)0xFEF6FFFF;
155 
156  /* Reset PLLCFGR register */
157  RCC->PLLCFGR = 0x24003010;
158 
159  /* Reset HSEBYP bit */
160  RCC->CR &= (uint32_t)0xFFFBFFFF;
161 
162  /* Disable all interrupts */
163  RCC->CIR = 0x00000000;
164 
165 #if defined (DATA_IN_ExtSDRAM)
166  SystemInit_ExtMemCtl();
167 #endif /* DATA_IN_ExtSDRAM */
168 
169  /* Configure the Vector Table location add offset address ------------------*/
170 #ifdef VECT_TAB_SRAM
171  SCB->VTOR = SRAM1_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
172 #else
173  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
174 #endif
175 }
176 
214 {
215  uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
216 
217  /* Get SYSCLK source -------------------------------------------------------*/
218  tmp = RCC->CFGR & RCC_CFGR_SWS;
219 
220  switch (tmp)
221  {
222  case 0x00: /* HSI used as system clock source */
224  break;
225  case 0x04: /* HSE used as system clock source */
227  break;
228  case 0x08: /* PLL used as system clock source */
229 
230  /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
231  SYSCLK = PLL_VCO / PLL_P
232  */
233  pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
234  pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
235 
236  if (pllsource != 0)
237  {
238  /* HSE used as PLL clock source */
239  pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
240  }
241  else
242  {
243  /* HSI used as PLL clock source */
244  pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
245  }
246 
247  pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
248  SystemCoreClock = pllvco/pllp;
249  break;
250  default:
252  break;
253  }
254  /* Compute HCLK frequency --------------------------------------------------*/
255  /* Get HCLK prescaler */
256  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
257  /* HCLK frequency */
258  SystemCoreClock >>= tmp;
259 }
260 
261 #if defined (DATA_IN_ExtSDRAM)
262 
270 void SystemInit_ExtMemCtl(void)
271 {
272  register uint32_t tmpreg = 0, timeout = 0xFFFF;
273  register __IO uint32_t index;
274 
275  /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
276  clock */
277  RCC->AHB1ENR |= 0x000001F8;
278 
279  /* Connect PDx pins to FMC Alternate function */
280  GPIOD->AFR[0] = 0x000000CC;
281  GPIOD->AFR[1] = 0xCC000CCC;
282  /* Configure PDx pins in Alternate function mode */
283  GPIOD->MODER = 0xA02A000A;
284  /* Configure PDx pins speed to 100 MHz */
285  GPIOD->OSPEEDR = 0xF03F000F;
286  /* Configure PDx pins Output type to push-pull */
287  GPIOD->OTYPER = 0x00000000;
288  /* No pull-up, pull-down for PDx pins */
289  GPIOD->PUPDR = 0x50150005;
290 
291  /* Connect PEx pins to FMC Alternate function */
292  GPIOE->AFR[0] = 0xC00000CC;
293  GPIOE->AFR[1] = 0xCCCCCCCC;
294  /* Configure PEx pins in Alternate function mode */
295  GPIOE->MODER = 0xAAAA800A;
296  /* Configure PEx pins speed to 100 MHz */
297  GPIOE->OSPEEDR = 0xFFFFC00F;
298  /* Configure PEx pins Output type to push-pull */
299  GPIOE->OTYPER = 0x00000000;
300  /* No pull-up, pull-down for PEx pins */
301  GPIOE->PUPDR = 0x55554005;
302 
303  /* Connect PFx pins to FMC Alternate function */
304  GPIOF->AFR[0] = 0x00CCCCCC;
305  GPIOF->AFR[1] = 0xCCCCC000;
306  /* Configure PFx pins in Alternate function mode */
307  GPIOF->MODER = 0xAA800AAA;
308  /* Configure PFx pins speed to 100 MHz */
309  GPIOF->OSPEEDR = 0xFFC00FFF;
310  /* Configure PFx pins Output type to push-pull */
311  GPIOF->OTYPER = 0x00000000;
312  /* No pull-up, pull-down for PFx pins */
313  GPIOF->PUPDR = 0x55400555;
314 
315  /* Connect PGx pins to FMC Alternate function */
316  GPIOG->AFR[0] = 0x00CC0CCC;
317  GPIOG->AFR[1] = 0xC000000C;
318  /* Configure PGx pins in Alternate function mode */
319  GPIOG->MODER = 0x80020A2A;
320  /* Configure PGx pins speed to 100 MHz */
321  GPIOG->OSPEEDR = 0xC0030F3F;
322  /* Configure PGx pins Output type to push-pull */
323  GPIOG->OTYPER = 0x00000000;
324  /* No pull-up, pull-down for PGx pins */
325  GPIOG->PUPDR = 0x40010515;
326 
327  /* Connect PHx pins to FMC Alternate function */
328  GPIOH->AFR[0] = 0x00C0CC00;
329  GPIOH->AFR[1] = 0xCCCCCCCC;
330  /* Configure PHx pins in Alternate function mode */
331  GPIOH->MODER = 0xAAAA08A0;
332  /* Configure PHx pins speed to 100 MHz */
333  GPIOH->OSPEEDR = 0xFFFF0CF0;
334  /* Configure PHx pins Output type to push-pull */
335  GPIOH->OTYPER = 0x00000000;
336  /* No pull-up, pull-down for PHx pins */
337  GPIOH->PUPDR = 0x55550450;
338 
339  /* Connect PIx pins to FMC Alternate function */
340  GPIOI->AFR[0] = 0xCCCCCCCC;
341  GPIOI->AFR[1] = 0x00000CC0;
342  /* Configure PIx pins in Alternate function mode */
343  GPIOI->MODER = 0x0028AAAA;
344  /* Configure PIx pins speed to 100 MHz */
345  GPIOI->OSPEEDR = 0x003CFFFF;
346  /* Configure PIx pins Output type to push-pull */
347  GPIOI->OTYPER = 0x00000000;
348  /* No pull-up, pull-down for PIx pins */
349  GPIOI->PUPDR = 0x00145555;
350 
351  /* Enable the FMC interface clock */
352  RCC->AHB3ENR |= 0x00000001;
353 
354  /* Configure and enable SDRAM bank1 */
355  FMC_Bank5_6->SDCR[0] = 0x000019E4;
356  FMC_Bank5_6->SDTR[0] = 0x01116361;
357 
358  /* SDRAM initialization sequence */
359  /* Clock enable command */
360  FMC_Bank5_6->SDCMR = 0x00000011;
361  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
362  while((tmpreg != 0) && (timeout-- > 0))
363  {
364  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
365  }
366 
367  /* Delay */
368  for (index = 0; index<1000; index++);
369 
370  /* PALL command */
371  FMC_Bank5_6->SDCMR = 0x00000012;
372  timeout = 0xFFFF;
373  while((tmpreg != 0) && (timeout-- > 0))
374  {
375  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
376  }
377 
378  /* Auto refresh command */
379  FMC_Bank5_6->SDCMR = 0x000000F3;
380  timeout = 0xFFFF;
381  while((tmpreg != 0) && (timeout-- > 0))
382  {
383  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
384  }
385 
386  /* MRD register program */
387  FMC_Bank5_6->SDCMR = 0x00046014;
388  timeout = 0xFFFF;
389  while((tmpreg != 0) && (timeout-- > 0))
390  {
391  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
392  }
393 
394  /* Set refresh count */
395  tmpreg = FMC_Bank5_6->SDRTR;
396  FMC_Bank5_6->SDRTR = (tmpreg | (0x00000603<<1));
397 
398  /* Disable write protection */
399  tmpreg = FMC_Bank5_6->SDCR[0];
400  FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
401 }
402 #endif /* DATA_IN_ExtSDRAM */
403 
416 /************************ (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
SystemCoreClock
uint32_t SystemCoreClock
System clock frequency (core clock)
Definition: system_stm32f7xx.c:110
GPIOE
#define GPIOE
Definition: stm32f407xx.h:1107
SRAM1_BASE
#define SRAM1_BASE
Definition: stm32f407xx.h:909
SystemInit
void SystemInit(void)
Setup the microcontroller system Initialize the Embedded Flash Interface, the PLL and update the Syst...
Definition: system_stm32f7xx.c:140
APBPrescTable
const uint8_t APBPrescTable[8]
Definition: system_stm32f7xx.c:112
RCC_CFGR_HPRE
#define RCC_CFGR_HPRE
Definition: stm32f407xx.h:9557
RCC_PLLCFGR_PLLSRC
#define RCC_PLLCFGR_PLLSRC
Definition: stm32f407xx.h:9516
stm32f7xx.h
CMSIS STM32F7xx Device Peripheral Access Layer Header File.
RCC_PLLCFGR_PLLM
#define RCC_PLLCFGR_PLLM
Definition: stm32f407xx.h:9487
RCC_CFGR_SWS
#define RCC_CFGR_SWS
Definition: stm32f407xx.h:9546
HSE_VALUE
#define HSE_VALUE
Definition: system_stm32f7xx.c:51
FMC_Bank5_6
#define FMC_Bank5_6
Definition: stm32f469xx.h:1379
GPIOH
#define GPIOH
Definition: stm32f407xx.h:1110
VECT_TAB_OFFSET
#define VECT_TAB_OFFSET
Definition: system_stm32f7xx.c:82
HSI_VALUE
#define HSI_VALUE
Definition: system_stm32f7xx.c:55
GPIOI
#define GPIOI
Definition: stm32f407xx.h:1111
RCC
#define RCC
Definition: stm32f407xx.h:1113
RCC_PLLCFGR_PLLN
#define RCC_PLLCFGR_PLLN
Definition: stm32f407xx.h:9497
GPIOG
#define GPIOG
Definition: stm32f407xx.h:1109
SystemCoreClockUpdate
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
Definition: system_stm32f7xx.c:213
GPIOD
#define GPIOD
Definition: stm32f407xx.h:1106
GPIOF
#define GPIOF
Definition: stm32f407xx.h:1108
AHBPrescTable
const uint8_t AHBPrescTable[16]
Definition: system_stm32f7xx.c:111
RCC_PLLCFGR_PLLP
#define RCC_PLLCFGR_PLLP
Definition: stm32f407xx.h:9510


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