122 #include "stm32f4xx.h"
148 #define VECT_TAB_OFFSET 0x00
183 __I uint8_t
AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
194 #ifdef DATA_IN_ExtSRAM
195 static void SystemInit_ExtMemCtl(
void);
215 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
216 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));
221 RCC->CR |= (uint32_t)0x00000001;
224 RCC->CFGR = 0x00000000;
227 RCC->CR &= (uint32_t)0xFEF6FFFF;
230 RCC->PLLCFGR = 0x24003010;
233 RCC->CR &= (uint32_t)0xFFFBFFFF;
236 RCC->CIR = 0x00000000;
238 #ifdef DATA_IN_ExtSRAM
239 SystemInit_ExtMemCtl();
291 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
294 tmp = RCC->CFGR & RCC_CFGR_SWS;
309 pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
310 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
315 pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
320 pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
323 pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
349 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
352 RCC->CR |= ((uint32_t)RCC_CR_HSEON);
357 HSEStatus = RCC->CR & RCC_CR_HSERDY;
359 }
while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
361 if ((RCC->CR & RCC_CR_HSERDY) != RESET)
363 HSEStatus = (uint32_t)0x01;
367 HSEStatus = (uint32_t)0x00;
370 if (HSEStatus == (uint32_t)0x01)
373 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
374 PWR->CR |= PWR_CR_VOS;
377 RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
380 RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
383 RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
386 RCC->PLLCFGR =
PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) | (RCC_PLLCFGR_PLLSRC_HSE) | (
PLL_Q << 24);
389 RCC->CR |= RCC_CR_PLLON;
392 while((RCC->CR & RCC_CR_PLLRDY) == 0);
395 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
398 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
399 RCC->CFGR |= RCC_CFGR_SW_PLL;
402 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
421 #ifdef DATA_IN_ExtSRAM
429 void SystemInit_ExtMemCtl(
void)
452 RCC->AHB1ENR = 0x00000078;
455 GPIOD->AFR[0] = 0x00cc00cc;
456 GPIOD->AFR[1] = 0xcc0ccccc;
458 GPIOD->MODER = 0xaaaa0a0a;
460 GPIOD->OSPEEDR = 0xffff0f0f;
462 GPIOD->OTYPER = 0x00000000;
464 GPIOD->PUPDR = 0x00000000;
467 GPIOE->AFR[0] = 0xc00cc0cc;
468 GPIOE->AFR[1] = 0xcccccccc;
470 GPIOE->MODER = 0xaaaa828a;
472 GPIOE->OSPEEDR = 0xffffc3cf;
474 GPIOE->OTYPER = 0x00000000;
476 GPIOE->PUPDR = 0x00000000;
479 GPIOF->AFR[0] = 0x00cccccc;
480 GPIOF->AFR[1] = 0xcccc0000;
482 GPIOF->MODER = 0xaa000aaa;
484 GPIOF->OSPEEDR = 0xff000fff;
486 GPIOF->OTYPER = 0x00000000;
488 GPIOF->PUPDR = 0x00000000;
491 GPIOG->AFR[0] = 0x00cccccc;
492 GPIOG->AFR[1] = 0x000000c0;
494 GPIOG->MODER = 0x00080aaa;
496 GPIOG->OSPEEDR = 0x000c0fff;
498 GPIOG->OTYPER = 0x00000000;
500 GPIOG->PUPDR = 0x00000000;
504 RCC->AHB3ENR = 0x00000001;
507 FSMC_Bank1->BTCR[2] = 0x00001015;
508 FSMC_Bank1->BTCR[3] = 0x00010603;
509 FSMC_Bank1E->BWTR[2] = 0x0fffffff;
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
void SystemInit(void)
Setup the microcontroller system Initialize the Embedded Flash Interface, the PLL and update the Syst...
__I uint8_t AHBPrescTable[16]
static void SetSysClock(void)
Configures the System clock source, PLL Multiplier and Divider factors, AHB/APBx prescalers and Flash...