stm32f407時(shí)鐘配置方法例程解析
/*到了這一步,我們已經(jīng)配置好了系統(tǒng)時(shí)鐘,頻率為168MHz.下面我們可以對(duì)AHB,APB,外設(shè)等的時(shí)鐘進(jìn)行配置*/
/*時(shí)鐘的結(jié)構(gòu)請(qǐng)參考用戶手冊(cè)*/
/*首先配置AHB時(shí)鐘(HCLK).為了獲得較高的頻率,我們對(duì)SYSCLK 1分頻,得到HCLK*/
RCC_HCLKConfig(RCC_HCLK_Div1);
/*APBx時(shí)鐘(PCLK)由AHB時(shí)鐘(HCLK)分頻得到,下面我們配置PCLK*/
/*APB1時(shí)鐘配置. 4分頻,即PCLK1 = 42 MHz*/
RCC_PCLK1Config(RCC_HCLK_Div4);
/*APB2時(shí)鐘配置. 2分頻,即PCLK2 = 84 MHz*/
RCC_PCLK2Config(RCC_HCLK_Div2);
/*****函數(shù)結(jié)束******/
/*以上函數(shù)可以大體上說(shuō)明這些庫(kù)函數(shù)的作用*/
}
對(duì)于 RCC_PLLConfig();函數(shù),大家可能會(huì)迷惑。
其函數(shù)原型為:
void RCC_PLLConfig(uint32_t RCC_PLLSource,
uint32_t PLLM,
uint32_t PLLN,
uint32_t PLLP,
uint32_t PLLQ);
迷惑的地方肯定在于后面4個(gè)參數(shù)PLLM / PLLN / PLLP / PLLQ.
在庫(kù)函數(shù)源文件 system_stm32f4xx.c中可以找到這4個(gè)參數(shù)的說(shuō)明,請(qǐng)看下圖注釋部分:
(下面的是從 庫(kù)函數(shù)源文件 stm32f4xx_rcc.c 中找到的。其他函數(shù)可以直接去看庫(kù)函數(shù),注釋非常詳細(xì))
/**
* @brief Configures the main PLL clock source, multiplication and division factors.
@簡(jiǎn)介 配置主PLL時(shí)鐘源,以及分頻因子 (PLL不止一個(gè),還有一個(gè)用來(lái)為音頻處理提供高質(zhì)量時(shí)鐘)
* @note This function must be used only when the main PLL is disabled.
* @注意 這個(gè)函數(shù)只能在主PLL失能時(shí)才能使用
* @param RCC_PLLSource: specifies the PLL entry clock source.
@參數(shù) RCC_PLLSource:選擇PLL時(shí)鐘源
* This parameter can be one of the following values:
這個(gè)參數(shù)可以是如下值:
* @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock entry
選擇HSI作為PLL時(shí)鐘源
* @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock entry
選擇HSE作為PLL時(shí)鐘源
* @note This clock source (RCC_PLLSource) is common for the main PLL and PLLI2S.
*
* @param PLLM: specifies the division factor for PLL VCO input clock
@參數(shù) PLLM:設(shè)置 PLL VCO 輸入時(shí)鐘的 除法因子(division factor)
* This parameter must be a number between 0 and 63.
這個(gè)參數(shù) 范圍是 0 ~ 63
* @note You have to set the PLLM parameter correctly to ensure that the VCO input
* frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
* of 2 MHz to limit PLL jitter.
* @注意 你需要正確選擇 PLLM的值, 使得 VCO輸入頻率 介于 1~2MHz.
建議選擇 2MHz 來(lái)限制PLL震蕩(jitter?)
* @param PLLN: specifies the multiplication factor for PLL VCO output clock
* This parameter must be a number between 192 and 432.
@參數(shù) PLLN 選擇 PLL VCO輸出時(shí)鐘的 乘法因子(multiplication factor )
這個(gè)參數(shù)的值 介于 192 ~432
* @note You have to set the PLLN parameter correctly to ensure that the VCO
* output frequency is between 192 and 432 MHz.
* @注意 你學(xué)要正確選PLLN的大小,以保證VCO輸出時(shí)鐘介于 192 ~432MHz
* @param PLLP: specifies the division factor for main system clock (SYSCLK)
* This parameter must be a number in the range {2, 4, 6, or 8}.
@參數(shù) PLLP 選擇 系統(tǒng)時(shí)鐘SYSCLK 的除法因子(division factor ),這個(gè)
值可以是2,4,6,8
* @note You have to set the PLLP parameter correctly to not exceed 168 MHz on
* the System clock frequency.
* @注意 你需要正確設(shè)置PLLP,確保系統(tǒng)時(shí)鐘SYSCLK不超過(guò)168MHz
* @param PLLQ: specifies the division factor for OTG FS, SDIO and RNG clocks
* This parameter must be a number between 4 and 15.
@參數(shù) PLLQ 選擇給 OTG FS(USB), SDIO(SD卡讀寫), RNG(隨機(jī)數(shù)發(fā)生器)
時(shí)鐘的除法因子,其值介于4~15
* @note If the USB OTG FS is used in your application, you have to set the
* PLLQ parameter correctly to have 48 MHz clock for the USB. However,
* the SDIO and RNG need a frequency lower than or equal to 48 MHz to work
* correctly.
* @注意 如果在你的程序中用到 USB OTG FS,你需要正確設(shè)置PLLQ,確保USB有
48MHz的時(shí)鐘。但是對(duì)于SDIO,RNG需要一個(gè)小于或等于48MHz的時(shí)鐘
* @retval None
評(píng)論