stm32f030时钟配置工具AN4055
STM32F103的复位及时钟控制模块头文件
STM32F103的复位及时钟控制模块头文件在处理器正常工作前,肯定要做一些初始化工作,其中最主要的一个就是初始化各种时钟。
通过对STM32F103的复位及时钟控制(RCC)模块分析之后,自己写了一个RCC的头文件,这样使用起来更方便。
头文件中首先定义了最基本的几个寄存器,然后再对每个寄存器中的域使用结构体做了定义,可以直接使用寄存器中的位来操作。
注意设置系统时钟时要先设置好FLASH的等待周期,不然程序就可能会跑飞。
该测试工程是在以前的GPIO实验的基础上增加系统时钟初始化代码,设置系统时钟为72M。
通过流水灯可以看到,比未配置系统时钟之前(8M)流水灯的速度快了很多。
从这里下载完整的测试工程:系统时钟初始化的代码如下://以下时钟配置为最高性能void SystemClockInit(void){//设置flash等待周期为2,否则设置为72M系统时钟时就会跑飞FLASH_ACR=0x32;pbRCC_CR->HSEON=1; //使能外部高速时钟while(!(pbRCC_CR->HSERDY)); //等待外部高速时钟稳定pbRCC_CFGR->MCO=0; //MCO无时钟输出pbRCC_CFGR->USBPRE=1; //USB时钟1.5分频pbRCC_CFGR->PLLMUL=9-2; //PLL倍频设置为9倍(外部时钟8M,PLL输出72M)pbRCC_CFGR->PLLXTPRE=0; //HSE不分频pbRCC_CFGR->PLLSRC=1; //HSE选作做为PLL时钟源输入pbRCC_CFGR->ADCPRE=0; //ADC时钟2分频pbRCC_CFGR->PPRE2=1+6; //APB2设置为1分频pbRCC_CFGR->PPRE1=2+6; //APB1设置为2分频pbRCC_CFGR->HPRE=0; //AHB无分频pbRCC_CR->PLLON=1; //启动PLLwhile(!(pbRCC_CR->PLLRDY)); //等待PLL稳定pbRCC_CFGR->SW=2; //选择PLL输出为时钟源//pbRCC_AHBENR->SRAMEN=1;//pbRCC_AHBENR->FLITFEN=1;//IO口第二功能时钟使能pbRCC_APB2ENR->AFIOEN=1;//各通用IO口时钟使能pbRCC_APB2ENR->IOPAEN=1;pbRCC_APB2ENR->IOPBEN=1;pbRCC_APB2ENR->IOPCEN=1;pbRCC_APB2ENR->IOPDEN=1;pbRCC_APB2ENR->IOPEEN=1;//ADC时钟使能pbRCC_APB2ENR->ADC1EN=1;pbRCC_APB2ENR->ADC2EN=1;//定时器1时钟使能//SPI1时钟使能pbRCC_APB2ENR->SPI1EN=1;//串口1时钟使能pbRCC_APB2ENR->USART1EN=1;//定时器2、3、4时钟使能pbRCC_APB1ENR->TIM2EN=1; pbRCC_APB1ENR->TIM3EN=1; pbRCC_APB1ENR->TIM4EN=1;//窗口看门狗时钟不使能pbRCC_APB1ENR->WWDGEN=0;//SPI2时钟使能pbRCC_APB1ENR->SPI2EN=1;//串口2、3时钟使能pbRCC_APB1ENR->USART2EN=1; pbRCC_APB1ENR->USART3EN=1;//I2C1、2时钟使能pbRCC_APB1ENR->I2C2EN=1;//USB时钟使能pbRCC_APB1ENR->USBEN=1;//CAN时钟使能pbRCC_APB1ENR->CANEN=1;//备份接口时钟使能pbRCC_APB1ENR->BKPEN=1;//电源接口时钟使能pbRCC_APB1ENR->PWREN=1;//外部低速时钟启动pbRCC_BDCR->LSEON=1;pbRCC_BDCR->LSEBYP=0;pbRCC_BDCR->RTCSEL=1; //选择外部时钟为RTC时钟}STM32/STM8意法半导体/ST/STM。
STM32F0系列寄存器操作02RCC时钟配置
STM32F0系列寄存器操作02RCC时钟配置对于STM32F0系列的RCC时钟配置,以下是一个超过1200字的例子:RCC(Reset and Clock Control)是用于配置和控制STM32F0系列微控制器的时钟的模块。
时钟系统对于微控制器的运行非常重要,因为它影响到系统的性能、功耗和稳定性。
在使用STM32F0系列微控制器时,首先需要配置RCC模块的寄存器,以确定各种时钟源的频率、分频系数和使能状态。
以下是配置RCC模块的步骤:1.选择系统时钟源:RCC_CFGR寄存器用于选择系统时钟源。
主要的时钟源有内部高速时钟HSI(高速内部),外部晶体时钟HSE(高速外部),外部低速时钟LSI(低速内部)和外部低速时钟LSE(低速外部)。
可以使用RCC_CFGR寄存器的SW位域来选择时钟源。
2.设置时钟频率和分频系数:根据应用的需求,可以设置时钟的频率和分频系数。
RCC_CFGR寄存器的HPRE、PPRE、和PLLMUL位域用于设置时钟的分频系数。
同时,还可以使用RCC_CFGR2和RCC_CFGR3寄存器来设置PLL(锁相环)的输入时钟和分频因子。
3.使能时钟源:RCC_APB2ENR、RCC_APB1ENR和RCC_AHBENR寄存器用于使能各个外设的时钟源。
可以使用这些寄存器的位域来控制外设时钟的使能状态。
4.时钟安全配置:RCC_CFGR寄存器的MCO和MCOPRE位域用于配置主要时钟输出的时钟安全特性。
可以设置MCO和MCOPRE位域来输出主时钟信号、内部时钟信号或外部时钟信号。
配置完毕后,需要等待时钟系统配置完成。
通过读取RCC_CFGR寄存器的SWS位域,可以确保时钟系统配置已经生效。
一旦配置完成后,系统将按照配置的时钟源和频率来运行。
在使用STM32F0系列微控制器时,正确配置RCC时钟是非常重要的。
这样可以确保系统的稳定性、性能和功耗都能达到预期的要求。
通过操作RCC模块的相关寄存器,可以实现对时钟源和频率的灵活配置,以满足不同应用的需求。
stm32如何配置时钟
学习STM32笔记2 如何配置时钟学习STM32笔记2 如何配置时钟/*************************************************************该程序目的是用于测试核心板回来后是否能正常工作。
包括两个按键、两个LED现实。
按键为PC4、PC5,LED为PA0\PA1。
LED为低电平时点亮。
按键为低电平时触发。
************************************************************/#i nclude "stm32f10x_lib.h"void RCC_Configuration(void);//设置系统主时钟void GPIO_Configuration(void);//设置邋邋IO参数void NVIC_Configuration(void);//设置中断表地址void delay(void);//延时函数int main(void){#ifdef DEBUGdebug();#endifRCC_Configuration();NVIC_Configuration();GPIO_Configuration();while (1){delay();//设置指定的数据端口位GPIO_SetBits(GPIOA,GPIO_Pin_0);//设置指定的数据端口位delay();GPIO_ResetBits(GPIOA,GPIO_Pin_0);//清除指定的数据端口位GPIO_SetBits(GPIOA,GPIO_Pin_1);delay();GPIO_ResetBits(GPIOA,GPIO_Pin_1);delay();/*********************************************使用setbits 与resetbits 是比较简单,其实还是可以使用其它函数。
stm32的时钟配置(非常详细)
stm32的时钟配置(⾮常详细)⼤家都知道在使⽤单⽚机时,时钟速度决定于外部晶振或内部RC振荡电路的频率,是不可以改变的。
⽽ARM的出现打破了这⼀传统的法则,可以通过软件随意改变时钟速度。
这⼀出现让我们的设计更加灵活,但是也给我们的设计增加了复杂性。
为了让⽤户能够更简单的使⽤这⼀功能,STM32的库函数已经为我们设计的更加简单⽅便。
在⽐较靠前的版本中,我们需要向下⾯那样设置时钟:ErrorStatus HSEStartUpStatus;void RCC_Configuration(void){RCC_DeInit(); // RCC system reset(for debug purpose)RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is readyif (HSEStartUpStatus == SUCCESS) // 当HSE准备完毕切振荡稳定后{RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // PLLCLK = 8MHz * 9 = 72 MHzRCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET){; // Wait till PLL is ready}RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock sourcewhile (RCC_GetSYSCLKSource() != 0x08) // Wait till PLL is used as system clock source {;}}}随之函数库的不断升级,到3.0以上时,我们就不⽤再这样编写时钟设置了,我们只要做如下两部即可:第⼀个: system_stm32f10x.c 中 #define SYSCLK_FREQ_72MHz 72000000第⼆个:调⽤SystemInit()说明:在stm32固件库3.0中对时钟频率的选择进⾏了⼤⼤的简化,原先的⼀⼤堆操作都在后台进⾏。
STM32F0xx 微控制器的时钟配置介绍
2 年 05 月
文档 ID 022837 第 1 版
1/16
目录
目录
AN4055
1
术语表 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 专家模式 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4
已知限制 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
文档 ID 022837 第 1 版
3/16
3
图片索引
图片索引
AN4055
图 1. 图 2. 图 3. 图 4. 图 5. 图 6. 图 7.
时钟结构图 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 I2S 时钟结构图 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 向导模式用户界面 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 选择时钟源 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 文件生成错误 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 专家模式用户界面 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 超出系统时钟频率 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
STM32F103RC系统时钟配置
地址:安徽省、合肥市、肥东县、店埠镇,合肥市福来德电子科技有限公司 STM32F103RC 系统时钟配置1、打开D:\program\KEL_MDT_ARM\STM32_Template\USER 目录,找到STM32-DEMO 文件,双击打开,KEIL-uVision4就开始运行了,得到下图:2、双击“STARTCODE ”下面的“start_stm32f10x_hd.s ”打开STM32F103RC 的启动文件,找“SystemInit ”,得到下图:地址:安徽省、合肥市、肥东县、店埠镇,合肥市福来德电子科技有限公司3、点击当前的行,右击鼠标,将光标移动到“Go To Definition Of SystemInit”,见下图:4、点击“Go To Definition Of SystemInit ”,会跳转到system_stm32f10x.c 文件,见下图:地址:安徽省、合肥市、肥东县、店埠镇,合肥市福来德电子科技有限公司5、在“system_stm32f10x.c ”文件中,在“void SystemInit (void)”函数体内找到“SetSysClock();”,见下图:6、点击“SetSysClock()”,右击鼠标,将光标移动到“Go To Definition Of SystemClock”,见下图:地址:安徽省、合肥市、肥东县、店埠镇,合肥市福来德电子科技有限公司 7、点击“Go To Definition Of SystemClock”,会跳转到system_stm32f10x.c 文件,见下图:8、点击“defined SYSCLK_FREQ_72MHz ”,右击鼠标,将光标移到到“Go To Definition Of SYSCLK_FREQ_72MHz ”,见下图:地址:安徽省、合肥市、肥东县、店埠镇,合肥市福来德电子科技有限公司9、点击“Go To Definition Of SYSCLK_FREQ_72MHz ”,会跳转到下图:10、在上图中,我们可以设置所需要的系统时钟,这里设置系统时钟是SYSCLK_FREQ_72MHz ,见下面粘贴的部分#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) /* #define SYSCLK_FREQ_HSE HSE_VALUE */#define SYSCLK_FREQ_24MHz 24000000#else/* #define SYSCLK_FREQ_HSE HSE_VALUE *//* #define SYSCLK_FREQ_24MHz 24000000 *//* #define SYSCLK_FREQ_36MHz 36000000 *//* #define SYSCLK_FREQ_48MHz 48000000 *//* #define SYSCLK_FREQ_56MHz 56000000 */#define SYSCLK_FREQ_72MHz 72000000 //这是我们要设置的系统时钟#endif。
STM32芯片时钟配置
对STM32进行软件开发时,最基本的就是对STM32芯片进行时钟和端口配置,然后是对项目所用到的片上资源进行配置并驱动,下面给出时钟和端口配置代码,该代码几乎涵盖了片上所有时钟和端口配置项目,可根据自己需要进行删除不必要的配置项:/******************************************************************* Function Name :RCC_Configuration 复位时钟控制配置* Description : Configures the different system clocks.* Input : None* Output : None* Return : None*******************************************************************/void RCC_Configuration(void){/* system clocks configuration -----系统时钟配置----*//* RCC system reset(for debug purpose) */RCC_DeInit(); //将外设RCC寄存器重设为缺省值/* Enable HSE */RCC_HSEConfig(RCC_HSE_ON);//开启外部高速晶振(HSE)/* Wait till HSE is ready */HSEStartUpStatus = RCC_WaitForHSEStartUp();//等待HSE起振if(HSEStartUpStatus == SUCCESS) //若成功起振,(下面为系统总线时钟设置){/* Enable Prefetch Buffer */FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //使能FLASH预取指缓存/* Flash 2 wait state */FLASH_SetLatency(FLASH_Latency_2); //设置FLASH存储器延时时钟周期数(根据不同的系统时钟选取不同的值)/* HCLK = SYSCLK */RCC_HCLKConfig(RCC_SYSCLK_Div1);//设置AHB时钟=72 MHz/* PCLK2 = HCLK/2 */RCC_PCLK2Config(RCC_HCLK_Div2); //设置APB1时钟=36 MHz(APB1时钟最大值) /* PCLK1 = HCLK */RCC_PCLK1Config(RCC_HCLK_Div1); //设置APB2时钟=72 MHz/* Configure ADCCLK such as ADCCLK = PCLK2/2 */RCC_ADCCLKConfig(RCC_PCLK2_Div2);//RCC_PCLK2_Div2,4,6,8/* PLLCLK = 8MHz * 9 = 72 MHz */RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //PLL必须在其激活前完成配置(设置PLL时钟源及倍频系数)/* Enable PLL */RCC_PLLCmd(ENABLE);/* Wait till PLL is ready */while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);/* Select PLL as system clock source */RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);/* Wait till PLL is used as system clock source */while(RCC_GetSYSCLKSource() != 0x08);}/* Enable peripheral clocks ----------外设时钟使能---------*//* Enable AHB peripheral clocks -----AHB外设时钟使能----------*//* Enable DMA clock */RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//使能DMA时钟/* Enable SRAM clock */RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM, ENABLE);//使能SRAM时钟/* Enable FLITF clock */RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FLITF, ENABLE);//使能FLITF时钟/* Enable APB1 peripheral clocks -----APB1外设时钟使能------*//* TIM2,3,4 clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//使能TIM2时钟 if (APB1 prescaler="1") x1// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//使能TIM3时钟 else x2 // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);//使能TIM4时钟/* WWDG clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);//使能WWDG时钟/* Enable SPI2 clocks */// RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI2, ENABLE);//使能SPI2时钟/* USART2,3 clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//使能USART2时钟(对应万利开发板上的USART1)// RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//使能USART3时钟(万利开发板上未接该串口)/* I2C1,2 clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);//使能I2C1时钟// RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);//使能I2C2时钟/* USB clock enable / PLL clock divided by 1.5 used as USB clock source */// RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); //根据不同PLLCLK选择分频比,必须确保USBCLK始终是48MHz// RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);//使能USB时钟/* CAN clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);//使能CAN时钟/* BKP clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP, ENABLE);//使能BKP时钟/* PWR clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//使能PWR时钟/* APB1Periph_ALL clock enable */// RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, ENABLE);//使能APB1Periph_ALL时钟/* Enable APB2 peripheral clocks -----APB2外设时钟使能-------*//* Enable GPIOA,B,C,D,E clocks */RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//使能GPIOA时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//使能GPIOB时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能GPIOC时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);//使能GPIOD时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);//使能GPIOE时钟/* AFIO clock enable */RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);////使能AFIO时钟/* Enable ADC1,2clocks */RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);//使能ADC1时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);//使能ADC2时钟/* TIM1 clock enable */// RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);//使能TIM1时钟/* Enable SPI1 clocks */// RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//使能SPI1时钟/* USART1 clock enable */RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);//使能USART1时钟/* APB1Periph_ALL clock enable */// RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, ENABLE);//使能APB2Periph_ALL时钟/* Enable no peripheral clocks ------非总线上外设时钟配置-------*//* Enable Internal High Speed oscillator *///RCC_HSICmd(ENABLE);/* Enable the Internal Low Speed oscillator *///RCC_LSICmd(ENABLE); //给IWDG提供时钟信号(如果IWDG运行的话,LSI不能被失能) /* Configure RTCCLK such as ADCCLK = PCLK2/2 */// RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);///* Select the LSE as RTC clock source */// RCC_RTCCLKCmd(ENABLE);///* Enable the RTC clock *//* Enable the Clock Security System *///RCC_ClockSecuritySystemCmd(ENABLE);/* Output PLL clock divided by 2 on MCO pin *///RCC_MCOConfig(RCC_MCO_PLLCLK_Div2);// 警告:当选中系统时钟作为MCO管脚的输出时,注意它的时钟频率不超过50MHz(最大I/O速率)。
STM32F时钟配置1
//程序中需要用的其他时钟也可以确定了。 //因为 APB1 Prescaler=1(没有分频),所以 TIMxCLK=PLCK1=36M //因为 APB2 Prescaler=1(没有分频),所以 TIM1CLK=PLCK2=36M //在 SystemInit 中 ADCPRE:ADC 预分频 00:PCLK2 2 分频后作为 ADC 时钟,即 ADCCLK=PCLK2/2,所以 ADCCLK=18M
FLASH->ACR |= FLASH_ACR_PRFTBE;
FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY); FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;
CanolaFlower
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
RCC->CIR = 0x009F0000;
SetSysClock(); }
static void SetSysClockTo36(void) { __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
//注释为:SYSLCK,HCLK,PCLK2 和 PCLK1 的配置
RCC->CR |= RCC_CR_PLLON;
while((RCC->CR & RCC_CR_PLLRDY) == 0) { }
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
STM32F0系列寄存器操作02RCC时钟配置
STM32F0系列寄存器操作02RCC时钟配置RCC(Reset and Clock Control)模块是STM32F0系列微控制器中的一个重要模块,用于配置系统时钟。
在这里,我们将详细介绍如何通过寄存器操作来配置RCC模块。
RCC模块的寄存器位于设备的的地址空间中,通过写入特定的值来配置和控制系统时钟。
以下是与RCC模块相关的一些重要寄存器:1. RCC_CR(RCC Control Register):用于配置内部和外部时钟、使能外部时钟和使能内部时钟等。
2. RCC_CFGR(RCC Configuration Register):用于配置系统时钟源、时钟分频等。
3. RCC_AHBENR(RCC AHB Peripheral Clock Enable Register):用于使能或禁用AHB总线上的外设时钟。
4. RCC_APBENR(RCC APB Peripheral Clock Enable Register):用于使能或禁用APB总线上的外设时钟。
根据需求,我们可以按照以下步骤配置RCC模块:1.确定系统时钟源:使用RCC_CFGR寄存器来选择主时钟源,可以从内部时钟(HSI或HSI48)、外部时钟(HSE或HSE32)或PLL时钟中选择。
2.配置时钟分频:使用RCC_CFGR寄存器来设置HCLK、PCLK1和PCLK2的分频系数,以确定这些时钟频率。
3.使能外设时钟:使用RCC_AHBENR和RCC_APBENR寄存器来使能或禁用需要使用的外设时钟。
下面是一个示例代码,用于配置STM32F0系列微控制器的RCC模块:```c#include "stm32f0xx.h"void RCC_Config(void)//使能外部时钟RCC->CR,=RCC_CR_HSEON;//等待外部时钟稳定while(!(RCC->CR & RCC_CR_HSERDY));//配置PLL时钟RCC->CFGR,=RCC_CFGR_PLLSRC_HSE_PREDIV;RCC->CFGR,=RCC_CFGR_PLLMUL6;//使能PLL时钟RCC->CR,=RCC_CR_PLLON;//等待PLL时钟稳定while(!(RCC->CR & RCC_CR_PLLRDY));//配置系统时钟源为PLL时钟RCC->CFGR,=RCC_CFGR_SW_PLL;//等待系统时钟源切换完成while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);//配置时钟分频RCC->CFGR,=RCC_CFGR_HPRE_DIV1;//AHB时钟不分频RCC->CFGR,=RCC_CFGR_PPRE_DIV2;//APB1时钟分频为2//使能外设时钟RCC->AHBENR,=RCC_AHBENR_GPIOAEN;RCC->APBENR,=RCC_APBENR_TIM2EN;```在这个示例中,首先使能外部时钟(HSE)并等待其稳定,然后配置PLL时钟和分频系数。
STM32F103x时钟配置
首先要知道系统时钟(SYSTEMCLOCK)->AHB时钟(HPRE)->APB1&2时钟(PPRE1&2)依次往下分频的关系。
必须记住其次要知道涉及到时钟分配一定在RCC里。
找到时钟配置寄存器(RCC_CFGR)很清楚的看清楚分频关系。
第三要知道STM32103X的系统时钟、AHB时钟、APB时钟的设置都在CMSIS->system_stm32f103x.c里面,可以看上面提供的图。
系统时钟的设置AHB时钟和APB时钟的设置从上图可以看出,AHB时钟和APB时钟和系统时钟是一样的,没有分频。
由软件置1或清零。
当进入待机和停止模式时,该位由硬件清零,关闭外部时钟。
当外部时钟被用作或被选择将要作为系统时钟时,该位不能被清零。
0:HSE 振荡器关闭 1:HSE 振荡器开启位15:8HSICAL[7:0]:内部高速时钟校准 在系统启动时,这些位被自动初始化位7:3HSITRIM[4:0]:内部高速时钟调整由软件写入来调整内部高速时钟,它们被叠加在HSICAL[5:0]数值上。
位2 保留,始终读为0。
位1HSIRDY :内部高速时钟就绪标志由硬件置1来指示内部8MHz 时钟已经稳定。
在HSION 位清零后,该位需要6个内部时钟周期清零。
0:内部8MHz 时钟没有就绪 1:内部8MHz 时钟就绪位0HSION :内部高速时钟使能 由软件置1或清零。
当从待机和停止模式返回或用作系统时钟的外部1-25MHz 时钟发生故障时,该位由硬件置1来启动内部8MHz 的RC 振荡器。
当内部8MHz 时钟被直接或间接地用作或被选择将要作为系统时钟时,该位不能被清零。
0:内部8MHz 时钟关闭 1:内部8MHz 时钟开启4.3.2时钟配置寄存器(RCC_CFGR)偏移地址: 04h 复位值: 0000 0000h访问: 0到2个等待周期,字, 半字 和字节访问只有当访问发生在时钟切换时,才会插入1或2个等待周期。
STM32定时器时钟配置技巧
STM32定时器时钟配置技巧众所周知STM32 的时钟配置⽐较复杂,⽽定时器的时钟配置更是 ‘奇葩‘。
如下图(截图⾃STM32F4编程⼿册)APB 的预分频器分频系数如果不为1,则定时器的时钟就倍频了反⽽。
配置技巧下⾯以STM32F4为例,这⾥配置定时器8的计数频率为 10Khz,从时钟树中可知TIM8挂在APB2总线获取当前 APB2(PLCK2) 的时钟频率获取 APB2 预分频器的分频值根据上述参数判断,如果分频值不为1,则定时器时钟 x2.Prescaler = xxx 这是⼀个推荐的写法int hw_timer_init(TIM_HandleTypeDef *htim){uint32_t FLatency, t8Clk;RCC_ClkInitTypeDef clkCfg;TIM_ClockConfigTypeDef sClockSourceConfig = {0};TIM_OC_InitTypeDef sConfigOC = {0};/* USER CODE BEGIN TIM_Init 1 */t8Clk = HAL_RCC_GetPCLK2Freq();HAL_RCC_GetClockConfig(&clkCfg, &FLatency);if (clkCfg.APB2CLKDivider != RCC_HCLK_DIV1) {t8Clk = HAL_RCC_GetPCLK2Freq() * 2;}/* USER CODE END TIM1_Init 1 */htim->Instance = TIM8;htim->Init.Prescaler = (t8Clk / 10000) - 1;// 10Khtim->Init.CounterMode = TIM_COUNTERMODE_UP;htim->Init.Period = 0xFFFF;htim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;htim->Init.RepetitionCounter = 0;htim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;HAL_TIM_Base_Init(htim);...return 0;}```总结这种配置⽅法最⼤的好处就是该定时器不受底层时钟配置的影响,移植性也更好。
STM32 时钟配置
void RCC_SYSCLKConfig(u32 RCC_SYSCLKSource)
参数:RCC_SYSCLKSource 用作系统时钟的时钟源
u8 RCC_GetSYSCLKSource( void) - RCC_SYSCLKSource_HSI 选择HSI作为系统时钟 - RCC_SYSCLKSource_HSE 选择HSE作为系统时钟 返回值:用作系统时钟的时钟源: - RCC_SYSCLKSource_PLLCLK 选择 PLL作为系统时钟 - 0x00:HSI 作为系统时钟 - 0x04:HSE 作为系统时钟 HSI RC - 0x08:PLL 作为系统时钟 8MHz
Page 10
stm32f10x_rcc.h解析__102~140
定义PLL倍频系数 宏
RCC_CFGR
Page 11
stm32f10x_rcc.h解析__148~282
定义STM32F10X_xx_VL,STM32F10X_CL预分频,锁相 环2,3倍频系数等 宏,与STM32F10X_HD无关。
Page 12
stm32f10x_rcc.h解析__289~294
定义系统时钟源 宏
RCC_CFGR
Page 13
stm32f10x_rcc.h解析__303~316
定义AHB分频系数 宏
RCC_CFGR
Page 14
stm32f10x_rcc.h解析__325~333
定义APB分频系数 宏
Prescaler
ADCClk
OSC32_IN RCC_PLLMul 32.768kHz : PLL 倍频系数 ENABLE 启动PLL 参数 : RCC_FLAG OSC32_OUT - OSC RCC_PLLMul_2 PLL 输入时钟 x2 PLL RTCClk - DISABLE 禁用
STM32F103x时钟配置
STM32F103x时钟配置
void STM32_Clock_Init(u8 PLL)
{
unsigned char temp=0;
MYRCC_DeInit(); //复位并配置向量表
RCC->;CR|=0x00010000; //把时钟控制寄存器的地16位置1来开启外部振荡器
while(!(RCC->;CR>;>;17)); //通过判断时钟寄存器的地17位,看一下时钟外部振荡器是否就绪
RCC->;CFGR=0x00000400; //设置时钟配置寄存器
8-10位来保证APB1时钟频率不超过36MHz
PLL-=2; //抵消2个单位
RCC->;CFGR|=PLL;CFGR|=1;ACR|=0x32; //FLASH两个延时周期
RCC->;CR|=0x01000000; //通过时钟寄存器的第24位,使能PLL
while(!(RCC->;CR>;>;25)); //通过判断时钟寄存器的第25位,看一下PLL是否就位
RCC->;CFGR|=0x00000002; //通过设置时钟配置寄存器的第0-1位把PLL作为系统时钟
while(temp!=0x02) //等待PLL作为系统时钟
{
temp=RCC->;CFGR>;>;2; temp&=0x03;
}
}。
STM32时钟配置方法
STM32时钟配置方法详解一、在STM32中,有五个时钟源,为HSI、HSE、LSI、LSE、PLL。
①HSI是高速内部时钟,RC振荡器,频率为8MHz。
②HSE是高速外部时钟,可接石英/陶瓷谐振器,或者接外部时钟源,频率范围为4MHz~16MHz。
③LSI是低速内部时钟,RC振荡器,频率为40kHz。
④LSE是低速外部时钟,接频率为32.768kHz的石英晶体。
⑤PLL为锁相环倍频输出,其时钟输入源可选择为HSI/2、HSE或者HSE/2。
倍频可选择为2~16倍,但是其输出频率最大不得超过72MHz。
二、在STM32上如果不使用外部晶振,OSC_IN和OSC_OUT的接法:如果使用内部RC振荡器而不使用外部晶振,请按照下面方法处理:①对于100脚或144脚的产品,OSC_IN应接地,OSC_OUT应悬空。
②对于少于100脚的产品,有2种接法:第1种:OSC_IN和OSC_OUT分别通过10K电阻接地。
此方法可提高EMC性能;第2种:分别重映射OSC_IN 和OSC_OUT至PD0和PD1,再配置PD0和PD1为推挽输出并输出'0'。
此方法可以减小功耗并(相对上面)节省2个外部电阻。
三、用HSE时钟,程序设置时钟参数流程:01、将RCC寄存器重新设置为默认值RCC_DeInit;02、打开外部高速时钟晶振HSE RCC_HSEConfig(RCC_HSE_ON);03、等待外部高速时钟晶振工作HSEStartUpStatus = RCC_WaitForHSEStar tUp();04、设置AHB时钟RCC_HCLKConfig;05、设置高速AHB时钟RCC_PCLK2Config;06、设置低速速AHB时钟RCC_PCLK1Config;07、设置PLL RCC_PLLConfig;08、打开PLL RCC_PLLCmd(ENABLE);09、等待PLL工作while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RE SET)10、设置系统时钟RCC_SYSCLKConfig;11、判断是否PLL是系统时钟while(RCC_GetSYSCLKSource() != 0x08)12、打开要使用的外设时钟RCC_APB2PeriphClockCmd()/RCC_APB1Perip hClockCmd()四、下面是STM32软件固件库的程序中对RCC的配置函数(使用外部8MHz晶振)/******************************************************************************** Function Name : RCC_Configuration* Description : RCC配置(使用外部8MHz晶振)* Input : 无* Output : 无* Return : 无*******************************************************************************/void RCC_Configuration(void){/*将外设RCC寄存器重设为缺省值*/RCC_DeInit();/*设置外部高速晶振(HSE)*/RCC_HSEConfig(RCC_HSE_ON); //RCC_HSE_ON——HSE晶振打开(ON)/*等待HSE起振*/HSEStartUpStatus = RCC_WaitForHSEStartUp();if(HSEStartUpStatus == SUCCESS) //SUCCESS:HSE晶振稳定且就绪 {/*设置AHB时钟(HCLK)*/RCC_HCLKConfig(RCC_SYSCLK_Div1); //RCC_SYSCLK_Div1——AHB 时钟= 系统时钟/* 设置高速AHB时钟(PCLK2)*/RCC_PCLK2Config(RCC_HCLK_Div1); //RCC_HCLK_Div1——APB2时钟= HCLK/*设置低速AHB时钟(PCLK1)*/RCC_PCLK1Config(RCC_HCLK_Div2); //RCC_HCLK_Div2——APB1时钟= HCLK / 2/*设置FLASH存储器延时时钟周期数*/FLASH_SetLatency(FLASH_Latency_2); //FLASH_Latency_2 2延时周期/*选择FLASH预取指缓存的模式*/FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // 预取指缓存使能/*设置PLL时钟源及倍频系数*/RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);// PLL的输入时钟= HSE时钟频率;RCC_PLLMul_9——PLL输入时钟x 9/*使能PLL */RCC_PLLCmd(ENABLE);/*检查指定的RCC标志位(PLL准备好标志)设置与否*/while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET){}/*设置系统时钟(SYSCLK)*/RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//RCC_SYSCLKSource_PLLCLK——选择PLL作为系统时钟/* PLL返回用作系统时钟的时钟源*/while(RCC_GetSYSCLKSource() != 0x08) //0x08:PLL作为系统时钟 {}}/*使能或者失能APB2外设时钟*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph _GPIOB |RCC_APB2Periph_GPIOC , ENABLE);//RCC_APB2Periph_GPIOA GPIOA时钟//RCC_APB2Periph_GPIOB GPIOB时钟//RCC_APB2Periph_GPIOC GPIOC时钟//RCC_APB2Periph_GPIOD GPIOD时钟}五、时钟频率STM32F103内部8M的内部震荡,经过倍频后最高可以达到72M。
STM32时钟配置方法详解
STM32时钟配置方法详解STM32是意法半导体(STMicroelectronics)公司推出的一系列32位Flash微控制器,被广泛应用于各种嵌入式系统中。
时钟是STM32微控制器的核心部分,正确配置时钟可以确保系统正常工作并达到预期的性能。
本文将详细介绍STM32时钟配置的方法。
1.时钟源:STM32微控制器提供了多个时钟源,包括内部时钟(HSI、LSI)和外部时钟(HSE、LSE)。
其中,HSI(高速内部时钟)是一个高频率(通常为8MHz)的内部RC振荡器,适用于低功耗应用;LSI(低速内部时钟)是一个低频率(通常为40kHz)的内部RC振荡器,用于RTC(实时时钟)模块;HSE(高速外部时钟)是一个外接的高频晶振,用于提供更精确的时钟信号;LSE(低速外部时钟)是一个外接的低频晶振,适用于RTC模块。
2.主频和系统时钟:主频是指CPU的时钟频率,系统时钟是指STM32微控制器的总线时钟,包括AHB(高性能总线)、APB1(低速外设总线)和APB2(高速外设总线)。
在进行STM32时钟配置之前,需要按照以下几个步骤来完成。
1.启用对应的时钟源:根据具体需求,选择合适的时钟源并启用相应的时钟。
可以通过设置RCC_CR寄存器和RCC_APB1ENR/RCC_APB2ENR寄存器来实现。
例如,要使用HSE作为时钟源,需要首先启用HSE时钟。
2.配置时钟分频器:为了使系统时钟不超过芯片规格要求的最大频率,需要对时钟进行分频。
分频器有两个,即AHB分频器和APB分频器。
可以通过设置RCC_CFGR寄存器来实现。
例如,将AHB分频器设置为8,将APB1和APB2分频器分别设置为4,可以将主频分别分频为8MHz、32MHz和64MHz。
3.等待时钟稳定:当启用外部时钟源时,需要等待时钟稳定。
可以通过读取RCC_CR寄存器的特定标志位来判断时钟是否稳定。
4. 配置Flash存储器的延时:根据主频的不同,需要设置Flash存储器的访问延时,以确保正常读写数据。
STM32时钟详细配置
STM32时钟详细配置STM32时钟配置STM32时钟配置步骤// 开启HSI时钟寄存器操作1).开启高速时钟HSE // 设置时钟控制寄存器RCC_CR 位16 置1使能RCC->CR|= 0x00010000;位16 :HSEON:外部高速时钟使能当进入待机和停止模式时,该位由硬件清零,关闭4-16MHz外部振荡器。
当外部4-16MHz 振荡器被用作或被选择将要作为系统时钟时,该位不能被清零。
2).等待高速时钟就绪// 读取时钟控制寄存器RCC_CR位17为1就位while(!(RCC-> CR>>17));位17:HSERDY:外部高速时钟就绪标志由硬件置’1’来指示外部4-16MHz振荡器已经稳定。
在HSEON位清零后,该位需要6个外部4-25MHz振荡器周期清零。
3).设置APB1,APB2,AHB分频系数// 设置时钟配置寄存器RCC_CFGRRCC_CFGR=0x00000400;(AHB :位4-7, (低速)APB1 :位8-10, (高速)APB2 :位11-13)位7:4:HPRE[3:0]:AHB预分频(AHB Prescaler)0xxx:SYSCLK 不分频位10:8:PPRE1[2:0]:低速APB预分频(APB1) 100:HCLK 2分频位13:11:PPRE2[2:0]:高速APB预分频(APB2) 0xx:HCLK不分频4).设置PLL倍频// 配置时钟配置寄存器RCC_CFGR 位18-21RCC_CFGR|=7<<18;位21:18:PLLMUL:PLL倍频系数0111:PLL 9倍频输出5).PLL输入时钟源选择// 配置时钟配置寄存器RCC_CFGR 位16RCC_CFGR|=1<<16;位16:PLLSRC:PLL输入时钟源(PLL entry clock source) 1:HSE时钟作为PLL输入时钟。
STM32F030开发日志60篇附代码
STM32F030探索套件开发日志/评测/学习笔记/使用问题60篇STM32F030超值系列基于48MHz的ARM Cortex™-M0处理器内核,批量订货最低价仅为0.32美元。
产品发布以后,ST MCU社区开展了免费申请STM32F030活动,之后发出150块套件,并收到60余篇网友开发日志,篇篇附有详细说明以及代码,部分如下:(点击进入各篇日志中,可查看详细内容,登陆论坛后,可直接下载代码)1、【STM32F030开发日志笔记】+PROJECT模板+解决flash download error终于有空试一下到手的板子了。
先发一下工程模板吧,用的是默认程序。
发现keil5.0多了个pack-installer,要安装相应的pack 才能选择对应的flash,这大概是很多人flash download error的原因吧2、【STM32F0开发日志/评测/笔记】+学习资料的收集与分享时钟配置工具AN4055.pdf工具篇:STLINK的使用.pdfSTM32F030数据手册.pdf3、【STM32F030开发日志】工程模板_基础实验(实现端口驱动,外部中断,定时器中断,PWM 控制、串口通信现已实现基本功能驱动,此程序可作为模版程序使用,程序包含IO端口驱动,外部中断,定时器中断,PWM控制,串口通信,ADC转换. 直接上传代码了,希望大家在此基础上增加功能并共享,有问题回帖讨论。
4、【STM32F0开发日志---二】+ucosii.2.92移植在STM32F0305、基于STM32F0的LCD显示驱动经过查找对比,确定使用IAR for ARM 6.7 了。
从官网下载IAR for ARM 6.7 解压缩安装很顺利,发现现在的软件愈来愈求大求全啊,越发的想念dos版的cpp编译器了6、【STM32F030开发日志/评测/笔记】+采集角位移传感器信号控制直流电机(待续)1、4只mos管,2只pmos,2只nmos,驱动直流电机换向工作;2、stm32f030,产生pwm波控制直流电机;3、1只精密角位移传感器,传感直流电机的偏转角度;4、stm32f030采集角位移传感器的角度值,反馈控制电机的偏转。
stm32f030时钟配置工具AN4055
May 2012Doc ID 022837 Rev 11/17AN4055Application noteClock configuration tool for STM32F0xx microcontrollersIntroductionThis application note presents the clock system configuration tool for the STM32F0xx microcontroller family.The purpose of this tool is to help the user configure the microcontroller clocks, taking into consideration product parameters such as power supply and Flash access mode.The configuration tool is implemented in the “STM32F0xx_Clock_Configuration_VX.Y .Z.xls” file which is supplied with the STM32F0xx Standard Peripherals Library and can be downloaded from .This tool supports the following functionalities for the STM32F0xx:●Configuration of the system clock, HCLK source and output frequency●Configuration of the Flash latency (number of wait states depending on the HCLK frequency)●Setting of the PCLK1, PCLK2, TIMCLK (timer clocks) and I2SCLK frequencies ●Generation of a ready-to-use system_stm32f0xx.c file with all the above settings(STM32F0xx CMSIS Cortex-M0 Device Peripheral Access Layer System Source File)The STM32F0xx_Clock_Configuration_VX.Y .Z.xls is referred to as “clock tool” throughout this document.Before using the clock tool, it is essential to read the STM32F0xx microcontroller reference manual (RM0091). This application note is not a substitute for the reference manual.This tool supports only the STM32F0xx devices.For VX.Y .Z, please refer to the tool version, example V1.0.0Contents AN4055Contents1Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.1Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2.2Clock scheme for STM32F0xx microcontrollers . . . . . . . . . . . . . . . . . . . 72.2.3I2S clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.1Wizard mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.2Expert mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4Known limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 6Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162/17Doc ID 022837 Rev 1AN4055List of tables List of tablesTable 1.Definition of terms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Table 2.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Doc ID 022837 Rev 13/17List of figures AN4055 List of figuresFigure 1.Clock scheme. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 2.I2S clock generator architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 3.Wizard mode user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 4.Select the clock source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 5.File generation error. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 6.Expert mode user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 7.System clock frequency is exceeded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4/17Doc ID 022837 Rev 1AN4055Glossary 1 GlossaryTable 1.Definition of termsTerm DescriptionHCLK AHB clockPCLK1APB1 clockPCLK2APB2 clockTIMCLK Timer clockF CPU Cortex-M0 clockExt.Clock External clockV DD Power supplyHSI High-speed internal clockHSE High-speed external clockMCLK Master clockI2S Integrated interchip soundFs Sampling frequencyI2SCLK I2S clockDoc ID 022837 Rev 15/17Getting started AN40556/17Doc ID 022837 Rev 12 Getting startedThis section describes the requirements and procedures needed to start using the clocktool.2.1 Software requirementsTo use the clock tool with Windows ® operating system, a recent version of Windows, suchas Windows XP , Vista or Windows 7 must be installed on the PC with at least 256 Mbytes of RAM.Before starting to use the clock tool, make sure that Microsoft ® Office is installed on your machine and then follow these steps:●Download the latest version of the clock tool for the STM32F0xx product from .●Enable macros and ActiveX ® controls:Excel ® 1997-2003 version1.Click Tools in the menu bar.2. Click Macro .3. Click Security .4. Click Low (not recommended).Note:If ActiveX controls are not enabled, a warning message is displayed asking you to enable ActiveX. In this case, you should click “OK” to enable it.Excel 2007 version1.Click the Microsoft Office button and then click Excel options .2. Click Trust Center , click Trust center settings , and then click Macro settings .3. Click Enable all macros (not recommended, potentially dangerous code can run).4. Click Trust Center , click Trust center settings , and then click ActiveX settings .5. Click Enable all controls without restrictions and without prompting (notrecommended; potentiality dangerous controls can run).6. Click OK .Note:For more information about how to enable macros and ActiveX controls please refer to the Microsoft Office website.AN4055Getting startedDoc ID 022837 Rev 17/172.2 Hardware requirements2.2.1 IntroductionThe clock tool is designed to configure the system clocks and generate thesystem_stm32f0xx.c file for STM32F0xx microcontrollers.The system_stm32f0xx.c file is provided as a template system clock configuration file which can be easily modified to select the corresponding system clock frequency and to configure the Flash latency.2.2.2 Clock scheme for STM32F0xx microcontrollersThis section describes the system clock scheme that is dependent on the voltagerequirements (V DD ) versus the system clock frequency and Flash latency versus the system clock frequency.Three different clock sources can be used to drive the system clock (SYSCLK):1.HSI (8 MHz) oscillator clock2. HSE (4 MHz to 32 MHz) oscillator clock3.Main phase-locked loop (PLL) clock with a PLL voltage-controlled oscillator (PLLVCO) input frequency.All peripheral clocks are derived from the SYSCLK.Note:The number of Flash memory wait states (latency) is defined according to the frequency of the CPU (Cortex-M0):- Zero wait states if 0 < SYSCLK <= 24 MHz - One wait state if SYSCLK > 24 MHzGetting started AN40558/17Doc ID 022837 Rev 1AN4055Getting startedDoc ID 022837 Rev 19/172.2.3 I2S clock generatorThis section describes the I2S clock generator. It is dependent on:●Master clock MCLK (enable or disable)●Frame width●I2S peripheral clock (I2SCLK).Figure 2.I2S clock generator architectureThe audio sampling frequency may be 192 kHz, 96 kHz, 48 kHz, 44.1 kHz, 32 kHz,22.05 kHz, 16 kHz, 11.025 kHz or 8 kHz. To reach the desired frequency, the linear divider (DIV) needs to be programmed according to the formulas below:When the master clock is generated (MCKOE bit in the SPI_I2SPR register is set):●FS = I2SxCLK/[(16*2)*((2*I2SDIV)+ODD)*8)] when the channel frame is 16 bits wide ●FS = I2SxCLK/[(32*2)*((2*I2SDIV)+ODD)*4)] when the channel frame is 32 bits wide Where ODD is an odd factor for the prescaler.When the master clock is disabled (MCKOE bit cleared):●FS = I2SxCLK/[(16*2)*((2*I2SDIV)+ODD))] when the channel frame is 16 bits wide ●FS = I2SxCLK/[(32*2)*((2*I2SDIV)+ODD))] when the channel frame is 32 bits wideNote:This tool does not configure the I2S register.The sampling frequency error is computed as an indicator according to the I2S parameters which are not configured in the output file “system_stm32f0xx.c”.8-bit divider +linearCKODDI2SDIV[7:0]I2SxCLKCHLENI2SMOD reshaping stageDivider by 4Div210MCKOE MCKOEMCK1Tutorials AN405510/17Doc ID 022837 Rev 13 TutorialsThis section describes how to use the clock tool to configure all system clocks and generate the system_stm32f0xx.c file. Two modes are available: Wizard and Expert . The selection is made in the Configuration mode list box.3.1 Wizard modeThis mode (default mode) guides you through a series of steps to obtain the desired clocksystem configuration quickly and easily.Figure 3.Wizard mode user interfaceNote:The ‘Reset ’ button permits the system clock for the default configuration to be set.The wizard guides you through the following steps:1.Set the HSE frequency (if is used in your application) between a minimum of 4 MHz, and a maximum of 32 MHz if a crystal oscillator is used for the STM32F0xx. If thefrequency entered is out of range, an error message is displayed, and a valid frequency must be entered.The definition of HSE_VALUE in the stm32f0xx.h file must be modified each time the user changes the HSE oscillator value.2. Configure the Prefetch buffer (select ON or OFF from the list box).3. Specify if the I2S clock is needed. If needed, enable it and follow steps 7, 8 and 9.Otherwise, go to step 4.4. Set the desired HCLK frequency. If the value entered is higher than the maximum HCLK frequency, an error message is displayed.5.Select the PCLK1 and PCLK2 prescaler settings from the list box to obtain the desired PCLK1 and PCLK2 frequencies. The TIMCLK frequencies are configured automatically depending on the PCLK1 and PCLK2 prescaler settings.AN4055Tutorials Doc ID 022837 Rev 111/17Note:In this product PCLK1 and PCLK2 share the some clock signal, so APB1 prescaler shouldalways equal APB2 prescaler.6.If the I2S clock is needed, select the frame width (16 or 32 bits).7.Specify if the master clock is enabled or disabled (Select ON/OFF from the list box).8. Select the Frequency from the list box. The Fs value can be 192 kHz, 96 kHz, 48 kHz,44.1 kHz, 32 kHz, 22.05 kHz, 16 kHz, 11.025 kHz, or 8 kHz.9. Click the RUN button.If more than one clock source is possible, a message box displays the clock sourcesthat can be selected (see Figure 4). Choose HSE, HSI or PLL (which are sourced bythe HSI or HSE).Figure 4.Select the clock source 10. Clickthe Generate button to automatically generate system_stm32f0xx.c file.The system_stm32f0xx.c file is generated in the same location as the clock tool.Display the file to verify the value of the system clock, SystemCoreClock, and thevalues of HCLK, PCLK1, PCLK2, Flash access mode, and other parameters which aredefined in the SetSysClock function.If the file is not generated, an error message is displayed as shown Figure 5.Figure 5.File generation error11. The system_stm32f0xx.c file must be added to the working project to be built.Tutorials AN405512/17Doc ID 022837 Rev 13.2 Expert modeThis mode provides more flexibility regarding the configuration setup but the user mustensure that the configuration is correct.Figure 6.Expert mode user interfaceThe ‘View ’ button permits the .xls file to be viewed in full screen, to be activated ordeactivated.The ‘Reset ’ button permits the system clock to be reset to the default configuration.These main steps are described in detail in this section:1.Configure the SYSCLK frequency.2.If required, enable the I2S clock and configure the I2S clock frequency.3. If required, configure the Prefetch buffer.4. Generate the system_stm32f0xx.c file.5. Add the system_stm32f0xx.c file to the working project to be built.AN4055TutorialsDoc ID 022837 Rev 113/171.Configure the SYSCLK frequency.a) If the HSE is used in your application, set its frequency to between 4MHz and32MHz (set it to 32 MHz if a crystal oscillator is used for the STM32F0xx.If the frequency entered is out of range, an error message is displayed. A validfrequency must be entered.Note:The definition of HSE_VALUE in the stm32f0xx.h file must be modified each time the userchanges the HSE oscillator value.b) Configure the SYSCLK source (PLL, HSE or HSI). If the clock source selection isinvalid (HCLK frequency is too high) the error message in Figure 7 is displayed.Figure 7.System clock frequency is exceededc) If PLL is selected as the SYSCLK source, it is necessary to select the source clockfor the PLL (HSE or HSI).d) If PLL is selected as the SYSCLK source, configure the main PLL (PLLMUL) andthe PLL division factor (PREDIV) if the HSE is selected as PLL clock source.e) Set HCLK prescaler using the AHBPrescaler list box to obtain the desired HCLKfrequency.f) Select PCLK1 prescaler settings from the list box to obtain the desired PCLK1frequency. The TIMCLK frequencies are configured automatically depending onthe PCLK1 prescaler settings.g) Select PCLK2 prescaler settings from the list box to obtain the desired PCLK2frequency. The TIMCLK frequencies are configured automatically depending onthe PCLK2 prescaler settings.Note:In this product the PCLK1 and PCLK2 share the some clock signal, so APB1 prescalershould always equal APB2 prescaler.h) Configure the Flash Latency: after setting the HCLK prescaler, the number ofFlash wait states is configured automatically with the best value (lowest possiblevalue) which can be modified to any value higher than the best value.i)Generate the clock configuration files by clicking on the Generate button.2. If required, enable the I2S clock and configure the I2S clock frequency.a) Select frame width (16 or 32 bits) and specify if the master clock is enabled or not.b) Select the Fs from the list box. The Fs value can be 192 kHz, 96 kHz, 48 kHz, 44.1kHz, 32 kHz, 22.05 kHz, 16 kHz, 11.025 kHz and 8 kHz.3. Optionally configure the Prefetch buffer.4. Generate the system_stm32f0xx.c file.Click the Generate button to automatically generate the system_stm32f0xx.c file in thesame location as the clock tool. It can be displayed to verify the value of the SYSCLK,SystemCoreClock, and the values of HCLK, PCLK1, PCLK2, Flash access mode, andother parameters which are defined in the “SetSysClock” function.5. The system_stm32f0xx.c file must be added to the working project to be built.Known limitations AN405514/17Doc ID 022837 Rev 14 Known limitationsThis section describes the known limitations of the clock configuration tool.This tool does not support configurations that use the HSE external clock source (HSEbypass).AN4055Conclusion Doc ID 022837 Rev 115/175 ConclusionThis application note provides a description of how to use the clock tool with theSTM32F0xx microcontroller devices.This tool generates a source code file system_stm32f0xx.c to configure the clock system ofthe STM32F0xx. It can be accessed from either of the two configuration modes:●Wizard mode: provides a quick and easy way to configure the system clocks. ●Expert mode: offers more flexibility in setting up the system clock configuration while still respecting all the product constraints.Revision history AN405516/17Doc ID 022837 Rev 16 Revision historyTable 2.Document revision history DateRevision Changes03-May-20121Initial releaseAN4055Please Read Carefully:Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.All ST products are sold pursuant to ST’s terms and conditions of sale.Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein.No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.UNL ESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SAL E ST DISCL AIMS ANY EXPRESS OR IMPL IED WARRANTY WITH RESPECT TO THE USE AND/OR SAL E OF ST PRODUCTS INCL UDING WITHOUT L IMITATION IMPL IED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNL ESS EXPRESSL Y APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST.ST and the ST logo are trademarks or registered trademarks of ST in various countries.Information in this document supersedes and replaces all information previously supplied.The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.© 2012 STMicroelectronics - All rights reservedSTMicroelectronics group of companiesAustralia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of AmericaDoc ID 022837 Rev 117/17。
STM32时钟配置方法详解
STM32时钟配置方法详解时钟树是STM32微控制器中一系列时钟源和时钟分频器的组成部分。
时钟树包括系统时钟、外设时钟和内核时钟。
系统时钟用于驱动整个微控制器系统的核心,外设时钟用于驱动各种外设,内核时钟用于驱动CPU的运算。
在进行时钟配置之前,首先需要了解系统所需的时钟频率。
在STM32中,系统时钟可以通过多种方式进行配置,例如使用外部晶体、外部时钟、内部RC振荡器或者PLL(锁相环)等方式。
外部晶体是一种常用的时钟源,可以提供高精度的时钟频率。
在使用外部晶体时,首先需要设置PLL的时钟源为外部晶体,并设置PLL输入除频器的分频系数。
然后,再根据系统所需的时钟频率,设置PLL的倍频系数,以得到最终的系统时钟频率。
外部时钟是从外部提供的时钟信号,一般用于测试和调试。
使用外部时钟时,需要设置PLL的时钟源为外部时钟,并设置PLL的倍频系数,以得到所需的系统时钟频率。
内部RC振荡器是一种低成本的时钟源,但是其频率不如外部晶体稳定和精确。
在使用内部RC振荡器时,需要设置PLL的时钟源为内部RC振荡器,并设置PLL的倍频系数,以得到所需的系统时钟频率。
PLL是一种用于产生稳定高频时钟的电路,可以从一个低频时钟源产生一个高频时钟源。
使用PLL时,需要设置其输入时钟源和倍频系数。
系统时钟的分频系数可以通过RCC_CFGR寄存器进行设置。
RCC_CFGR寄存器的各个位域用于配置系统时钟的分频系数,包括分频因子、APB1的分频系数、APB2的分频系数等。
外设时钟是用于驱动外设的时钟,可以由系统时钟分频得到。
外设时钟的分频系数可以通过RCC_CFGR寄存器及各个外设的控制寄存器进行设置。
内核时钟是用于驱动CPU的运算的时钟。
在STM32微控制器中,CPU 时钟可以由系统时钟分频得到,分频系数可以通过RCC_CFGR寄存器和FLASH_ACR寄存器进行设置。
除了上述方法之外,STM32还可以使用时钟配置工具进行时钟配置。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
May 2012Doc ID 022837 Rev 11/17AN4055Application noteClock configuration tool for STM32F0xx microcontrollersIntroductionThis application note presents the clock system configuration tool for the STM32F0xx microcontroller family.The purpose of this tool is to help the user configure the microcontroller clocks, taking into consideration product parameters such as power supply and Flash access mode.The configuration tool is implemented in the “STM32F0xx_Clock_Configuration_VX.Y .Z.xls” file which is supplied with the STM32F0xx Standard Peripherals Library and can be downloaded from .This tool supports the following functionalities for the STM32F0xx:●Configuration of the system clock, HCLK source and output frequency●Configuration of the Flash latency (number of wait states depending on the HCLK frequency)●Setting of the PCLK1, PCLK2, TIMCLK (timer clocks) and I2SCLK frequencies ●Generation of a ready-to-use system_stm32f0xx.c file with all the above settings(STM32F0xx CMSIS Cortex-M0 Device Peripheral Access Layer System Source File)The STM32F0xx_Clock_Configuration_VX.Y .Z.xls is referred to as “clock tool” throughout this document.Before using the clock tool, it is essential to read the STM32F0xx microcontroller reference manual (RM0091). This application note is not a substitute for the reference manual.This tool supports only the STM32F0xx devices.For VX.Y .Z, please refer to the tool version, example V1.0.0Contents AN4055Contents1Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.1Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2.2Clock scheme for STM32F0xx microcontrollers . . . . . . . . . . . . . . . . . . . 72.2.3I2S clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.1Wizard mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.2Expert mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4Known limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 6Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162/17Doc ID 022837 Rev 1AN4055List of tables List of tablesTable 1.Definition of terms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Table 2.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Doc ID 022837 Rev 13/17List of figures AN4055 List of figuresFigure 1.Clock scheme. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 2.I2S clock generator architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 3.Wizard mode user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 4.Select the clock source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 5.File generation error. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 6.Expert mode user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 7.System clock frequency is exceeded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4/17Doc ID 022837 Rev 1AN4055Glossary 1 GlossaryTable 1.Definition of termsTerm DescriptionHCLK AHB clockPCLK1APB1 clockPCLK2APB2 clockTIMCLK Timer clockF CPU Cortex-M0 clockExt.Clock External clockV DD Power supplyHSI High-speed internal clockHSE High-speed external clockMCLK Master clockI2S Integrated interchip soundFs Sampling frequencyI2SCLK I2S clockDoc ID 022837 Rev 15/17Getting started AN40556/17Doc ID 022837 Rev 12 Getting startedThis section describes the requirements and procedures needed to start using the clocktool.2.1 Software requirementsTo use the clock tool with Windows ® operating system, a recent version of Windows, suchas Windows XP , Vista or Windows 7 must be installed on the PC with at least 256 Mbytes of RAM.Before starting to use the clock tool, make sure that Microsoft ® Office is installed on your machine and then follow these steps:●Download the latest version of the clock tool for the STM32F0xx product from .●Enable macros and ActiveX ® controls:Excel ® 1997-2003 version1.Click Tools in the menu bar.2. Click Macro .3. Click Security .4. Click Low (not recommended).Note:If ActiveX controls are not enabled, a warning message is displayed asking you to enable ActiveX. In this case, you should click “OK” to enable it.Excel 2007 version1.Click the Microsoft Office button and then click Excel options .2. Click Trust Center , click Trust center settings , and then click Macro settings .3. Click Enable all macros (not recommended, potentially dangerous code can run).4. Click Trust Center , click Trust center settings , and then click ActiveX settings .5. Click Enable all controls without restrictions and without prompting (notrecommended; potentiality dangerous controls can run).6. Click OK .Note:For more information about how to enable macros and ActiveX controls please refer to the Microsoft Office website.AN4055Getting startedDoc ID 022837 Rev 17/172.2 Hardware requirements2.2.1 IntroductionThe clock tool is designed to configure the system clocks and generate thesystem_stm32f0xx.c file for STM32F0xx microcontrollers.The system_stm32f0xx.c file is provided as a template system clock configuration file which can be easily modified to select the corresponding system clock frequency and to configure the Flash latency.2.2.2 Clock scheme for STM32F0xx microcontrollersThis section describes the system clock scheme that is dependent on the voltagerequirements (V DD ) versus the system clock frequency and Flash latency versus the system clock frequency.Three different clock sources can be used to drive the system clock (SYSCLK):1.HSI (8 MHz) oscillator clock2. HSE (4 MHz to 32 MHz) oscillator clock3.Main phase-locked loop (PLL) clock with a PLL voltage-controlled oscillator (PLLVCO) input frequency.All peripheral clocks are derived from the SYSCLK.Note:The number of Flash memory wait states (latency) is defined according to the frequency of the CPU (Cortex-M0):- Zero wait states if 0 < SYSCLK <= 24 MHz - One wait state if SYSCLK > 24 MHzGetting started AN40558/17Doc ID 022837 Rev 1AN4055Getting startedDoc ID 022837 Rev 19/172.2.3 I2S clock generatorThis section describes the I2S clock generator. It is dependent on:●Master clock MCLK (enable or disable)●Frame width●I2S peripheral clock (I2SCLK).Figure 2.I2S clock generator architectureThe audio sampling frequency may be 192 kHz, 96 kHz, 48 kHz, 44.1 kHz, 32 kHz,22.05 kHz, 16 kHz, 11.025 kHz or 8 kHz. To reach the desired frequency, the linear divider (DIV) needs to be programmed according to the formulas below:When the master clock is generated (MCKOE bit in the SPI_I2SPR register is set):●FS = I2SxCLK/[(16*2)*((2*I2SDIV)+ODD)*8)] when the channel frame is 16 bits wide ●FS = I2SxCLK/[(32*2)*((2*I2SDIV)+ODD)*4)] when the channel frame is 32 bits wide Where ODD is an odd factor for the prescaler.When the master clock is disabled (MCKOE bit cleared):●FS = I2SxCLK/[(16*2)*((2*I2SDIV)+ODD))] when the channel frame is 16 bits wide ●FS = I2SxCLK/[(32*2)*((2*I2SDIV)+ODD))] when the channel frame is 32 bits wideNote:This tool does not configure the I2S register.The sampling frequency error is computed as an indicator according to the I2S parameters which are not configured in the output file “system_stm32f0xx.c”.8-bit divider +linearCKODDI2SDIV[7:0]I2SxCLKCHLENI2SMOD reshaping stageDivider by 4Div210MCKOE MCKOEMCK1Tutorials AN405510/17Doc ID 022837 Rev 13 TutorialsThis section describes how to use the clock tool to configure all system clocks and generate the system_stm32f0xx.c file. Two modes are available: Wizard and Expert . The selection is made in the Configuration mode list box.3.1 Wizard modeThis mode (default mode) guides you through a series of steps to obtain the desired clocksystem configuration quickly and easily.Figure 3.Wizard mode user interfaceNote:The ‘Reset ’ button permits the system clock for the default configuration to be set.The wizard guides you through the following steps:1.Set the HSE frequency (if is used in your application) between a minimum of 4 MHz, and a maximum of 32 MHz if a crystal oscillator is used for the STM32F0xx. If thefrequency entered is out of range, an error message is displayed, and a valid frequency must be entered.The definition of HSE_VALUE in the stm32f0xx.h file must be modified each time the user changes the HSE oscillator value.2. Configure the Prefetch buffer (select ON or OFF from the list box).3. Specify if the I2S clock is needed. If needed, enable it and follow steps 7, 8 and 9.Otherwise, go to step 4.4. Set the desired HCLK frequency. If the value entered is higher than the maximum HCLK frequency, an error message is displayed.5.Select the PCLK1 and PCLK2 prescaler settings from the list box to obtain the desired PCLK1 and PCLK2 frequencies. The TIMCLK frequencies are configured automatically depending on the PCLK1 and PCLK2 prescaler settings.AN4055Tutorials Doc ID 022837 Rev 111/17Note:In this product PCLK1 and PCLK2 share the some clock signal, so APB1 prescaler shouldalways equal APB2 prescaler.6.If the I2S clock is needed, select the frame width (16 or 32 bits).7.Specify if the master clock is enabled or disabled (Select ON/OFF from the list box).8. Select the Frequency from the list box. The Fs value can be 192 kHz, 96 kHz, 48 kHz,44.1 kHz, 32 kHz, 22.05 kHz, 16 kHz, 11.025 kHz, or 8 kHz.9. Click the RUN button.If more than one clock source is possible, a message box displays the clock sourcesthat can be selected (see Figure 4). Choose HSE, HSI or PLL (which are sourced bythe HSI or HSE).Figure 4.Select the clock source 10. Clickthe Generate button to automatically generate system_stm32f0xx.c file.The system_stm32f0xx.c file is generated in the same location as the clock tool.Display the file to verify the value of the system clock, SystemCoreClock, and thevalues of HCLK, PCLK1, PCLK2, Flash access mode, and other parameters which aredefined in the SetSysClock function.If the file is not generated, an error message is displayed as shown Figure 5.Figure 5.File generation error11. The system_stm32f0xx.c file must be added to the working project to be built.Tutorials AN405512/17Doc ID 022837 Rev 13.2 Expert modeThis mode provides more flexibility regarding the configuration setup but the user mustensure that the configuration is correct.Figure 6.Expert mode user interfaceThe ‘View ’ button permits the .xls file to be viewed in full screen, to be activated ordeactivated.The ‘Reset ’ button permits the system clock to be reset to the default configuration.These main steps are described in detail in this section:1.Configure the SYSCLK frequency.2.If required, enable the I2S clock and configure the I2S clock frequency.3. If required, configure the Prefetch buffer.4. Generate the system_stm32f0xx.c file.5. Add the system_stm32f0xx.c file to the working project to be built.AN4055TutorialsDoc ID 022837 Rev 113/171.Configure the SYSCLK frequency.a) If the HSE is used in your application, set its frequency to between 4MHz and32MHz (set it to 32 MHz if a crystal oscillator is used for the STM32F0xx.If the frequency entered is out of range, an error message is displayed. A validfrequency must be entered.Note:The definition of HSE_VALUE in the stm32f0xx.h file must be modified each time the userchanges the HSE oscillator value.b) Configure the SYSCLK source (PLL, HSE or HSI). If the clock source selection isinvalid (HCLK frequency is too high) the error message in Figure 7 is displayed.Figure 7.System clock frequency is exceededc) If PLL is selected as the SYSCLK source, it is necessary to select the source clockfor the PLL (HSE or HSI).d) If PLL is selected as the SYSCLK source, configure the main PLL (PLLMUL) andthe PLL division factor (PREDIV) if the HSE is selected as PLL clock source.e) Set HCLK prescaler using the AHBPrescaler list box to obtain the desired HCLKfrequency.f) Select PCLK1 prescaler settings from the list box to obtain the desired PCLK1frequency. The TIMCLK frequencies are configured automatically depending onthe PCLK1 prescaler settings.g) Select PCLK2 prescaler settings from the list box to obtain the desired PCLK2frequency. The TIMCLK frequencies are configured automatically depending onthe PCLK2 prescaler settings.Note:In this product the PCLK1 and PCLK2 share the some clock signal, so APB1 prescalershould always equal APB2 prescaler.h) Configure the Flash Latency: after setting the HCLK prescaler, the number ofFlash wait states is configured automatically with the best value (lowest possiblevalue) which can be modified to any value higher than the best value.i)Generate the clock configuration files by clicking on the Generate button.2. If required, enable the I2S clock and configure the I2S clock frequency.a) Select frame width (16 or 32 bits) and specify if the master clock is enabled or not.b) Select the Fs from the list box. The Fs value can be 192 kHz, 96 kHz, 48 kHz, 44.1kHz, 32 kHz, 22.05 kHz, 16 kHz, 11.025 kHz and 8 kHz.3. Optionally configure the Prefetch buffer.4. Generate the system_stm32f0xx.c file.Click the Generate button to automatically generate the system_stm32f0xx.c file in thesame location as the clock tool. It can be displayed to verify the value of the SYSCLK,SystemCoreClock, and the values of HCLK, PCLK1, PCLK2, Flash access mode, andother parameters which are defined in the “SetSysClock” function.5. The system_stm32f0xx.c file must be added to the working project to be built.Known limitations AN405514/17Doc ID 022837 Rev 14 Known limitationsThis section describes the known limitations of the clock configuration tool.This tool does not support configurations that use the HSE external clock source (HSEbypass).AN4055Conclusion Doc ID 022837 Rev 115/175 ConclusionThis application note provides a description of how to use the clock tool with theSTM32F0xx microcontroller devices.This tool generates a source code file system_stm32f0xx.c to configure the clock system ofthe STM32F0xx. It can be accessed from either of the two configuration modes:●Wizard mode: provides a quick and easy way to configure the system clocks. ●Expert mode: offers more flexibility in setting up the system clock configuration while still respecting all the product constraints.Revision history AN405516/17Doc ID 022837 Rev 16 Revision historyTable 2.Document revision history DateRevision Changes03-May-20121Initial releaseAN4055Please Read Carefully:Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.All ST products are sold pursuant to ST’s terms and conditions of sale.Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein.No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.UNL ESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SAL E ST DISCL AIMS ANY EXPRESS OR IMPL IED WARRANTY WITH RESPECT TO THE USE AND/OR SAL E OF ST PRODUCTS INCL UDING WITHOUT L IMITATION IMPL IED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNL ESS EXPRESSL Y APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST.ST and the ST logo are trademarks or registered trademarks of ST in various countries.Information in this document supersedes and replaces all information previously supplied.The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.© 2012 STMicroelectronics - All rights reservedSTMicroelectronics group of companiesAustralia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of AmericaDoc ID 022837 Rev 117/17。