这个函数的详细内容复制到如下:
/**
* @brief Setup the microcontroller system
* Initialize the Embedded Flash Interface, the PLL and update the
* SystemCoreClock variable.
* @note This function should be used only after reset.
* @param None
* @retval None
*/
void SystemInit (void)
{
/* Reset the RCC clock configuration to the default reset state(for debug purpose) */
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001;
/* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
#ifndef STM32F10X_CL
RCC->CFGR &= (uint32_t)0xF8FF0000;
#else
RCC->CFGR &= (uint32_t)0xF0FF0000;
#endif /* STM32F10X_CL */
/* Reset HSEON, CSSON and PLLON bits */
RCC->CR &= (uint32_t)0xFEF6FFFF;
/* Reset HSEBYP bit */
RCC->CR &= (uint32_t)0xFFFBFFFF;
/* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
RCC->CFGR &= (uint32_t)0xFF80FFFF;
#ifdef STM32F10X_CL
/* Reset PLL2ON and PLL3ON bits */
RCC->CR &= (uint32_t)0xEBFFFFFF;
/* Disable all interrupts and clear pending bits */
RCC->CIR = 0x00FF0000;
/* Reset CFGR2 register */
RCC->CFGR2 = 0x00000000;
#elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
/* Disable all interrupts and clear pending bits */
RCC->CIR = 0x009F0000;
/* Reset CFGR2 register */
RCC->CFGR2 = 0x00000000;
#else
/* Disable all interrupts and clear pending bits */
RCC->CIR = 0x009F0000;
#endif /* STM32F10X_CL */
#if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)
#ifdef DATA_IN_ExtSRAM
SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM */
#endif
/* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
/* Configure the Flash Latency cycles and enable prefetch buffer */
SetSysClock();
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
#endif
}
4、我们可以看到SystemInit()函数当中又调用了一个叫SetSysClock()的函数(在上面代码中用红色字体标注),我们接着追踪SetSysClock()的函数,我们看到这个函数还是位于system_stm32f10x.c当中:
5、我们可以看到这个设置系统时钟的函数中通过宏定义的方式共有6个函数可以调用,但是我们在追踪函数的时候,只能追踪到其中的一个,原因是在system_stm32f10x.c源文件的开始处有一个声明系统时钟频率的宏定义:
用户可以根据自己的需要在这个地方修改系统的时钟频率。
6、在知道这个系统时钟频率之后,我们就可以在第4点的基础上追踪函数了:
我们可以看到这个设置系统时钟频率的函数仍然位于system_stm32f10x.c源文件当中,找到这个函数以后继续往上翻页,我们可以看到SetSysClock()中出现的函数全都在这里出现了,因此我们可以由此得出结论:在STM32标准外设库的所有时钟频率设置全都放置在system_stm32f10x.c源文件当中,因此用户完全没有必要再去纠结这个系统频率的设置了,用户唯一需要做的就是根据需要修改设置系统时钟频率的宏定义(如下图所示)。(哈哈!我想我这一个结论对大家肯定能起到很大的帮助作用的,但是对我来说得出的结论就是我这一周白做了很多事情,无用功太多呀!。)