STM32F2XX RCC configuration

Publisher:水手谷水手Latest update time:2017-09-19 Source: eefocusKeywords:STM32F2XX Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. System clock configuration

STM32 has multiple clock sources, namely HSI, HSE, LSE, and LSI.

HSI Oscillator Clock:

The default clock when the system is powered on is the internal oscillator 8MHZ, which can be used directly as the system clock or as the input of the PLL after being divided by 2. The clock frequency accuracy is poor.

HSE oscillator clock external:

Provides a very accurate master clock, 8MHZ on the STM32F1 series board and 25MHZ on the STM32F2 series board. Multiplied by PLL: used as system clock.

The PLL clock source input can be half of the HSI clock or the HSE clock.

LSE Clock:

The LSE crystal is a 32.867k low speed external crystal. It provides a real-time clock. It is usually used exclusively for RTC and will be used when the RTC module is used.

LSI clock (Internal):

LSI's RC acts as a low-power clock source, which can keep running in shutdown and standby modes. It provides clocks for independent watchdog and automatic wake-up units. The LSI clock frequency is about 40KHZ. It is generally used for IWDGCLK.

The usual clock choice is HSE with PLL to make it work at 72MHZ (STM32F1 series) or 120MHZ (STM32F2 series).

STM32F1xx series

STM32F2XX series

The only difference between RCC_DeInit() and SystemInit() is that SystemInit() has an additional SetSysClock(). SystemInit() includes the entire configuration of the internal clock to the external clock, but the configured frequency is not adjustable. If you need to adjust the frequency, you can use RCC_DeInit() and other operations.

Clock configuration process:

1. Reset the RCC register to the default value RCC_DeInit;

2. Turn on the external high-speed clock crystal HSE RCC_HSEConfig (RCC_HSE_ON);

3. Wait for the external high-speed clock crystal to work HSEStartUpStatus =RCC_WaitForHSEStartUp();

4. Set AHB clock RCC_HCLKConfig;

5. Set high-speed APB2 clock RCC_PCLK2Config;

6. Set the low speed APB1 clock RCC_PCLK1Config

7. Set PLL RCC_PLLConfig;

8. Enable PLL RCC_PLLCmd(ENABLE);

9. Wait for PLL to work while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

10. Set the system clock RCC_SYSCLKConfig;

11. Determine whether PLL is the system clock while(RCC_GetSYSCLKSource() != 0x08);

12. Turn on the peripheral clock to be used RCC_APB2PeriphClockCmd()/RCC_APB1PeriphClockCmd();

/****************************************************** ****************************

* Function Name: RCC_Configuration

* Description: Configures the different system clocks.

* Input : None

* Output : None

* Return : None

*************************************************** *******************************/

void RCC_Configuration(void)

{

  /* RCC system reset(for debug purpose) */

  RCC_DeInit();

 

  /* Enable HSE */

  RCC_HSEConfig(RCC_HSE_ON);

 

  /* Wait till HSE is ready */

  HSEStartUpStatus = RCC_WaitForHSEStartUp();

 

  if(HSESTartUpStatus == SUCCESS)

  {

    /* Enable Prefetch Buffer */

    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

   

    /* HCLK = SYSCLK */

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

 

    /* PCLK2 = HCLK */

    RCC_PCLK2Config(RCC_HCLK_Div1);

 

    /* PCLK1 = HCLK */

    RCC_PCLK1Config(RCC_HCLK_Div1);

 

    /* Select HSE as system clock source */

    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

 

    /* Wait till HSE is used as system clock source */

    while(RCC_GetSYSCLKSource() != 0x04)

    {

    }

  }

XXXXXXXX; // Clock configuration for other peripherals respectively.

XXXXXXXX;

 

XXXXXXXX;

}

  

 

2. About PLL Settings

The PLL setting is mainly implemented through the function: void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ, uint32_t PLLR).

The main point is to talk about the relationship between the setting of PLL value and the clock of each part. The function involves the setting of 6 quantities, the first one is the selection of internal clock or external clock, and the following ones are the setting of PLL value.

RCC_PLLSource selection:

RCC_PLLSource_HIS: HIS internal clock is selected, the frequency is 16MHZ

RCC_PLLSource_HSE: HSE external clock selection, the frequency can be selected by yourself, between 4MHZ-26MHZ, the system default is 25MHZ, if you need to change, then change the 70th line in stm32f2xx.h

#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */

Modify it to the value of the external crystal oscillator.

l By selecting PLLM and PLLN, PLLVCO is calculated using the following formula:

PLLVCO = (HSE_VALUE / PLL_M) * PLL_N.

The value of PLL_M can be 0-63, and the value of PLL_N can be 192-432.

l Select the frequency division number by selecting PLLP to obtain the system clock. The calculation formula is as follows:

SYSCLK = PLLVCO / PLL_P. Remember not to exceed the maximum frequency of 120MHZ.

The PLLP options are 2, 4, 6, and 8.

l Select PLLQ to OTGFS, SDIO and RNG clocks. The calculation formula is as follows:

Clock = PLLVCO / PLLQ, cannot exceed 48MHZ.

PLL_Q can be 4-15.

l Determine the I2S clock by selecting PLLR. The calculation formula is as follows:

I2SCLK = PLLVCO / PLLR.

PLL_R can be 2-7.


Keywords:STM32F2XX Reference address:STM32F2XX RCC configuration

Previous article:Causes and solutions for insufficient STM32 stack allocation space
Next article:Application of STM32F2xx timer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号