以上在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;
/* 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;
?00100100(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();函數
上一篇:keil+stm32+JTAG利用swd方式進行printf輸出
下一篇:STM32-使用定時器做延時函數時遇到的坑
推薦閱讀
史海拾趣