当前位置:网站首页>Stm32f04 clock configuration
Stm32f04 clock configuration
2022-07-03 09:52:00 【0725 you Guangchuan】
Clock configuration
1、 summary
F407 The internal clock of has LSI(32Hz)、HSI(16MHz)
External clock has HSE 25MHz, It is more stable to use an external clock .
use HSE The clock configuration system clock is as follows
25Mhz, adopt PLL frequency doubling , As PllClk and PLL48CLK The clock ,(m The frequency division factor is generally HSE size : Configure as input VCO by 1MHz,XN Frequency doubling is the output VCO =336Mhz, Through the frequency division factor p(=2) and R(=7) Provide clock for external bus ,ABB(HCLK)=168,APB1 Bus is 42Hz、APB2 Bus is 84Hz, The timer clock is APB Bus clock 2 times ,)
2、 Clock configuration summary
/*
- Use HSE when , Steps to set the system clock
- 1、 Turn on HSE , And wait for HSE Stable
- 2、 Set up AHB、 APB2、 APB1 The prescaler factor of
- 3、 Set up PLL The source of the clock
- Set up VCO Input clock Division factor m
- Set up VCO Output clock Octave factor n
- Set up PLLCLK Clock division factor p
- Set up OTG FS,SDIO,RNG Clock division factor q
- 4、 Turn on PLL, And wait for PLL Stable
- 5、 hold PLLCK Switch to system clock SYSCLK
- 6、 Read clock switch status bit , Make sure PLLCLK Selected as the system clock
- m: VCO Input clock Division factor , Value 2~63
- n: VCO Output clock Octave factor , Value 192~432
- p: PLLCLK Clock division factor , Value 2, 4, 6, 8
- q: OTG FS,SDIO,RNG Clock division factor , Value 4~15
- Function call examples , Use HSE Set the clock
- SYSCLK=HCLK=168M,PCLK2=HCLK/2=84M,PCLK1=HCLK/4=42M
*/
3、 Program with register
void hseCfg(void)
{
/*****************************************************************************/
/ PLL (clocked by HSE) used as System clock source /
/****************************************************************************/
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
/ Reset RCC All the registers of */
RCC_DeInit();
RCC->CR |=(uint32_t)RCC_CR_HSEON;// Can make HSE The clock
// The following is waiting for the hardware to automatically set CR The register is HSERDY by 1 Express HSE The clock is ready
do
{
HSEStatus=RCC->CR & RCC_CR_HSERDY;
StartUpCounter++;
}while((HSEStatus==0)&&(StartUpCounter!=HSE_STARTUP_TIMEOUT));
if((RCC->CR & RCC_CR_HSERDY)!=RESET)
{
HSEStatus=0x1;
}
else
{
HSEStatus=0x0;
}
if(HSEStatus==0x1)
{
/* Select regulator voltage output Scale 1 mode */
/* The mode of selecting the voltage regulator is 1, Used to balance the voltage , Reduce power consumption */
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
PWR->CR |= PWR_CR_VOS;
/* Divide the frequency of each bus of the system
AHB It's divided into 1
APB1 It's divided into 4
APB1 It's divided into 2
*/
RCC->CFGR |=RCC_CFGR_HPRE_DIV1;
RCC->CFGR |=RCC_CFGR_PPRE1_DIV4;
RCC->CFGR |=RCC_CFGR_PPRE2_DIV2;
/* PLL frequency doubling * RCC_PLLCFGR_PLLSRC_HSE As a system clock /
RCC->PLLCFGR = 25 | (336 << 6) | (((2 >> 1) -1) << 16) |
(RCC_PLLCFGR_PLLSRC_HSE) | (7 << 24);
/* Enable the main PLL /
/ Enable the Lord PLL /
RCC->CR |= RCC_CR_PLLON;
/ Wait till the main PLL is ready /
/ Wait for the Lord PLL Stable */
while((RCC->CR & RCC_CR_PLLRDY) == 0)
{
}
/* Configure Flash prefetch, Instruction cache, Data cache and wait state */
/* To configure FLASH Prefetch finger , Instruction cache , Data caching , Waiting period */
FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
RCC->CFGR &=~(RCC_CFGR_SW);
RCC->CFGR |=RCC_CFGR_SW_PLL;// choice PLL As a system clock
while((RCC->CFGR &(uint32_t)RCC_CFGR_SWS_PLL) !=RCC_CFGR_SWS_PLL)
{
}// wait for PLL be ready , There are hardware settings
}
else
{
Do other processing for exceptions
}
}
4、 Program with firmware library
void HseCFg(uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ)
{
ErrorStatus errorStatus=ERROR;
RCC_DeInit(); /* Reset RCC All the registers of */
RCC_HSEConfig(RCC_HSE_ON);// Can make HSE The clock
// The following is waiting for the hardware to automatically set CR The register is HSERDY by 1 Express HSE The clock is ready
errorStatus=RCC_WaitForHSEStartUp();
if(errorStatus==SUCCESS)
{
/* Divide the frequency of each bus of the system
AHB It's divided into 1
APB1 It's divided into 4
APB1 It's divided into 2
*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div4);
RCC_PCLK2Config(RCC_HCLK_Div2);
/* PLL frequency doubling * RCC_PLLCFGR_PLLSRC_HSE As a system clock /
RCC_PLLConfig(RCC_PLLSource_HSE, PLLM, PLLN, PLLP, PLLQ);
RCC_PLLCmd(ENABLE);// Bit band operation used , Give the register X Location 1
while((RCC->CR & RCC_CR_PLLRDY) == 0)
{
}
/* Configure Flash prefetch, Instruction cache, Data cache and wait state */
/* To configure FLASH Prefetch finger , Instruction cache , Data caching , Waiting period */
FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while((RCC->CFGR &(uint32_t)RCC_CFGR_SWS_PLL) !=RCC_CFGR_SWS_PLL)
{
}
}
else
{
}
}
5、HSI Configured as system clock
void HSIFun(uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
// ErrorStatus errorStatus=ERROR;
/* Reset RCC All the registers of */
RCC_DeInit();
RCC->CR |=(uint32_t)RCC_CR_HSION;
do
{
HSEStatus=RCC->CR & RCC_CR_HSIRDY;
StartUpCounter++;
}while((HSEStatus==0)&&(StartUpCounter!=HSE_STARTUP_TIMEOUT));
if((RCC->CR & RCC_CR_HSIRDY)==RCC_CR_HSIRDY)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div4);
RCC_PCLK2Config(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSI, PLLM, PLLN, PLLP, PLLQ);
RCC_PLLCmd(ENABLE);
while((RCC->CR & RCC_CR_PLLRDY) == 0)
{
}
/* Configure Flash prefetch, Instruction cache, Data cache and wait state */
/* To configure FLASH Prefetch finger , Instruction cache , Data caching , Waiting period */
FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while((RCC->CFGR &(uint32_t)RCC_CFGR_SWS_PLL) !=RCC_CFGR_SWS_PLL)
{
}
}
else
{
}
}
边栏推荐
- CEF download, compile project
- numpy. Reshape() and resize() functions
- Project scope management__ Scope management plan and scope specification
- 1300. sum of varied array closed to target
- A lottery like scissors, stone and cloth (C language)
- IDEA远程断点调试jar包项目
- 内存数据库究竟是如何发挥内存优势的?
- MySQL的简单使用(增删改查)
- Implementing distributed lock with redis
- Find all possible recipes from given supplies
猜你喜欢

Flink learning notes (VIII) multi stream conversion

JMX、MBean、MXBean、MBeanServer 入门

STM32 serial port usart1 routine

Flink learning notes (IX) status programming

SSB Introduction (PbCH and DMRs need to be supplemented)

Project cost management__ Topic of comprehensive calculation

UCI and data multiplexing are transmitted on Pusch - Part I

The third paper of information system project manager in soft examination

Definition and use of enum in C language

【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
随机推荐
Project cost management__ Plan value_ Earned value_ Relationship among actual cost and Countermeasures
STM32 interrupt priority management
Leetcode daily question (2232. minimize result by addressing parents to expression)
我想各位朋友都应该知道学习的基本规律就是:从易到难
Design and development of biological instruments
Stm32-hal library learning, using cubemx to generate program framework
UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths
【男保姆式】教你打开第一个微信小程序
Successful graduation [3]- blog system update...
STM32 external interrupt experiment
学习开发没有捷径,也几乎不存在带路会学的快一些的情况
Error output redirection
SSB Introduction (PbCH and DMRs need to be supplemented)
Basic knowledge of MySQL database (an introduction to systematization)
自动装箱与拆箱了解吗?原理是什么?
[CSDN]C1训练题解析_第四部分_Web进阶
SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
Quelle langue choisir pour programmer un micro - ordinateur à puce unique
Implementing distributed lock with redis
Development of fire evacuation system