122 #include "stm32f4xx.h"
148 #define VECT_TAB_OFFSET 0x00
154 #define PLL_M 4 // 2MHz
155 #define PLL_N 168 // 336MHz
158 #define PLL_P 2 // 168MHz
161 #define PLL_Q 7 // 48MHz
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);
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...