STM32 M0 clock configuration

Publisher:SereneNature7Latest update time:2018-08-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This article mainly talks about the clock configuration of STM32 M0.

Let's first look at the clock tree of the M0 core (stm32f072)


As can be seen from the figure, the M0 chip has 4 clock sources, a high-speed internal RC clock source with a frequency of 8M; a high-speed external clock source with a frequency of 8 to 32MHz; a low-speed external clock source with a frequency of generally 32.768kHz; a low-speed internal clock source with a frequency of 40kHz;

1. HSI

When the chip is powered on, the internal RC oscillation is enabled by default, that is, the internal clock source of 8MHz. If the clock requirement is not very high, using the internal clock is sufficient, saving the money for an external crystal oscillator.

Let's first talk about the configuration of using the internal clock. The official demo uses the internal clock by default. Let's start with the clock tree analysis, HSI (8MHz) startup, through PLLSRC (phase-locked loop clock source selection register), and then to PREDIV (prescaler), the prescaler selects no frequency division, and then PLLMUL (phase-locked loop multiplier), here the frequency is multiplied by 6 times, and the frequency is 48MHz. Be careful not to exceed 48MHz, the maximum supported by the chip is 48MHz. Then SW (clock source selection register), here select PLLCLK (phase-locked loop clock after multiplication), in fact, here you can directly select the 8MHz internal clock, not PLLCLK. The final choice of SW is our machine clock.

II. HSE

HSE means high-speed external clock. In order to obtain a lower temperature drift and a more stable clock, an external crystal oscillator is generally selected. If an external crystal oscillator is added, the external clock selection register needs to be turned on, and then the external clock oscillates stably. The stable waiting time needs to be selected according to different oscillation frequencies. After waiting for the external clock to oscillate stably, come to PLLSRC, where HSE is selected. Assuming that the external crystal oscillator is 8MHz, PREDIV is also selected as non-divided, PLLMUL is selected as 6 times frequency, and the clock source is selected as HSE in SW, then the machine clock of the chip is 48MHz.

Observe the SW register, there is a CSS option, which is a clock safety selection register. Its function is to switch to HSI immediately when the external crystal oscillator suddenly stops working. When the program is running, the external crystal oscillator stops oscillating, and the system will immediately switch to the internal clock. At this time, a synchronous abnormal interrupt will be generated, and the interrupt level is negative and cannot be modified. In the interrupt, the HSI frequency is divided and multiplied by itself, and then the main clock is changed to the required machine clock. CSS is only meaningful after HSE is turned on. If the internal clock is used, this option can be ignored. Of course, this option can also be chosen not to be turned on, and it is not turned on by default.

3. LSE

The low-speed external clock also needs to be configured and enabled. After it is enabled and the oscillation is stable, the RTCCLK (real-time clock selection register) selects LSE, which is used to provide a clock source for the internal RTC. As for why it is 32.768kHz, this article does not intend to explain it in detail. Please search on Baidu. LSE can also be used as a machine clock source. I have not tried it, and I believe no one has done it. If you have, please introduce your experience and purpose.

4. LSI

The low-speed internal clock is the internal dedicated clock that provides the internal watchdog register. The watchdog time setting is on this clock line. The watchdog time is generally selected in seconds. My opinion is that the longer the time, the better. One thing to note about the use of the watchdog is that whether it is bare-metal development or development with RTOS, the watchdog cannot be fed in an interrupt. The entire code can and can only have one place to feed the watchdog. Of course, if you insist on feeding the watchdog once in the infinite loop of tasks A, B, and C, that's fine, but if the reader really adopts this approach, it is recommended to seriously think about whether there is room for improvement in the software architecture.

5. I2C1

The I2C interface clock can be selected from HSI or machine clock

6. I2S

I2S can only select the machine clock

VII. AHB

The basic peripheral clock source pre-divides the machine clock to obtain the required frequency and supplies it to the peripherals on the AHB bus according to the needs. DMA, SRAM, FLITFEN, CRC, GPIO, TSC and other peripherals are directly mounted on this clock bus. After the division, there is another way to supply APB, which also has a pre-divider, and USART and TIM are mounted. The clock source selection of USART is relatively rich. You can choose PCLK from APB, or directly select the machine clock, HSI, LSE, etc.; TIM clock also has a pre-divider, called APB1, the purpose is to obtain the required timing time or pulse width frequency.


The basic clock of STM32M0 is basically finished here. At first glance, this clock diagram is still quite complicated, just like when learning analog circuits, directly taking the schematic diagram of the switching power supply to look at it is like reading a book of heaven, but if you can calm down and chew it bit by bit, you can still slowly understand it. Recently, various chip manufacturers have developed their own code generation tools, which are much more convenient for development and lower the development threshold. However, if you can have a deep understanding of the chip (of course, you don’t have to go deep into the IP layer), when problems occur, DEBUG can be faster. To borrow a sentence from Song Baohua: Sooner or later, you will have to pay back for what you have done. What you don’t understand today but are unwilling to understand, when the problem reappears in the future, it is time to pay back.


Keywords:STM32 Reference address:STM32 M0 clock configuration

Previous article:stm32f103 clock tree explanation
Next article:stm32l476 clock settings

Recommended ReadingLatest update time:2024-11-16 14:58

Understanding of 8 modes of STM32 GPIO
1. Pull-up input: Pull-up means pulling the potential up, such as pulling it to Vcc. Pull-up means embedding an uncertain signal at a high level through a resistor! The resistor also acts as a current limiter! Weak and strong are just different in the resistance value of the pull-up resistor, and there is no strict di
[Microcontroller]
Understanding of 8 modes of STM32 GPIO
STM32 implements DAC output related settings
Introduction to STM32 DAC         The large-capacity STM32F103 has an internal DAC. The battleship STM32 selected is the STM32F103ZET6, which is a large-capacity product, so it has a DAC module. The DAC module (digital/analog conversion module) of STM32 is a 12-bit digital input, voltage output DAC. The DAC can be con
[Microcontroller]
STM32 implements DAC output related settings
STM32 operation access internal Flash
Table of contents: 1. STM32 FLASH operation process 2. Basic knowledge of Flash 3. OK, let’s get started and get some code ------------------------------------------------------------------------------------------------- The storage area in STM32 is divided into random access memory RAM and read-only memory RO
[Microcontroller]
STM32 operation access internal Flash
STM32 FSMC control LCD function explanation
I encountered this problem while doing the project. I think the article is well written. I would like to share it with my colleagues who have doubts about the use of FSMC! LCD has the following control lines: CS: Chip Select, low level valid RS: Register Select WR: Write signal, low level valid RD: Read signal, low l
[Microcontroller]
STM32 CAN bus basics
CAN bus protocol overview:   CAN is the abbreviation of Controller Area Network, which was developed by Bosch of Germany. CAN is standardized by ISO11891 and ISO11519.        Characteristics of CAN bus:     1. Multi-master control       When the bus is idle, all units can start sending messages (multi-master
[Microcontroller]
STM32 CAN bus basics
STM32 system clock configuration and clock tree
Reference: "STM32F4xx Chinese Reference Manual" RCC chapter. The STM32 clock can be roughly divided into two categories: system clock and other clocks, including a total of 5 clock sources: HSI (High Speed ​​Internal Clock), HSE (High Speed ​​External Clock), LSI (low Speed ​​Internal Clock), LSE (Low Speed ​​Extern
[Microcontroller]
STM32 system clock configuration and clock tree
STM32 analog IIC read and write 24CXX
File (iic.h): #define SDA_IN()  {GPIOB- CRL&=0X0FFFFFFF;GPIOB- CRL|=0X80000000;} #define SDA_OUT() {GPIOB- CRL&=0X0FFFFFFF;GPIOB- CRL|=0X30000000;} #define IIC_SCL    PBout(6)  #define IIC_SDA    PBout(7)   #define READ_SDA   PBin(7)  void bsp_iic_init(void);                              void bsp_iic_start(void)
[Microcontroller]
Self-understanding of the function of reading status flag bits in stm32
In order to allow the program to read the status of multiple status flags, the firmware designs a general function RCC_GetStatus() to read the status of each flag. The following are all the RCC flags: *                       - RCC_FLAG_HSIRDY: HSI oscillator clock ready   *                       - RCC_FLAG_HSERDY:
[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号