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));
220 RCC->CR |= (uint32_t)0x00000001;
223 RCC->CFGR = 0x00000000;
226 RCC->CR &= (uint32_t)0xFEF6FFFF;
229 RCC->PLLCFGR = 0x24003010;
232 RCC->CR &= (uint32_t)0xFFFBFFFF;
235 RCC->CIR = 0x00000000;
237 #ifdef DATA_IN_ExtSRAM
238 SystemInit_ExtMemCtl();
290 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
293 tmp = RCC->CFGR & RCC_CFGR_SWS;
308 pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
309 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
314 pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
319 pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
322 pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
348 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
351 RCC->CR |= ((uint32_t)RCC_CR_HSEON);
356 HSEStatus = RCC->CR & RCC_CR_HSERDY;
358 }
while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
360 if ((RCC->CR & RCC_CR_HSERDY) != RESET)
362 HSEStatus = (uint32_t)0x01;
366 HSEStatus = (uint32_t)0x00;
369 if (HSEStatus == (uint32_t)0x01)
372 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
373 PWR->CR |= PWR_CR_VOS;
376 RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
379 RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
382 RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
385 RCC->PLLCFGR =
PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
386 (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);
416 #ifdef DATA_IN_ExtSRAM
424 void SystemInit_ExtMemCtl(
void)
447 RCC->AHB1ENR = 0x00000078;
450 GPIOD->AFR[0] = 0x00cc00cc;
451 GPIOD->AFR[1] = 0xcc0ccccc;
453 GPIOD->MODER = 0xaaaa0a0a;
455 GPIOD->OSPEEDR = 0xffff0f0f;
457 GPIOD->OTYPER = 0x00000000;
459 GPIOD->PUPDR = 0x00000000;
462 GPIOE->AFR[0] = 0xc00cc0cc;
463 GPIOE->AFR[1] = 0xcccccccc;
465 GPIOE->MODER = 0xaaaa828a;
467 GPIOE->OSPEEDR = 0xffffc3cf;
469 GPIOE->OTYPER = 0x00000000;
471 GPIOE->PUPDR = 0x00000000;
474 GPIOF->AFR[0] = 0x00cccccc;
475 GPIOF->AFR[1] = 0xcccc0000;
477 GPIOF->MODER = 0xaa000aaa;
479 GPIOF->OSPEEDR = 0xff000fff;
481 GPIOF->OTYPER = 0x00000000;
483 GPIOF->PUPDR = 0x00000000;
486 GPIOG->AFR[0] = 0x00cccccc;
487 GPIOG->AFR[1] = 0x000000c0;
489 GPIOG->MODER = 0x00080aaa;
491 GPIOG->OSPEEDR = 0x000c0fff;
493 GPIOG->OTYPER = 0x00000000;
495 GPIOG->PUPDR = 0x00000000;
499 RCC->AHB3ENR = 0x00000001;
502 FSMC_Bank1->BTCR[2] = 0x00001015;
503 FSMC_Bank1->BTCR[3] = 0x00010603;
504 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...