Chapter 3 STM32 Clock and configuration Cortex Intelligent Processors by ARM
2 Chapter 3 STM32 Clock and Configuration
CONTENTS Objectives Clock System of STM32F103 Clock Configuration of STM32 sTM32 functions related to clock
3 CONTENTS • Objectives • Clock System of STM32F103 • Clock Configuration of STM32 • STM32 functions related to clock
3.1 Objectives All STM32 peripherals are driven by the clock, and every module uses independent clock to meet the low-power requirement. So STM32 clock system must be studied in detail to use peripherals properl
4 • 3.1 Objectives All STM32 peripherals are driven by the clock, and every module uses independent clock to meet the low-power requirement. So STM32 clock system must be studied in detail to use peripherals properly
3.2 STM32 Clock System There 5 clock sources in Stm32F103 HSI High Speed Internal) HSE(High Speed External LSI(Low Speed Internal) LSE(LOW Speed EXternal) PLL(Phase Locked Loop) Where, HIS, HSE, and pll can be used as system clock LSi and lse are second level clock The clock tree of stM32F103 is shown in Fig 11 on page 115 of the STM32 Reference Manual(RM)
5 3.2 STM32 Clock System There 5 clock sources in STM32F103: HSI (High Speed Internal) HSE (High Speed External) LSI (Low Speed Internal) LSE (Low Speed External) PLL(Phase Locked Loop) Where, HIS, HSE, and PLL can be used as System Clock. LSI and LSE are second level clock. The clock tree of STM32F103 is shown in Fig.11 on page 115 of the STM32 Reference Manual (RM)
The clock tree of stM32F103 is shown in Fig 11 on page 115 of the STM32 Reference Manual(RM) Figure 11. Clock tre KA加 A co memory and DM wm回a 123As
6 The clock tree of STM32F103 is shown in Fig.11 on page 115 of the STM32 Reference Manual (RM)
There are several clocks for mcu core and different peripherals. Why?
8 There are several clocks for MCU core and different peripherals. Why?
First reason High speed clock is used for high speed devices, like CPU, and low speed clock is used for low speed devices like peripherals Second reason This mode of clock is helpful to realize low power
9 Second reason This mode of clock is helpful to realize low power. First reason High speed clock is used for high speed devices, like CPU, and low speed clock is used for low speed devices like peripherals
Enable clock out Due to the requirement of low power, every module of stm32 microcontroller uses the clocks independently So, when we use a peripheral, we must enable its clock firstly. Otherwise, it will not work 10
10 Enable clock out Due to the requirement of low power, every module of STM32 microcontroller uses the clocks independently. So, when we use a peripheral, we must enable its clock firstly. Otherwise, it will not work
3.3 Clock configuration of stM32 In general, an embedded system should be initialized before it works In embedded system initialization, the system should be set up. The clock source should be considered in clock setup and PLL Should also be considered then the internal bus external bus and peripherals clock should be set up. The flow chart of clock setup is shown in Fig 3-1 Enable hse clock Set up AB clock according to the system clock RCC HCLK Config Set up APB2 clock according to AHB clock RCC HCLK2 Config Set up aPbl clock according to AHB clock RCC HCLKIConfig Select HIS, HSE or PLL as the system Set up system clock clock Enable peripherals ig. 3-1 Flow chart of clock setup RCC AHBPeriphClock Cmd
11 In general, an embedded system should be initialized before it works. In embedded system initialization, the system should be set up. The clock source should be considered in clock setup, and PLL should also be considered. Then the internal bus, external bus and peripherals clock should be set up. The flow chart of clock setup is shown in Fig.3-1. 3.3 Clock configuration of STM32 Enable HSE clock Set up AHB clock according to the system clock RCC_HCLKConfig Set up APB2 clock according to AHB clock RCC_HCLK2Config Set up APB1 clock according to AHB clock RCC_HCLK1Config Set up system clock Enable peripherals RCC_AHBPeriphClockCmd Select HIS, HSE or PLL as the system clock Fig. 3-1 Flow chart of clock setup