📄 stm32f4xx_rcc.c
字号:
*(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;
}
/**
* @brief Configures the External Low Speed oscillator (LSE).
* @note As the LSE is in the Backup domain and write access is denied to
* this domain after reset, you have to enable write access using
* PWR_BackupAccessCmd(ENABLE) function before to configure the LSE
* (to be done once after reset).
* @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_Bypass), the application
* software should wait on LSERDY flag to be set indicating that LSE clock
* is stable and can be used to clock the RTC.
* @param RCC_LSE: specifies the new state of the LSE.
* This parameter can be one of the following values:
* @arg RCC_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after
* 6 LSE oscillator clock cycles.
* @arg RCC_LSE_ON: turn ON the LSE oscillator
* @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock
* @retval None
*/
void RCC_LSEConfig(uint8_t RCC_LSE)
{
/* Check the parameters */
assert_param(IS_RCC_LSE(RCC_LSE));
/* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
/* Reset LSEON bit */
*(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
/* Reset LSEBYP bit */
*(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
/* Configure LSE (RCC_LSE_OFF is already covered by the code section above) */
switch (RCC_LSE)
{
case RCC_LSE_ON:
/* Set LSEON bit */
*(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_ON;
break;
case RCC_LSE_Bypass:
/* Set LSEBYP and LSEON bits */
*(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_Bypass | RCC_LSE_ON;
break;
default:
break;
}
}
/**
* @brief Enables or disables the Internal Low Speed oscillator (LSI).
* @note After enabling the LSI, the application software should wait on
* LSIRDY flag to be set indicating that LSI clock is stable and can
* be used to clock the IWDG and/or the RTC.
* @note LSI can not be disabled if the IWDG is running.
* @param NewState: new state of the LSI.
* This parameter can be: ENABLE or DISABLE.
* @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
* clock cycles.
* @retval None
*/
void RCC_LSICmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
*(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;
}
/**
* @brief Configures the main PLL clock source, multiplication and division factors.
* @note This function must be used only when the main PLL is disabled.
*
* @param RCC_PLLSource: specifies the PLL entry clock source.
* This parameter can be one of the following values:
* @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock entry
* @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock entry
* @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
* This parameter must be a number between 0 and 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.
*
* @param PLLN: specifies the multiplication factor for PLL VCO output clock
* This parameter must be a number between 192 and 432.
* @note You have to set the PLLN parameter correctly to ensure that the VCO
* output frequency is between 192 and 432 MHz.
*
* @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}.
* @note You have to set the PLLP parameter correctly to not exceed 168 MHz on
* the System clock frequency.
*
* @param PLLQ: specifies the division factor for OTG FS, SDIO and RNG clocks
* This parameter must be a number between 4 and 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.
*
* @retval None
*/
void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ)
{
/* Check the parameters */
assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));
assert_param(IS_RCC_PLLM_VALUE(PLLM));
assert_param(IS_RCC_PLLN_VALUE(PLLN));
assert_param(IS_RCC_PLLP_VALUE(PLLP));
assert_param(IS_RCC_PLLQ_VALUE(PLLQ));
RCC->PLLCFGR = PLLM | (PLLN << 6) | (((PLLP >> 1) -1) << 16) | (RCC_PLLSource) |
(PLLQ << 24);
}
/**
* @brief Enables or disables the main PLL.
* @note After enabling the main PLL, the application software should wait on
* PLLRDY flag to be set indicating that PLL clock is stable and can
* be used as system clock source.
* @note The main PLL can not be disabled if it is used as system clock source
* @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
* @param NewState: new state of the main PLL. This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void RCC_PLLCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
*(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;
}
/**
* @brief Configures the PLLI2S clock multiplication and division factors.
*
* @note This function must be used only when the PLLI2S is disabled.
* @note PLLI2S clock source is common with the main PLL (configured in
* RCC_PLLConfig function )
*
* @param PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
* This parameter must be a number between 192 and 432.
* @note You have to set the PLLI2SN parameter correctly to ensure that the VCO
* output frequency is between 192 and 432 MHz.
*
* @param PLLI2SR: specifies the division factor for I2S clock
* This parameter must be a number between 2 and 7.
* @note You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
* on the I2S clock frequency.
*
* @retval None
*/
void RCC_PLLI2SConfig(uint32_t PLLI2SN, uint32_t PLLI2SR)
{
/* Check the parameters */
assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
RCC->PLLI2SCFGR = (PLLI2SN << 6) | (PLLI2SR << 28);
}
/**
* @brief Enables or disables the PLLI2S.
* @note The PLLI2S is disabled by hardware when entering STOP and STANDBY modes.
* @param NewState: new state of the PLLI2S. This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void RCC_PLLI2SCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
*(__IO uint32_t *) CR_PLLI2SON_BB = (uint32_t)NewState;
}
/**
* @brief Enables or disables the Clock Security System.
* @note If a failure is detected on the HSE oscillator clock, this oscillator
* is automatically disabled and an interrupt is generated to inform the
* software about the failure (Clock Security System Interrupt, CSSI),
* allowing the MCU to perform rescue operations. The CSSI is linked to
* the Cortex-M4 NMI (Non-Maskable Interrupt) exception vector.
* @param NewState: new state of the Clock Security System.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void RCC_ClockSecuritySystemCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
*(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;
}
/**
* @brief Selects the clock source to output on MCO1 pin(PA8).
* @note PA8 should be configured in alternate function mode.
* @param RCC_MCO1Source: specifies the clock source to output.
* This parameter can be one of the following values:
* @arg RCC_MCO1Source_HSI: HSI clock selected as MCO1 source
* @arg RCC_MCO1Source_LSE: LSE clock selected as MCO1 source
* @arg RCC_MCO1Source_HSE: HSE clock selected as MCO1 source
* @arg RCC_MCO1Source_PLLCLK: main PLL clock selected as MCO1 source
* @param RCC_MCO1Div: specifies the MCO1 prescaler.
* This parameter can be one of the following values:
* @arg RCC_MCO1Div_1: no division applied to MCO1 clock
* @arg RCC_MCO1Div_2: division by 2 applied to MCO1 clock
* @arg RCC_MCO1Div_3: division by 3 applied to MCO1 clock
* @arg RCC_MCO1Div_4: division by 4 applied to MCO1 clock
* @arg RCC_MCO1Div_5: division by 5 applied to MCO1 clock
* @retval None
*/
void RCC_MCO1Config(uint32_t RCC_MCO1Source, uint32_t RCC_MCO1Div)
{
uint32_t tmpreg = 0;
/* Check the parameters */
assert_param(IS_RCC_MCO1SOURCE(RCC_MCO1Source));
assert_param(IS_RCC_MCO1DIV(RCC_MCO1Div));
tmpreg = RCC->CFGR;
/* Clear MCO1[1:0] and MCO1PRE[2:0] bits */
tmpreg &= CFGR_MCO1_RESET_MASK;
/* Select MCO1 clock source and prescaler */
tmpreg |= RCC_MCO1Source | RCC_MCO1Div;
/* Store the new value */
RCC->CFGR = tmpreg;
}
/**
* @brief Selects the clock source to output on MCO2 pin(PC9).
* @note PC9 should be configured in alternate function mode.
* @param RCC_MCO2Source: specifies the clock source to output.
* This parameter can be one of the following values:
* @arg RCC_MCO2Source_SYSCLK: System clock (SYSCLK) selected as MCO2 source
* @arg RCC_MCO2Source_PLLI2SCLK: PLLI2S clock selected as MCO2 source
* @arg RCC_MCO2Source_HSE: HSE clock selected as MCO2 source
* @arg RCC_MCO2Source_PLLCLK: main PLL clock selected as MCO2 source
* @param RCC_MCO2Div: specifies the MCO2 prescaler.
* This parameter can be one of the following values:
* @arg RCC_MCO2Div_1: no division applied to MCO2 clock
* @arg RCC_MCO2Div_2: division by 2 applied to MCO2 clock
* @arg RCC_MCO2Div_3: division by 3 applied to MCO2 clock
* @arg RCC_MCO2Div_4: division by 4 applied to MCO2 clock
* @arg RCC_MCO2Div_5: division by 5 applied to MCO2 clock
* @retval None
*/
void RCC_MCO2Config(uint32_t RCC_MCO2Source, uint32_t RCC_MCO2Div)
{
uint32_t tmpreg = 0;
/* Check the parameters */
assert_param(IS_RCC_MCO2SOURCE(RCC_MCO2Source));
assert_param(IS_RCC_MCO2DIV(RCC_MCO2Div));
tmpreg = RCC->CFGR;
/* Clear MCO2 and MCO2PRE[2:0] bits */
tmpreg &= CFGR_MCO2_RESET_MASK;
/* Select MCO2 clock source and prescaler */
tmpreg |= RCC_MCO2Source | RCC_MCO2Div;
/* Store the new value */
RCC->CFGR = tmpreg;
}
/**
* @}
*/
/** @defgroup RCC_Group2 System AHB and APB busses clocks configuration functions
* @brief System, AHB and APB busses clocks configuration functions
*
@verbatim
===============================================================================
System, AHB and APB busses clocks configuration functions
===============================================================================
This section provide functions allowing to configure the System, AHB, APB1 and
APB2 busses clocks.
1. Several clock sources can be used to drive the System clock (SYSCLK): HSI,
HSE and PLL.
The AHB clock (HCLK) is derived from System clock through configurable prescaler
and used to clock the CPU, memory and peripherals mapped on AHB bus (DMA, GPIO...).
APB1 (PCLK1) and APB2 (PCLK2) clocks are derived from AHB clock through
configurable prescalers and used to clock the peripherals mapped on these busses.
You can use "RCC_GetClocksFreq()" function to retrieve the frequencies of these clocks.
@note All the peripheral clocks are derived from the System clock (SYSCLK) except:
- I2S: the I2S clock can be derived either from a specific PLL (PLLI2S) or
from an external clock mapped on the I2S_CKIN pin.
You have to use RCC_I2SCLKConfig() function to configure this clock.
- RTC: the RTC clock can be derived either from the LSI, LSE or HSE clock
divided by 2 to 31. You have to use RCC_RTCCLKConfig() and RCC_RTCCLKCmd()
functions to configure this clock.
- USB OTG FS, SDIO and RTC: USB OTG FS require a frequency equal to 48 MHz
to work correctly, while the SDIO require a frequency equal or lower than
to 48. This clock is derived of the main PLL through PLLQ divider.
- IWDG clock which is always the LSI clock.
2. The maximum frequency of the SYSCLK and HCLK is 168 MHz, PCLK2 82 MHz and PCLK1 42 MHz.
Depending on the device voltage range, the maximum frequency should be
adapted accordingly:
+-------------------------------------------------------------------------------------+
| Latency | HCLK clock frequency (MHz) |
| |---------------------------------------------------------------------|
| | voltage range | voltage range | voltage range | voltage range |
| | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
|---------------|----------------|----------------|-----------------|-----------------|
|0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 18 |0 < HCLK <= 16 |
|---------------|----------------|----------------|-----------------|-----------------|
|1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |18 < HCLK <= 36 |16 < HCLK <= 32 |
|---------------|----------------|----------------|-----------------|-----------------|
|2WS(3CPU cycle)|60 < HCLK <= 90 |48 < HCLK <= 72 |36 < HCLK <= 54 |32 < HCLK <= 48 |
|---------------|----------------|----------------|-----------------|-----------------|
|3WS(4CPU cycle)|90 < HCLK <= 120|72 < HCLK <= 96 |54 < HCLK <= 72 |48 < HCLK <= 64 |
|---------------|----------------|----------------|-----------------|-----------------|
|4WS(5CPU cycle)|120< HCLK <= 150|96 < HCLK <= 120|72 < HCLK <= 90 |64 < HCLK <= 80 |
|---------------|----------------|----------------|-----------------|-----------------|
|5WS(6CPU cycle)|120< HCLK <= 168|120< HCLK <= 144|90 < HCLK <= 108 |80 < HCLK <= 96 |
|---------------|----------------|----------------|-----------------|-----------------|
|6WS(7CPU cycle)| NA |144< HCLK <= 168|108 < HCLK <= 120|96 < HCLK <= 112 |
|---------------|----------------|----------------|-----------------|-----------------|
|7WS(8CPU cycle)| NA | NA |120 < HCLK <= 138|112 < HCLK <= 120|
+-------------------------------------------------------------------------------------+
@note When VOS bit (in PWR_CR register) is reset to '0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -