新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > stm32f407時鐘配置方法例程解析

stm32f407時鐘配置方法例程解析

作者: 時間:2016-11-24 來源:網(wǎng)絡 收藏

/*到了這一步,我們已經(jīng)配置好了系統(tǒng)時鐘,頻率為168MHz.下面我們可以對AHB,APB,外設等的時鐘進行配置*/

/*時鐘的結(jié)構(gòu)請參考用戶手冊*/

/*首先配置AHB時鐘(HCLK).為了獲得較高的頻率,我們對SYSCLK 1分頻,得到HCLK*/

RCC_HCLKConfig(RCC_HCLK_Div1);

/*APBx時鐘(PCLK)由AHB時鐘(HCLK)分頻得到,下面我們配置PCLK*/

/*APB1時鐘配置. 4分頻,即PCLK1 = 42 MHz*/

RCC_PCLK1Config(RCC_HCLK_Div4);

/*APB2時鐘配置. 2分頻,即PCLK2 = 84 MHz*/

RCC_PCLK2Config(RCC_HCLK_Div2);

/*****函數(shù)結(jié)束******/

/*以上函數(shù)可以大體上說明這些庫函數(shù)的作用*/

}

對于 RCC_PLLConfig();函數(shù),大家可能會迷惑。

其函數(shù)原型為:

void RCC_PLLConfig(uint32_t RCC_PLLSource,

uint32_t PLLM,

uint32_t PLLN,

uint32_t PLLP,

uint32_t PLLQ);

迷惑的地方肯定在于后面4個參數(shù)PLLM / PLLN / PLLP / PLLQ.

在庫函數(shù)源文件 system_stm32f4xx.c中可以找到這4個參數(shù)的說明,請看下圖注釋部分:

(下面的是從 庫函數(shù)源文件 stm32f4xx_rcc.c 中找到的。其他函數(shù)可以直接去看庫函數(shù),注釋非常詳細)

/**

* @brief Configures the main PLL clock source, multiplication and division factors.

@簡介 配置主PLL時鐘源,以及分頻因子 (PLL不止一個,還有一個用來為音頻處理提供高質(zhì)量時鐘)

* @note This function must be used only when the main PLL is disabled.

* @注意 這個函數(shù)只能在主PLL失能時才能使用

* @param RCC_PLLSource: specifies the PLL entry clock source.

@參數(shù) RCC_PLLSource:選擇PLL時鐘源

* This parameter can be one of the following values:

這個參數(shù)可以是如下值:

* @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock entry

選擇HSI作為PLL時鐘源

* @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock entry

選擇HSE作為PLL時鐘源

* @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:設置 PLL VCO 輸入時鐘的 除法因子(division factor)

* This parameter must be a number between 0 and 63.

這個參數(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 來限制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輸出時鐘的 乘法因子(multiplication factor )

這個參數(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.

* @注意 你學要正確選PLLN的大小,以保證VCO輸出時鐘介于 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)時鐘SYSCLK 的除法因子(division factor ),這個

值可以是2,4,6,8

* @note You have to set the PLLP parameter correctly to not exceed 168 MHz on

* the System clock frequency.

* @注意 你需要正確設置PLLP,確保系統(tǒng)時鐘SYSCLK不超過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(隨機數(shù)發(fā)生器)

時鐘的除法因子,其值介于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,你需要正確設置PLLQ,確保USB有

48MHz的時鐘。但是對于SDIO,RNG需要一個小于或等于48MHz的時鐘

* @retval None


上一頁 1 2 下一頁

關(guān)鍵詞: stm32f407時鐘配置例程解

評論


技術(shù)專區(qū)

關(guān)閉