以上在stm32f4xx中文参考手册的截图
SYSCLK时钟的来源有3个分别是 HSI HSE PLL
我们主要的时钟有 低速的内部时钟 LSI RC震荡产生 32KHZ
低速的外部时钟 LSE 32.768KHZ晶振
高速的内部时钟 HSI RC震荡16MHZ
高速的外部时钟 HSE 一般为8Mhz
一般情况我们的SYSCLK时钟选择PLLCLK
看看我们的函数是怎么操作时钟分配的!
启动文件首先先配置时钟然后在运行用户主函数,打开SystemInit函数
**
* @brief Setup the microcontroller system
* Initialize the Embedded Flash Interface, the PLL and update the
* SystemFrequency variable.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
/* Reset the RCC clock configuration to the default reset state ------------*/
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001;
/* Reset CFGR register */
RCC->CFGR = 0x00000000;
/* Reset HSEON, CSSON and PLLON bits */
RCC->CR &= (uint32_t)0xFEF6FFFF;
/* Reset PLLCFGR register */
RCC->PLLCFGR = 0x24003010;
/* Reset HSEBYP bit */
RCC->CR &= (uint32_t)0xFFFBFFFF;
/* Disable all interrupts */
RCC->CIR = 0x00000000;
#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
/* Configure the System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings ----------------------------------*/
SetSysClock();
/* Configure the Vector Table location add offset address ------------------*/
#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
}
以上为整个代码
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
这个是设置FPU
/* Reset the RCC clock configuration to the default reset state ------------*/
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001;
CR寄存器的第0位置1,其他位保持不变 ,HSI振荡器打开
/* Reset CFGR register */
RCC->CFGR = 0x00000000;
CFGR寄存器全都设0,对其复位
/* Reset HSEON, CSSON and PLLON bits */
RCC->CR &= (uint32_t)0xFEF6FFFF;
将对cr寄存器设置,1111 1110 1111 0110 1111 1111 1111 1111将第16位19位24位置0,其他位保持不变
/* Reset PLLCFGR register */
RCC->PLLCFGR = 0x24003010;
0010
0100(4)
0
0
0000
00 (2)
0
011000000(192) 010000(16)
/* Reset HSEBYP bit */
RCC->CR &= (uint32_t)0xFFFBFFFF;
/* Disable all interrupts */
RCC->CIR = 0x00000000;
复位
再来看看 SetSysClock();函数