SlideShare a Scribd company logo
1 of 37
Clocks
Understanding HSI,HSE,PLL,HCLK,PCLKx
and configuration
For full video course on Microcontroller and RTOS
programming please visit : www.fastbitlab.com
All courses are hosted on
Udemy.com
Click here to enroll FREE !!!!
http://bit.ly/2P47IeX
Click here to watch free preview and enroll
http://bit.ly/2QaW0M9
Click here to watch free preview and enroll
http://bit.ly/2SA2uFO
Click here to watch free preview and enroll
http://bit.ly/2PAQRQh
Click here to watch free preview and enroll
http://bit.ly/2AEcneA
Click here to watch free preview and enroll
http://bit.ly/2zhqDrX
Click here to watch free preview and enroll
http://bit.ly/2OjgFf7
System Clock(SYSCLK)
• Three different clock sources can be used to drive the system clock
(SYSCLK):
– HSI oscillator clock
– HSE oscillator clock
– Two main PLL (PLL) clocks
• The devices have the two following secondary clock sources
– 32 kHz low-speed internal RC (LSI RC) which drives the independent
watchdog and, optionally, the RTC used for Auto-wakeup from the
Stop/Standby mode.
– 32.768 kHz low-speed external crystal (LSE crystal) which optionally
drives the RTCclock (RTCCLK)
NUCLEO-F446RE board
• HSI  16MHz (Internal to MCU)
• HSE 8MHz (External to MCU)
• PLL can generate clock up to 180MHz (Internal
to MCU)
• LSI32kHz (Internal to MCU)
• LSE32.768kHz (External to MCU)
Default Clock State
After reset of the MCU,
HSI is ON, HSE is OFF , PLL is OFF, LSE is OFF,
LSI is OFF
So, SYSCLK is sourced by HSI .
I.e : SYSCLK = 16MHz
Each clock source can be switched on or off independently when it is not used, to
optimize power consumption.
The HSI is used (enabled by hardware) as system clock source after startup from
Reset, wake-up from STOP and STANDBY mode, or in case of failure of the HSE used
directly or indirectly as system clock
The HSI RC oscillator has the advantage of providing a clock source at low cost (no
external components).
It also has a faster startup time than the HSE crystal oscillator.
However, even with calibration the frequency is less accurate than an external crystal
oscillator or ceramic resonator
The HSI signal can also be used as a backup source (auxiliary clock) if the HSE crystal
oscillator fails.
HSI
STM32 Cube Clock Handling APIs
STM32 HAL RCC Driver
stm32f4xx_hal_rcc.c
stm32f4xx_hal_rcc_ex.c
stm32f4xx_hal_rcc.h
stm32f4xx_hal_rcc_ex.h
Source header
ex = Extension
Methods to configure the STSCLK
Source
• First Enable the required clock and wait until the clock is
ready . If your application needs PLL, then configure the PLL
and enable it.
• Initializes the CPU, AHB and APB busses clock prescalers
according to your application requirements . Do not cross
maximum limits.
• Configure the flash latency properly by referring to MCU RM
• Select newly enabled Clock as SYSCLK
STM32 Cube Clock Handling APIs
1) HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
2) HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct,
uint32_t FLatency)
RCC_OscInitTypeDef
RCC Internal/External
Oscillator (HSE, HSI, LSE and
LSI) configuration structure
definition
RCC_ClkInitTypeDef
RCC System, AHB and APB
busses clock configuration
structure definition
HSI Calibration
The operating temperature has an impact on the accuracy of
the RC oscillators. At 25 °C, the HIS oscillators have an accuracy
of ±1% typically, but in the temperature range of -40 to 105 °C,
the accuracy decreases.
To compensate for the influence of temperature in the application,
the output frequency of the HSI oscillator can be further trimmed
by the user runtime calibration routine to improve the HSI
frequency accuracy. This may prove crucial for communication
peripherals.
HSI Calibration adjustment
HSI RC oscillators are factory
calibrated by ST to have a 1%
accuracy at TA = 25 °C. After
reset, the factory calibration
value is automatically loaded in
the internal calibration bits.
HSI Calibration adjustment
The frequency of the internal RC oscillators
can be fine-tuned to achieve better accuracy
with wider temperature and supply voltage
ranges. The trimming bits are used for this
purpose.
the calibration value is loaded in
HSICAL[7:0] bits after reset. Five
trimming bits HSITRIM[4:0] are
used for fine-tuning. The default
trimming value is 16
HSI Calibration adjustment
• Effect of HSITRIM[4:0]
– The default trimming value is 16
– An increase in this trimming value causes an increase
in HSI frequency
– Decrease in this trimming value causes an decrease in
HSI frequency
– The HSI oscillator is fine-tuned in steps of 0.5%
(around 80 kHz)
HSI Calibration adjustment
• Summary
– Writing a trimming value in the range of 17 to 31
increases the HSI frequency.
– Writing a trimming value in the range of 0 to 15
decreases the HSI frequency
– Writing a trimming value equal to 16 causes the
HSI frequency to keep its default value. (+- 1%)
HSE BYPASS
HSE BYPASS-NUCLEO-F446RE
Main MCUST link MCU
STLINK CKT
OSC_IN
MCO
PA8
8MHz
Exercise
Using HSE Configure the SYSCLK as 8MHz.
AHB clock as 4MHz (HCLK)
APB1 clock as 2MHz (PCLK1)
APB2 clock as 2MHz (PCLK2)
PLL(Phase Locked Loop)
• The PLL engine of the MCU is used to generate
different high frequency output clocks by
taking input clock sources such as HSE or HSI.
• By using PLL you can drive SYSCLK up to
180MHz in STM32F446RE MCU
Main PLL
VCO /P
/Q
/R
/M
X N
PLL Source Mux
PLLCLK
HSE
HSI 16MHz
8MHz
f(vco input clock) f(vco output clock)
Main PLL
VCO/M
PLL Source Mux
HSE
HSI 16MHz
8MHz
Division factor for the main PLL (PLL) input clock
1MHz < f(vco input clock) <= 2MHz
f(vco input clock) f(vco output clock)
Main PLL
VCO/M
PLL Source Mux
HSE
HSI 16MHz
8MHz
Main PLL (PLL) multiplication factor for VCO
1MHz < f(vco input clock) <= 2MHz
f(vco input clock) f(vco output clock)
X N
100MHz<=f(vco output clock) <= 432MHz
PLL Formulas
PLLCLKPLLCLK
Exercise
• Write an application to generate below HCLK
Frequencies using PLL . Use HSI as PLL’s input
source and repeat the exercise using HSE as
input source.
– 50MHz
– 84MHz
– 120MHz
PLL configuration
VCO /P
/Q
/R
/M
X N
PLL Source Mux
PLLCLK
HSE
HSI 16MHz
8MHz
f(vco input clock) f(vco output clock)
PLL configuration
SYSCLK HCLK
AHB
Prescaler
PLLCLK
50MHz
PLL configuration
SYSCLK HCLK
AHB
Prescaler
PLLCLK
84MHz
PLL configuration
SYSCLK HCLK
AHB
Prescaler
PLLCLK
120MHz
Exercise
• Write an application which does PLL
configuration to boost the HCLK to maximum
capacity (for STM32F446RE it is:180MHz). Use
HSE as PLL Source.

More Related Content

What's hot

What's hot (20)

ARM - Advance RISC Machine
ARM - Advance RISC MachineARM - Advance RISC Machine
ARM - Advance RISC Machine
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
Introduction to arm architecture
Introduction to arm architectureIntroduction to arm architecture
Introduction to arm architecture
 
Introduction to armv8 aarch64
Introduction to armv8 aarch64Introduction to armv8 aarch64
Introduction to armv8 aarch64
 
Msp 430 architecture module 1
Msp 430 architecture module 1Msp 430 architecture module 1
Msp 430 architecture module 1
 
Interrupts
InterruptsInterrupts
Interrupts
 
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processor
 
ARM architcture
ARM architcture ARM architcture
ARM architcture
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
CPU Verification
CPU VerificationCPU Verification
CPU Verification
 
Intro to Embedded OS, RTOS and Communication Protocols
Intro to Embedded OS, RTOS and Communication ProtocolsIntro to Embedded OS, RTOS and Communication Protocols
Intro to Embedded OS, RTOS and Communication Protocols
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
Arm processor
Arm processorArm processor
Arm processor
 
Introduction to stm32-part1
Introduction to stm32-part1Introduction to stm32-part1
Introduction to stm32-part1
 
embedded-systems-for-beginners
embedded-systems-for-beginnersembedded-systems-for-beginners
embedded-systems-for-beginners
 
Arm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_modelArm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_model
 
Arm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_armArm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_arm
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
PART-1 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-1 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingPART-1 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-1 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
 

Similar to STM32 Microcontroller Clocks and RCC block

Stm32f303 rest and Clock contol
Stm32f303 rest and Clock contolStm32f303 rest and Clock contol
Stm32f303 rest and Clock contolPrem Sanil
 
Pll in lpc2148
Pll in lpc2148Pll in lpc2148
Pll in lpc2148Aarav Soni
 
ESD III UNIT.pptx
ESD III UNIT.pptxESD III UNIT.pptx
ESD III UNIT.pptxECEHOD19
 
Lecture on PIC-1.pptx
Lecture on PIC-1.pptxLecture on PIC-1.pptx
Lecture on PIC-1.pptxgodfrey35
 
Microchip NANOWatt Technology
Microchip NANOWatt TechnologyMicrochip NANOWatt Technology
Microchip NANOWatt TechnologyEmanuele Bonanni
 
Overview of LPC213x MCUs
Overview of LPC213x MCUsOverview of LPC213x MCUs
Overview of LPC213x MCUsPremier Farnell
 
An Overview of LPC2101/02/03
An Overview of LPC2101/02/03An Overview of LPC2101/02/03
An Overview of LPC2101/02/03Premier Farnell
 
Manual cpu clocking system
Manual cpu clocking systemManual cpu clocking system
Manual cpu clocking systemreanto vilchez
 
Overview of LPC214x MCUs
Overview of LPC214x MCUsOverview of LPC214x MCUs
Overview of LPC214x MCUsPremier Farnell
 
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summary
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summaryAtmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summary
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summaryRajan Gautam
 
Q46S-66-Auto-Chem-Sulfite-Monitor.pdf
Q46S-66-Auto-Chem-Sulfite-Monitor.pdfQ46S-66-Auto-Chem-Sulfite-Monitor.pdf
Q46S-66-Auto-Chem-Sulfite-Monitor.pdfENVIMART
 
MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED pH...
MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED  pH...MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED  pH...
MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED pH...Abhijeet Powar
 
Q46F-82-Auto-Chem-Fluoride-Monitor.pdf
Q46F-82-Auto-Chem-Fluoride-Monitor.pdfQ46F-82-Auto-Chem-Fluoride-Monitor.pdf
Q46F-82-Auto-Chem-Fluoride-Monitor.pdfENVIMART
 
03 Mcu Day 2009 (C2000) 8 13 Editado
03   Mcu Day 2009 (C2000) 8 13   Editado03   Mcu Day 2009 (C2000) 8 13   Editado
03 Mcu Day 2009 (C2000) 8 13 EditadoTexas Instruments
 
Getting Started with RS08 MCUs
Getting Started with RS08 MCUsGetting Started with RS08 MCUs
Getting Started with RS08 MCUsPremier Farnell
 

Similar to STM32 Microcontroller Clocks and RCC block (20)

Stm32f303 rest and Clock contol
Stm32f303 rest and Clock contolStm32f303 rest and Clock contol
Stm32f303 rest and Clock contol
 
Pll in lpc2148
Pll in lpc2148Pll in lpc2148
Pll in lpc2148
 
HCS08 Overview
HCS08 OverviewHCS08 Overview
HCS08 Overview
 
ESD III UNIT.pptx
ESD III UNIT.pptxESD III UNIT.pptx
ESD III UNIT.pptx
 
Lecture on PIC-1.pptx
Lecture on PIC-1.pptxLecture on PIC-1.pptx
Lecture on PIC-1.pptx
 
Microchip NANOWatt Technology
Microchip NANOWatt TechnologyMicrochip NANOWatt Technology
Microchip NANOWatt Technology
 
Overview of LPC213x MCUs
Overview of LPC213x MCUsOverview of LPC213x MCUs
Overview of LPC213x MCUs
 
SIMH multi-system simulator
SIMH multi-system simulatorSIMH multi-system simulator
SIMH multi-system simulator
 
An Overview of LPC2101/02/03
An Overview of LPC2101/02/03An Overview of LPC2101/02/03
An Overview of LPC2101/02/03
 
pic_1.pdf
pic_1.pdfpic_1.pdf
pic_1.pdf
 
Manual cpu clocking system
Manual cpu clocking systemManual cpu clocking system
Manual cpu clocking system
 
Overview of LPC214x MCUs
Overview of LPC214x MCUsOverview of LPC214x MCUs
Overview of LPC214x MCUs
 
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summary
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summaryAtmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summary
Atmel 42735-8-bit-avr-microcontroller-a tmega328-328-p_summary
 
Q46S-66-Auto-Chem-Sulfite-Monitor.pdf
Q46S-66-Auto-Chem-Sulfite-Monitor.pdfQ46S-66-Auto-Chem-Sulfite-Monitor.pdf
Q46S-66-Auto-Chem-Sulfite-Monitor.pdf
 
MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED pH...
MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED  pH...MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED  pH...
MIXED SIGNAL VLSI TECHNOLOGY BASED SoC DESIGN FOR TEMPERATURE COMPENSATED pH...
 
Xmega d4 microcontroller
Xmega d4 microcontrollerXmega d4 microcontroller
Xmega d4 microcontroller
 
Q46F-82-Auto-Chem-Fluoride-Monitor.pdf
Q46F-82-Auto-Chem-Fluoride-Monitor.pdfQ46F-82-Auto-Chem-Fluoride-Monitor.pdf
Q46F-82-Auto-Chem-Fluoride-Monitor.pdf
 
2502s
2502s2502s
2502s
 
03 Mcu Day 2009 (C2000) 8 13 Editado
03   Mcu Day 2009 (C2000) 8 13   Editado03   Mcu Day 2009 (C2000) 8 13   Editado
03 Mcu Day 2009 (C2000) 8 13 Editado
 
Getting Started with RS08 MCUs
Getting Started with RS08 MCUsGetting Started with RS08 MCUs
Getting Started with RS08 MCUs
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

STM32 Microcontroller Clocks and RCC block

  • 2. For full video course on Microcontroller and RTOS programming please visit : www.fastbitlab.com All courses are hosted on Udemy.com
  • 3. Click here to enroll FREE !!!! http://bit.ly/2P47IeX
  • 4. Click here to watch free preview and enroll http://bit.ly/2QaW0M9
  • 5. Click here to watch free preview and enroll http://bit.ly/2SA2uFO
  • 6. Click here to watch free preview and enroll http://bit.ly/2PAQRQh
  • 7. Click here to watch free preview and enroll http://bit.ly/2AEcneA
  • 8. Click here to watch free preview and enroll http://bit.ly/2zhqDrX
  • 9. Click here to watch free preview and enroll http://bit.ly/2OjgFf7
  • 10. System Clock(SYSCLK) • Three different clock sources can be used to drive the system clock (SYSCLK): – HSI oscillator clock – HSE oscillator clock – Two main PLL (PLL) clocks • The devices have the two following secondary clock sources – 32 kHz low-speed internal RC (LSI RC) which drives the independent watchdog and, optionally, the RTC used for Auto-wakeup from the Stop/Standby mode. – 32.768 kHz low-speed external crystal (LSE crystal) which optionally drives the RTCclock (RTCCLK)
  • 11. NUCLEO-F446RE board • HSI  16MHz (Internal to MCU) • HSE 8MHz (External to MCU) • PLL can generate clock up to 180MHz (Internal to MCU) • LSI32kHz (Internal to MCU) • LSE32.768kHz (External to MCU)
  • 12. Default Clock State After reset of the MCU, HSI is ON, HSE is OFF , PLL is OFF, LSE is OFF, LSI is OFF So, SYSCLK is sourced by HSI . I.e : SYSCLK = 16MHz Each clock source can be switched on or off independently when it is not used, to optimize power consumption.
  • 13. The HSI is used (enabled by hardware) as system clock source after startup from Reset, wake-up from STOP and STANDBY mode, or in case of failure of the HSE used directly or indirectly as system clock The HSI RC oscillator has the advantage of providing a clock source at low cost (no external components). It also has a faster startup time than the HSE crystal oscillator. However, even with calibration the frequency is less accurate than an external crystal oscillator or ceramic resonator The HSI signal can also be used as a backup source (auxiliary clock) if the HSE crystal oscillator fails. HSI
  • 14. STM32 Cube Clock Handling APIs STM32 HAL RCC Driver stm32f4xx_hal_rcc.c stm32f4xx_hal_rcc_ex.c stm32f4xx_hal_rcc.h stm32f4xx_hal_rcc_ex.h Source header ex = Extension
  • 15. Methods to configure the STSCLK Source • First Enable the required clock and wait until the clock is ready . If your application needs PLL, then configure the PLL and enable it. • Initializes the CPU, AHB and APB busses clock prescalers according to your application requirements . Do not cross maximum limits. • Configure the flash latency properly by referring to MCU RM • Select newly enabled Clock as SYSCLK
  • 16. STM32 Cube Clock Handling APIs 1) HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) 2) HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
  • 17. RCC_OscInitTypeDef RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  • 18. RCC_ClkInitTypeDef RCC System, AHB and APB busses clock configuration structure definition
  • 19. HSI Calibration The operating temperature has an impact on the accuracy of the RC oscillators. At 25 °C, the HIS oscillators have an accuracy of ±1% typically, but in the temperature range of -40 to 105 °C, the accuracy decreases. To compensate for the influence of temperature in the application, the output frequency of the HSI oscillator can be further trimmed by the user runtime calibration routine to improve the HSI frequency accuracy. This may prove crucial for communication peripherals.
  • 20. HSI Calibration adjustment HSI RC oscillators are factory calibrated by ST to have a 1% accuracy at TA = 25 °C. After reset, the factory calibration value is automatically loaded in the internal calibration bits.
  • 21. HSI Calibration adjustment The frequency of the internal RC oscillators can be fine-tuned to achieve better accuracy with wider temperature and supply voltage ranges. The trimming bits are used for this purpose. the calibration value is loaded in HSICAL[7:0] bits after reset. Five trimming bits HSITRIM[4:0] are used for fine-tuning. The default trimming value is 16
  • 22. HSI Calibration adjustment • Effect of HSITRIM[4:0] – The default trimming value is 16 – An increase in this trimming value causes an increase in HSI frequency – Decrease in this trimming value causes an decrease in HSI frequency – The HSI oscillator is fine-tuned in steps of 0.5% (around 80 kHz)
  • 23. HSI Calibration adjustment • Summary – Writing a trimming value in the range of 17 to 31 increases the HSI frequency. – Writing a trimming value in the range of 0 to 15 decreases the HSI frequency – Writing a trimming value equal to 16 causes the HSI frequency to keep its default value. (+- 1%)
  • 25. HSE BYPASS-NUCLEO-F446RE Main MCUST link MCU STLINK CKT OSC_IN MCO PA8 8MHz
  • 26. Exercise Using HSE Configure the SYSCLK as 8MHz. AHB clock as 4MHz (HCLK) APB1 clock as 2MHz (PCLK1) APB2 clock as 2MHz (PCLK2)
  • 27. PLL(Phase Locked Loop) • The PLL engine of the MCU is used to generate different high frequency output clocks by taking input clock sources such as HSE or HSI. • By using PLL you can drive SYSCLK up to 180MHz in STM32F446RE MCU
  • 28. Main PLL VCO /P /Q /R /M X N PLL Source Mux PLLCLK HSE HSI 16MHz 8MHz f(vco input clock) f(vco output clock)
  • 29. Main PLL VCO/M PLL Source Mux HSE HSI 16MHz 8MHz Division factor for the main PLL (PLL) input clock 1MHz < f(vco input clock) <= 2MHz f(vco input clock) f(vco output clock)
  • 30. Main PLL VCO/M PLL Source Mux HSE HSI 16MHz 8MHz Main PLL (PLL) multiplication factor for VCO 1MHz < f(vco input clock) <= 2MHz f(vco input clock) f(vco output clock) X N 100MHz<=f(vco output clock) <= 432MHz
  • 32. Exercise • Write an application to generate below HCLK Frequencies using PLL . Use HSI as PLL’s input source and repeat the exercise using HSE as input source. – 50MHz – 84MHz – 120MHz
  • 33. PLL configuration VCO /P /Q /R /M X N PLL Source Mux PLLCLK HSE HSI 16MHz 8MHz f(vco input clock) f(vco output clock)
  • 37. Exercise • Write an application which does PLL configuration to boost the HCLK to maximum capacity (for STM32F446RE it is:180MHz). Use HSE as PLL Source.

Editor's Notes

  1. 1
  2. The frequency of the internal RC oscillators can be fine-tuned to achieve better accuracy with wider temperature and supply voltage ranges. The trimming bits are used for this purpose.
  3. 1 x 100 /2
  4. f(vco input clock)
  5. 1 x 100 /2
  6. 50MHz
  7. 50MHz
  8. 50MHz 0.02 micro seconds ---- > 1tick 1ms --> ? 1 ms / 0.02 micro 50MHz/ 1000
  9. C