STM32F051 application notes - system time selection and PLL frequency multiplication setting

Publisher:幸福自在Latest update time:2016-04-13 Source: eefocusKeywords:STM32F051 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
   For readers who are new to STM32 (or even ARM devices), after becoming familiar with the development environment, they often "fall" on the same problem. The key word in this problem is: clock tree.
   As we all know, the operation of microcontrollers (processors) must rely on periodic clock pulses to drive - often starting with an external crystal oscillator to provide clock input, and finally converted to the periodic operation of multiple external devices. The path of this clock "energy" diffusion flow is like the nutrients of a big tree flowing from the trunk to each branch, so it is often called a "clock tree". In some traditional low-end 8-bit microcontrollers such as 51, AVR, PIC and other microcontrollers, they also have their own clock tree system, but most of them are not controlled by users, that is, after the microcontroller is powered on, the clock tree is fixed in a certain unchangeable state (assuming that the microcontroller is in normal working state). For example, the 51 microcontroller uses a typical 12MHz crystal oscillator as the clock source, then the driving clock rate of peripherals such as IO ports, timers, serial ports and other devices is already fixed, and users cannot change this clock rate unless the crystal oscillator is replaced.
   The clock tree of the STM32 microcontroller is configurable, and there is no fixed relationship between the clock input source and the clock rate that ultimately reaches the peripheral. Different peripherals also have different clocks, and the corresponding clock must be turned on when using any peripheral. The advantage of this is that if a peripheral is not in use, its clock can be turned off, thereby reducing the power consumption of the system, achieving energy saving and low power consumption.
 
1. Startup code analysis—SystemInit (void) system clock initialization
SystemInit (void) is the system initialization function. Many novices don’t know where to call it. Xiao Xiao will explain it to you immediately.
The assembly code in the startup_stm32f0xx.s file is the STM32 startup code.
The steps to start the code are generally:
1) Initialization of heap and stack;
2) Vector table definition;
3) Address remapping and transfer of interrupt vector table;
4) Set the system clock frequency;
5) Initialization of interrupt register;
6) Enter the main program.
There is too much nonsense, and I guess you are tired of reading it. Now I will focus on the key points, especially step 4. (Steps 5 and 6 are usually executed in user code during programming).
Reset_Handler
PROC; marks the beginning of a function, which is also the reset entry.
IMPORT
__main ; tells the compiler to use the label in other files
IMPORT
SystemInit; Same as above
Here is the key.
LDR
R0, =SystemInit;
The "=" here means that LDR is currently a pseudo instruction, not a standard instruction. Here, the address of SystemInit is given to RO. That is, SystemInit (void) is called and compiled here. Therefore, users do not need to write a PLL configuration program when writing a program.
BX
R0; BX is the program jump between the ARM instruction set and the THUMB instruction set.
Others are omitted. Details are shown in the figure below:
 
After SystemInit initializes RCC, it calls SetSysClock(void) to set the system clock.
code show as below:
void SystemInit (void)
{
RCC->CR |= (uint32_t)0x00000001;
RCC->CFGR &= (uint32_t)0xF8FFB80C;
RCC->CR &= (uint32_t)0xFEF6FFFF;
RCC->CR &= (uint32_t)0xFFFBFFFF;
RCC->CFGR &= (uint32_t)0xFFC0FFFF;
RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
RCC->CFGR3 &= (uint32_t)0xFFFFFEAC;
RCC->CR2 &= (uint32_t)0xFFFFFFFE;
RCC->CIR = 0x00000000;
SetSysClock();
}
 
2. SetSysClock() sets the system clock
Since PLL_SOURCE_HSE was defined earlier, conditional compilation is performed.
RCC->CR |= ((uint32_t)RCC_CR_HSEON); // Enable HSE, as shown below:
 
Wait for HSE to be set up. The code is as follows.
 
 
do
{
HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
 
if ((RCC->CR & RCC_CR_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
 
The setting is completed, HSEStatus is assigned a value of 1, and the code is as follows:
if ((RCC->CR & RCC_CR_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
 
HSEStatus HSE==1 indicates that the HSE status is normal, enabling the buffer and setting the FLASH delay, HCLK\PCLK. The PLL frequency multiplication is shown in the red line in the figure below. Modify RCC_CFGR_PLLMULL to achieve frequency multiplication (default 6 times).

Keywords:STM32F051 Reference address:STM32F051 application notes - system time selection and PLL frequency multiplication setting

Previous article:Introduction to STM32 study notes
Next article:Things to note when doing ARM bare metal C and programming

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号