129 #include "stm32f4xx.h" 153 #define VECT_TAB_OFFSET FLASH_OFFSET 190 __I uint8_t
AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
225 RCC->CR |= (uint32_t)0x00000001;
228 RCC->CFGR = 0x00000000;
231 RCC->CR &= (uint32_t)0xFEF6FFFF;
234 RCC->PLLCFGR = 0x24003010;
237 RCC->CR &= (uint32_t)0xFFFBFFFF;
240 RCC->CIR = 0x00000000;
249 SCB->VTOR = (uint32_t)&__isr_vector_start;
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;
351 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
354 RCC->CR |= ((uint32_t)RCC_CR_HSEON);
359 HSEStatus = RCC->CR & RCC_CR_HSERDY;
361 }
while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
363 if ((RCC->CR & RCC_CR_HSERDY) != RESET)
365 HSEStatus = (uint32_t)0x01;
369 HSEStatus = (uint32_t)0x00;
372 if (HSEStatus == (uint32_t)0x01)
375 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
376 PWR->CR |= PWR_CR_PMODE;
379 RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
382 RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
385 RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
397 uint8_t pll_m=4, pll_q, pll_p=2;
399 uint8_t flash_latency;
400 uint32_t cr_flags = RCC_CR_CSSON;
405 flash_latency = FLASH_ACR_LATENCY_5WS;
409 pll_n=360; pll_q=15; pll_p=4;
410 flash_latency = FLASH_ACR_LATENCY_5WS;
416 flash_latency = FLASH_ACR_LATENCY_6WS;
421 flash_latency = FLASH_ACR_LATENCY_6WS;
426 flash_latency = FLASH_ACR_LATENCY_7WS;
431 flash_latency = FLASH_ACR_LATENCY_7WS;
440 RCC->PLLCFGR = pll_m | (pll_n << 6) | (((pll_p >> 1) -1) << 16) |
441 (RCC_PLLCFGR_PLLSRC_HSE) | (pll_q << 24);
444 RCC->CR |= RCC_CR_PLLON | cr_flags;
448 while((RCC->CR & RCC_CR_PLLRDY) == 0) { }
452 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN | flash_latency;
455 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
456 RCC->CFGR |= RCC_CFGR_SW_PLL;
459 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL) {}
461 FLASH->ACR |= FLASH_ACR_PRFTEN;
476 RCC->CFGR &= ~RCC_CFGR_I2SSRC;
480 #if 0 // we don't use I2S 482 RCC->CR |= ((uint32_t)RCC_CR_PLLI2SON);
485 while((RCC->CR & RCC_CR_PLLI2SRDY) == 0) { }
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
void SetSysClock(uint8_t oc)
Configures the System clock source, PLL Multiplier and Divider factors, AHB/APBx prescalers and Flash...
void __error(uint32_t num, uint32_t pc, uint32_t lr, uint32_t flag)
void uint32_t uint32_t lr
__I uint8_t AHBPrescTable[16]
unsigned __isr_vector_start
void uint32_t uint32_t uint32_t flag
void systemInit(uint8_t oc)
Setup the microcontroller system Initialize the Embedded Flash Interface, the PLL and update the Syst...