44 #include "stm32f4xx.h"
70 #define VECT_TAB_OFFSET 0x00
105 __I uint8_t
AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
116 #ifdef DATA_IN_ExtSRAM
117 static void SystemInit_ExtMemCtl(
void);
137 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
138 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));
143 RCC->CR |= (uint32_t)0x00000001;
146 RCC->CFGR = 0x00000000;
149 RCC->CR &= (uint32_t)0xFEF6FFFF;
152 RCC->PLLCFGR = 0x24003010;
155 RCC->CR &= (uint32_t)0xFFFBFFFF;
158 RCC->CIR = 0x00000000;
160 #ifdef DATA_IN_ExtSRAM
161 SystemInit_ExtMemCtl();
213 uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
216 tmp = RCC->CFGR & RCC_CFGR_SWS;
231 pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
232 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
237 pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
242 pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
245 pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
271 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
274 RCC->CR |= ((uint32_t)RCC_CR_HSEON);
279 HSEStatus = RCC->CR & RCC_CR_HSERDY;
281 }
while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
283 if ((RCC->CR & RCC_CR_HSERDY) != RESET)
285 HSEStatus = (uint32_t)0x01;
289 HSEStatus = (uint32_t)0x00;
292 if (HSEStatus == (uint32_t)0x01)
295 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
296 PWR->CR |= PWR_CR_VOS;
299 RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
302 RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
305 RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
308 RCC->PLLCFGR =
PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
309 (RCC_PLLCFGR_PLLSRC_HSE) | (
PLL_Q << 24);
312 RCC->CR |= RCC_CR_PLLON;
315 while((RCC->CR & RCC_CR_PLLRDY) == 0);
318 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
321 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
322 RCC->CFGR |= RCC_CFGR_SW_PLL;
325 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
342 #ifdef DATA_IN_ExtSRAM
350 void SystemInit_ExtMemCtl(
void)
373 RCC->AHB1ENR = 0x00000078;
376 GPIOD->AFR[0] = 0x00cc00cc;
377 GPIOD->AFR[1] = 0xcc0ccccc;
379 GPIOD->MODER = 0xaaaa0a0a;
381 GPIOD->OSPEEDR = 0xffff0f0f;
383 GPIOD->OTYPER = 0x00000000;
385 GPIOD->PUPDR = 0x00000000;
388 GPIOE->AFR[0] = 0xc00cc0cc;
389 GPIOE->AFR[1] = 0xcccccccc;
391 GPIOE->MODER = 0xaaaa828a;
393 GPIOE->OSPEEDR = 0xffffc3cf;
395 GPIOE->OTYPER = 0x00000000;
397 GPIOE->PUPDR = 0x00000000;
400 GPIOF->AFR[0] = 0x00cccccc;
401 GPIOF->AFR[1] = 0xcccc0000;
403 GPIOF->MODER = 0xaa000aaa;
405 GPIOF->OSPEEDR = 0xff000fff;
407 GPIOF->OTYPER = 0x00000000;
409 GPIOF->PUPDR = 0x00000000;
412 GPIOG->AFR[0] = 0x00cccccc;
413 GPIOG->AFR[1] = 0x000000c0;
415 GPIOG->MODER = 0x00080aaa;
417 GPIOG->OSPEEDR = 0x000c0fff;
419 GPIOG->OTYPER = 0x00000000;
421 GPIOG->PUPDR = 0x00000000;
425 RCC->AHB3ENR = 0x00000001;
428 FSMC_Bank1->BTCR[2] = 0x00001015;
429 FSMC_Bank1->BTCR[3] = 0x00010603;
430 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...