清楚的看到,在進(jìn)入main函數(shù)之前,系統(tǒng)顯示進(jìn)入 SystemInit() 函數(shù),進(jìn)到這里看看; [url=][/url]
1 void SystemInit (void) 2 { 3 /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ 4 /* Set HSION bit */ 5 RCC->CR |= (uint32_t)0x00000001; 6 7 /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ 8 #ifndef STM32F10X_CL 9 RCC->CFGR &= (uint32_t)0xF8FF0000;10 #else11 RCC->CFGR &= (uint32_t)0xF0FF0000;12 #endif /* STM32F10X_CL */ 13 14 /* Reset HSEON, CSSON and PLLON bits */15 RCC->CR &= (uint32_t)0xFEF6FFFF;16 17 /* Reset HSEBYP bit */18 RCC->CR &= (uint32_t)0xFFFBFFFF;19 20 /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */21 RCC->CFGR &= (uint32_t)0xFF80FFFF;22 23 #ifdef STM32F10X_CL24 /* Reset PLL2ON and PLL3ON bits */25 RCC->CR &= (uint32_t)0xEBFFFFFF;26 27 /* Disable all interrupts and clear pending bits */28 RCC->CIR = 0x00FF0000;29 30 /* Reset CFGR2 register */31 RCC->CFGR2 = 0x00000000;32 #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)33 /* Disable all interrupts and clear pending bits */34 RCC->CIR = 0x009F0000;35 36 /* Reset CFGR2 register */37 RCC->CFGR2 = 0x00000000; 38 #else39 /* Disable all interrupts and clear pending bits */40 RCC->CIR = 0x009F0000;41 #endif /* STM32F10X_CL */42 43 #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)44 #ifdef DATA_IN_ExtSRAM45 SystemInit_ExtMemCtl(); 46 #endif /* DATA_IN_ExtSRAM */47 #endif 48 49 /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */50 /* Configure the Flash Latency cycles and enable prefetch buffer */51 SetSysClock();52 53 #ifdef VECT_TAB_SRAM54 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */55 #else56 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */57 #endif 58 }[url=][/url]
面前一系列的RCC寄存器的初始化,還有一些條件編譯選項(xiàng),那些都是無關(guān)緊要的,對(duì)寄存器的初始化,
還有就是根據(jù)mcu的型號(hào)選擇不同的編譯; 到最后那里調(diào)用了 SetSysClock() 函數(shù),
我們?cè)谶M(jìn)入到這個(gè)函數(shù)里看看,代碼: [url=][/url]
1 static void SetSysClock(void) 2 { 3 #ifdef SYSCLK_FREQ_HSE 4 SetSysClockToHSE(); 5 #elif defined SYSCLK_FREQ_24MHz 6 SetSysClockTo24(); 7 #elif defined SYSCLK_FREQ_36MHz 8 SetSysClockTo36(); 9 #elif defined SYSCLK_FREQ_48MHz10 SetSysClockTo48();11 #elif defined SYSCLK_FREQ_56MHz12 SetSysClockTo56(); 13 #elif defined SYSCLK_FREQ_72MHz14 SetSysClockTo72();15 #endif16 17 /* If none of the define above is enabled, the HSI is used as System clock18 source (default after reset) */ 19 }[url=][/url]