43 #include "stm32f4xx.h"
69 #define VECT_TAB_OFFSET 0x00
104 __I uint8_t
AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
115 #ifdef DATA_IN_ExtSRAM
116 static void SystemInit_ExtMemCtl(
void);
136 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
137 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));
142 RCC->CR |= (uint32_t)0x00000001;
145 RCC->CFGR = 0x00000000;
148 RCC->CR &= (uint32_t)0xFEF6FFFF;
151 RCC->PLLCFGR = 0x24003010;
154 RCC->CR &= (uint32_t)0xFFFBFFFF;
157 RCC->CIR = 0x00000000;
159 #ifdef DATA_IN_ExtSRAM
160 SystemInit_ExtMemCtl();
212 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
215 tmp = RCC->CFGR & RCC_CFGR_SWS;
230 pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
231 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
236 pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
241 pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
244 pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
270 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
273 RCC->CR |= ((uint32_t)RCC_CR_HSEON);
278 HSEStatus = RCC->CR & RCC_CR_HSERDY;
280 }
while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
282 if ((RCC->CR & RCC_CR_HSERDY) != RESET)
284 HSEStatus = (uint32_t)0x01;
288 HSEStatus = (uint32_t)0x00;
291 if (HSEStatus == (uint32_t)0x01)
294 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
295 PWR->CR |= PWR_CR_VOS;
298 RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
301 RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
304 RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
307 RCC->PLLCFGR =
PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
308 (RCC_PLLCFGR_PLLSRC_HSE) | (
PLL_Q << 24);
311 RCC->CR |= RCC_CR_PLLON;
314 while((RCC->CR & RCC_CR_PLLRDY) == 0);
317 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
320 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
321 RCC->CFGR |= RCC_CFGR_SW_PLL;
324 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
341 #ifdef DATA_IN_ExtSRAM
349 void SystemInit_ExtMemCtl(
void)
372 RCC->AHB1ENR = 0x00000078;
375 GPIOD->AFR[0] = 0x00cc00cc;
376 GPIOD->AFR[1] = 0xcc0ccccc;
378 GPIOD->MODER = 0xaaaa0a0a;
380 GPIOD->OSPEEDR = 0xffff0f0f;
382 GPIOD->OTYPER = 0x00000000;
384 GPIOD->PUPDR = 0x00000000;
387 GPIOE->AFR[0] = 0xc00cc0cc;
388 GPIOE->AFR[1] = 0xcccccccc;
390 GPIOE->MODER = 0xaaaa828a;
392 GPIOE->OSPEEDR = 0xffffc3cf;
394 GPIOE->OTYPER = 0x00000000;
396 GPIOE->PUPDR = 0x00000000;
399 GPIOF->AFR[0] = 0x00cccccc;
400 GPIOF->AFR[1] = 0xcccc0000;
402 GPIOF->MODER = 0xaa000aaa;
404 GPIOF->OSPEEDR = 0xff000fff;
406 GPIOF->OTYPER = 0x00000000;
408 GPIOF->PUPDR = 0x00000000;
411 GPIOG->AFR[0] = 0x00cccccc;
412 GPIOG->AFR[1] = 0x000000c0;
414 GPIOG->MODER = 0x00080aaa;
416 GPIOG->OSPEEDR = 0x000c0fff;
418 GPIOG->OTYPER = 0x00000000;
420 GPIOG->PUPDR = 0x00000000;
424 RCC->AHB3ENR = 0x00000001;
427 FSMC_Bank1->BTCR[2] = 0x00001015;
428 FSMC_Bank1->BTCR[3] = 0x00010603;
429 FSMC_Bank1E->BWTR[2] = 0x0fffffff;
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
static void SetSysClock(void)
Configures the System clock source, PLL Multiplier and Divider factors, AHB/APBx prescalers and Flash...
void SystemInit(void)
Setup the microcontroller system Initialize the Embedded Flash Interface, the PLL and update the Syst...
__I uint8_t AHBPrescTable[16]