STM8S CPU主时钟

STM8S上电后的时钟来源:

/* Public functions ----------------------------------------------------------*/
/**
* @addtogroup CLK_Public_Functions
* @{
*/

/**
* @brief Deinitializes the CLK peripheral registers to their default reset
* values.
* @param None
* @retval None
* @par Warning:
* Resetting the CCOR register: \n
* When the CCOEN bit is set, the reset of the CCOR register require
* two consecutive write instructions in order to reset first the CCOEN bit
* and the second one is to reset the CCOSEL bits.
*/
void CLK_DeInit(void)
{
CLK->ICKR = CLK_ICKR_RESET_VALUE;
CLK->ECKR = CLK_ECKR_RESET_VALUE;
CLK->SWR = CLK_SWR_RESET_VALUE; // 0xE1
CLK->SWCR = CLK_SWCR_RESET_VALUE;
CLK->CKDIVR = CLK_CKDIVR_RESET_VALUE;
CLK->PCKENR1 = CLK_PCKENR1_RESET_VALUE;
CLK->PCKENR2 = CLK_PCKENR2_RESET_VALUE;
CLK->CSSR = CLK_CSSR_RESET_VALUE;
CLK->CCOR = CLK_CCOR_RESET_VALUE;
while ((CLK->CCOR & CLK_CCOR_CCOEN)!= 0)
{}
CLK->CCOR = CLK_CCOR_RESET_VALUE;
CLK->HSITRIMR = CLK_HSITRIMR_RESET_VALUE;
CLK->SWIMCCR = CLK_SWIMCCR_RESET_VALUE;
}

CPU上电后是内站HSI时钟,16MHz :   16 MHz high-speed internal RC oscillator (HSI)

得到其它的时钟,可以通过时钟分频寄存器(CLK_CKDIVR)对时钟进行分频:

CPU 时钟分频器
CPU时钟(f CPU )由主时钟(f MASTER )分频而来,分频因子由时钟分频寄存器(CLK_CKDIVR)中的位
CPUDIV[2:0]决定。共7个分频因子可供选择(1至128中,2的幂)。f CPU 为CPU和窗口看门狗提供时钟。

那么CPU主时钟来源:

4.5 Clock controller
The clock controller distributes the system clock (fMASTER) coming from different
oscillators to the core and the peripherals. It also manages clock gating for low power
modes and ensures clock robustness.
Features
? Clock prescaler: to get the best compromise between speed and current consumption
the clock frequency to the CPU and peripherals can be adjusted by a programmable
prescaler.
? Safe clock switching: clock sources can be changed safely on the fly in run mode
through a configuration register. The clock signal is not switched until the new clock
source is ready. The design guarantees glitch-free switching.
? Clock management: to reduce power consumption, the clock controller can stop the
clock to the core, individual peripherals or memory.
? Master clock sources: four different clock sources can be used to drive the master
clock:
– 1-16 MHz high-speed external crystal (HSE)
– Up to 16 MHz high-speed user-external clock (HSE user-ext)
– 16 MHz high-speed internal RC oscillator (HSI)
– 128 kHz low-speed internal RC (LSI)
? Startup clock: After reset, the microcontroller restarts by default with an internal 2 MHz
clock (HSI/8). The prescaler ratio and clock source can be changed by the application
program as soon as the code execution starts.
? Clock security system (CSS): This feature can be enabled by software. If an HSE
clock failure occurs, the internal RC (16 MHz/8) is automatically selected by the CSS
and an interrupt can optionally be generated.
? Configurable main clock output (CCO): This outputs an external clock for use by the
application.

时间: 2024-08-05 11:16:15

STM8S CPU主时钟的相关文章

LPC1788系统时钟初始化

#ifndef __SYS_H_ #define __SYS_H_ #include "common.h" #define SystemCoreClock  120000000  //cpu时钟频率,计算时有用 #define ApbClock        120000000   //120M #define EmcClock        60000000    //60M #define UsbClock        48000000    //48M void SystemI

计算机的性能指标

__________________________________________青春=踏实+想法+实践+奋斗. CPU执行时间 = CPU时钟周期数 * CPU时钟周期 CPU执行时间表示一般程序所占用的CPU时间. CPU的工作节拍受CPU主时钟控制,主时钟不断产生固定频率的时钟,CPU的主时钟的频率(f)叫CPU的主频. CPU的主频的度量单位是MHz,GHz . 主频的倒数称为称为CPU 时钟周期(T),T= 1/f,度量单位是 微秒,ns. CPI=(执行某段程序所需要的)CPU时钟

STM8S学习笔记-时钟控制1

1.图13可见,STM8S单片机主要有四种时钟源可供选择: 1).1-24MHz外部晶体振荡器(HSE). 2).最大24MHz外部时钟(HSE ext). 3).16MHz高速内部RC振荡器(HSI). 4).128KHz低速内部RC振荡器(LSI). 2.主时钟可以从这四种时钟源中任意切换,切换过程可通过自动切换和手动切换. 自动切换过程: CLK_SWCR |= 0x20;    //使能切换 CLK_SWR = 0xE1; //  (HSI----复位值) // (0xD2 ----LS

STM8S编译时内存溢出错误的解决办法

? 导致COSMIC报告"segment .ubsct overflow"错误的根本原因是内存溢出, 相关原因分析如下: ? 1.变量存储空间结构 ? STM8S105系列CPU的RAM地址范围为0~0x7FF的2K空间,其中默认将高512字节分配给堆栈,剩下0~0x5FF字节为变量存储空间 .在0~0x5FF的空间范围内,低256字节被定义为Zero page,其中包括.bsct,.ubsct,.bit,.share ? 可见, 当segment .ubsct overflow错误出

STM8S时钟配置CLK_HSIPrescalerConfig与CLK_SYSCLKConfig区别

STM8S的时钟配置通过:CLK_CKDIVR寄存器,而CLK_CKDIVR一个是配置HSI分频,另一个是配置CPU的分频 static void CLK_Config(void){ CLK_DeInit(); /* Clock divider to HSI/1 */ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);  // 只配置HSI分频率,CPU分频率1 /* Output Fcpu on CLK_CCO pin */ CLK_CCOConfig

STM8S学习笔记-时钟控制2

今天把时钟系统的最后部分,时钟安全系统(CSS)和时钟输出功能(CCO),做一个简答的说明. 1.时钟安全系统(以下简称CSS) CSS功能很简单,就是监控HSE是否实效(如果系统使用HSE作为主时钟源),而自动切换到HSI/8作为主时钟源,从而避免系统停止运行. 如果使能CSSIEN,当主时钟失效,切换到HSI/8后可产生一个中断,这时可以改变HSI的分频,从而系统继续正常工作. 如果系统主时钟源不是HSE,则不用关心CSS. 2.时钟输出功能(以下简称CCO) CCO是MCU向外提供系统时钟

linux查看cpu个数,核数,逻辑cpu个数

物理CPU:物理CPU是相对于虚拟CPU而言的概念,指实际存在的处理器,就是我们可以看的见,摸得着的CPU,就是插在主板上面的. 物理核:CPU中包含的物理内核个数,比如我们通常说的双核CPU,单核CPU. 在linux系统下面的/proc/cpuinfo文件的条目中: 1.有多少个不同的physical id就有多少个物理CPU. 2.cpu cores记录了对应的物理CPU(以该条目中的physical id标识)有多少个物理核,现在我们个人使用的单机PC大部分使用的都是双核CPU. 逻辑C

CPU性能压测

有时候为了项目需求需要对CPU性能做一个压力测试,这里提供一种方法.通过对圆周率位数进行计算进而确定CPU性能,根据定义预计执行时间,具体操作如下: time echo "scale=1000; 4*a(1)" | bc -l -q 通过该命令运行,如果3.4分钟没有出现结果,基本问题就可以定位在CPU上,这里我通过自己的测试机,得出如下数字: "scale=1000; 4*a(1)"这个表达式具体什么意思我没看明白,但是大概意思应该是将该表达式的交给计算器bc来处

Linux 性能监控 : CPU 、Memory 、 IO 、Network

一.CPU 1.良好状态指标 CPU利用率:User Time <= 70%,System Time <= 35%,User Time + System Time <= 70% 上下文切换:与CPU利用率相关联,如果CPU利用率状态良好,大量的上下文切换也是可以接受的 可运行队列:每个处理器的可运行队列<=3个线程 2.监控工具 vmstat $ vmstat 1 procs -----------memory---------- ---swap-- -----io---- --s