前言
时不可以苟遇,道不可以虚行。
一、时钟树框图
- HSI 振荡器时钟
- HSE 振荡器时钟
- 主 PLL (PLL) 时钟
以上三种时钟源可以用来驱动系统时钟(SYSCLK);
还有两个次级时钟源:
- 32 kHz 低速内部 RC (LSI RC),该 RC 用于驱动独立看门狗,也可选择提供给 RTC 用 于停机/待机模式下的自动唤醒
- 32.768 kHz 低速外部晶振(LSE 晶振),用于驱动 RTC 时钟 (RTCCLK)

- 可通过多个预分频器配置 AHB 频率、高速 APB (APB2) 和低速 APB (APB1)。AHB 域的最大频率为 168 MHz。高速 APB2 域的最大允许频率为 84 MHz。低速 APB1 域的最大允许频 率为 42 MHz。
- RCC 向 Cortex 系统定时器 (SysTick) 馈送 8 分频的 AHB 时钟 (HCLK)。SysTick 可使用此时钟作为时钟源,也可使用 HCLK 作为时钟源,具体可在 SysTick 控制和状态寄存器中配置。
   


  
 
SystemInit 时钟系统初始化函数
- SystemInit 函数执行顺序在 main 函数之前,在启动文件中可以看出:
  
Systick 定时器(滴答定时器)
1、基础知识
- Systick 定时器,是一个简单的定时器,对于CM3、CM4 内核芯片,都有。
- Systick 定时器常用来延时,或者实时系统的心跳时钟,可以节省 MCU 的资源,不用浪费一个定时器,比如 UCOS 中,分时复用,需要一个最小的时间戳,一般在 stm32 + UCOS 系统中,都采用 Systick 定时器 做 UCOS 心跳时钟。
- Systick 定时器就是系统滴答定时器,一个 24 位的倒计数定时器,计到 0 时,将从 RELOAD 寄存器中自动重装载定时初值,只要不把它在 Systick 控制及状态寄存器中的使能位清除,就永不停息,即使在睡眠模式下也能工作
- Systick 定时器被捆绑在 NVIC 中,用于产生 SYSTICK 异常(异常号:15)
- Systick 中断的优先级也可以设置
2、库函数
3、相关寄存器
CTRL :Systick 控制和状态寄存器 LOADSysTick :自动重装载除值寄存器VAL :Systick 当前值寄存器 CALIBSystick :校准值寄存器
   
|