STM32F4 clock enable and configuration

Publisher:一条属马的龙Latest update time:2018-09-29 Source: eefocusKeywords:STM32F4 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the STM32F4 standard firmware library, the clock source selection and clock enable functions are declared and defined in the RCC related firmware library files stm32f4xx_rcc.h and stm32f4xx_rcc.c. When you open the stm32f4xx_rcc.h file, you can see that there are many macro definition identifiers at the beginning of the file, followed by a series of clock configuration and clock enable function declarations. These functions can be roughly divided into three categories: one is the peripheral clock enable function, one is the clock source and frequency division factor configuration function, and the other is the peripheral reset function. Of course, there are also several functions for obtaining the clock source configuration. Below we briefly introduce the use of these library functions with several common operations.

The first is the clock enable function. Clock enable related functions include peripheral setting enable and clock source enable. First, let's look at the peripheral clock enable related functions:

void   RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState);

void   RCC_AHB2PeriphClockCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState);

void   RCC_AHB3PeriphClockCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState);

void   RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);

void   RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);

There are mainly 5 peripheral clock enable functions. The 5 functions are used to enable the peripheral clocks mounted under the 5 buses, which are: AHB1 bus, AHB2 bus, AHB3 bus, APB1 bus and APB2 bus. To enable a peripheral, call the corresponding bus peripheral clock enable function.

  Here we have to explain that the clock of STM32F4 peripherals must be enabled before use. If the clock is not enabled, the peripherals will not work properly. As for which peripheral is mounted on which bus, although we can also check the manual, if you use the library function, it is actually not necessary to check the manual. Here we introduce a little trick.

  For example, if we want to enable GPIOA, we only need to search for GPIOA in the stm32f4xx_rcc.h header file, and we can find that the first entry parameter of the corresponding clock enable function is RCC_AHB1Periph_GPIOA. From this macro definition identifier, we can see at a glance that GPIOA is mounted under AHB1. Similarly, for serial port 1, we can search for USART1 and find the identifier RCC_APB2Periph_USART1, so it is easy to know that serial port 1 is mounted under APB2. This knowledge is also explained in the "4.7 Quick Code Organization Techniques" section below, so I will mention it here.

  If we want to enable GPIOA, we can find the macro definition identifier RCC_AHB1Periph_GPIOA in the header file stm32f4xx_rcc.h. As the name implies, GPIOA is mounted under the AHB1 bus, so we call the peripheral clock enable function RCC_AHB1PeriphClockCmd under the AHB1 bus. The specific calling method is as follows:

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //Enable GPIOA clock

Similarly, if we want to enable the clock of serial port 1, the function we call is:

void   RCC_AHB2PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState);

The specific calling method is:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);

Another type of clock enable function is the clock source enable function. We have already explained that STM32F4 has 5 major types of clock sources. Here we list several important clock source enable functions:

         void   RCC_HSICmd(FunctionalState NewState);

void   RCC_LSICmd(FunctionalState NewState);

void   RCC_PLLCmd(FunctionalState NewState);

void   RCC_PLLI2SCmd(FunctionalState NewState);

void   RCC_PLLSAICmd(FunctionalState NewState);

void   RCC_RTCCLKCmd(FunctionalState NewState);

These functions are used to enable the corresponding clock source. For example, if we want to enable the PLL clock, the function called is:

void   RCC_PLLCmd(FunctionalState NewState);

The specific calling method is as follows:

         RCC_PLLCmd(ENABLE);

We need to enable the corresponding clock source and call the corresponding function.

  Next we will explain the second type of clock function: clock source selection and frequency division factor configuration functions. These functions are used to select the corresponding clock source and configure the corresponding clock frequency division factor. For example, we have explained the system clock SYSCLK before. We can choose one of the three clock sources of HSI, HSE and PLL as the system clock. So which one to choose is configurable. Here are several clock source configuration functions:

         void       RCC_LSEConfig(uint8_t RCC_LSE);

void        RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource);

void        RCC_HCLKConfig(uint32_t RCC_SYSCLK);

void      RCC_PCLK1Config(uint32_t RCC_HCLK);

void      RCC_PCLK2Config(uint32_t RCC_HCLK);

void       RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource);

void        RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t PLLM,  

uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ);

For example, if we want to set the system clock source to HSI, we can call the system clock source configuration function:

void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource);

The specific configuration method is as follows:

void RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); //Configure the clock source to HSI

  For example, if we want to set the APB1 bus clock to 2 of HCLK, that is, set the division factor to 2, then if we want to enable HSI, the function to be called is:

void    RCC_PCLK1Config(uint32_t RCC_HCLK);

  The specific configuration method is as follows:

RCC_PCLK1Config(RCC_HCLK_Div2);

  Next, let's look at the third type of peripheral reset function. As follows:

void   RCC_AHB1PeriphResetCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState);

void   RCC_AHB2PeriphResetCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState);

void   RCC_AHB3PeriphResetCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState);

void   RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);

void   RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);

  The usage of this type of function is basically the same as the peripheral clock function explained above, the difference is that one is used to enable the peripheral clock, and the other is used to reset the corresponding peripheral. Don't be confused when calling the function here.

  We will not list these clock operation functions one by one. You can open the corresponding RCC file to learn more about it.


Keywords:STM32F4 Reference address:STM32F4 clock enable and configuration

Previous article:STM32f4---Marquee Experiment Code
Next article:STM32F4 clock initialization configuration

Recommended ReadingLatest update time:2024-11-17 05:38

STM32F4 three-way ADC simultaneous acquisition
Note that when the three ADCs are configured for DMA transfer, the addresses of ADC1-ADC3 need to be modified: #define ADC1_DR_Addr   ((uint32_t)0x4001204C) #define ADC2_DR_Addr   ((uint32_t)0x4001214C) #define ADC3_DR_Addr   ((uint32_t)0x4001224C)   The address definition above must be followed, otherwise
[Microcontroller]
STM32F407 study notes - Systick interrupt
#include   GPIO_TypeDef* io_led=GPIOC; const u16 pin_led=GPIO_Pin_1;   static __IO uint32_t TimingDelay;   void Led_Init() { GPIO_InitTypeDef GPIO_init_l; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); GPIO_init_l.GPIO_Pin=GPIO_Pin_1; GPIO_init_l.GPIO_Mode=GPIO_Mode_OUT; GPIO_init_l.GPIO_OType=GPIO_OTyp
[Microcontroller]
STM32F4 Marquee Experiment
Hardware connection: LEDs are connected to PF9 and PF10 pins respectively, and low level lights up the LEDs; Library functions used: head File  The source files all have header files corresponding to them, which need to be added to the project; Source files (lib directory)  misc.c (usually we will not delete this he
[Microcontroller]
Differences and comparisons of different DMA modes used by STM32F4 ADC module
These details are not explained in the original reference manual of STM32F4, but are listed briefly. I finally figured it out by checking the interface library that ST just released a few days ago, so I dare not keep it to myself! 1. STM32F4 has 3 independent ADC units with powerful performance. They can be used in
[Microcontroller]
stm32F4 encoder measures speed and prints through serial port --- program source code
1. Use cubeMX software to initialize the ports and resources needed by the program. In order to keep the program simple, only one serial port and one general timer are used here. (1) Pin initialization Note: There is no encoder mode in the pin configuration. I don't know why. The advanced registers are selected by th
[Microcontroller]
STM32F4 timer TIM(1) timer control output
Advanced clock control timer TIM1 & TIM8 introduction: The advanced control timer of STM32F4 contains an automatic reload counter, the input of the counter is a pre-divided system clock. This timer has a variety of uses, including vehicle input signal length (input capture mode) or generating waveform outputs (output
[Microcontroller]
Differences between STM32F4 and STM32F1
As the largest occupant of the Cortex M3 market, ST launched the STM32F4 series products based on the Cortex M4 core in 2011. Compared with Cortex M3 products such as STM32F1/F2, the biggest advantage of STM32F4 is the addition of hardware FPU unit and DSP instructions. At the same time, the main frequency of STM32F4
[Microcontroller]
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号