基于STM32F10时钟系统MCU的开发及配置
原标题:基于STM32时钟系统的开发及配置
一、背景
最近做个项目,需要使用STM32,还是以前一样的观点,时钟就是MCU心脏,供血即时钟频率输出,想要弄明白一个MCU,时钟是一个非常好的切入点。言归正传,网上已经有太多大神详述过STM32的详细配置方法了,在此就简单介绍下STM32时钟系统,以及如何配置做个简单记录,方便以后的快速开发。
二、正文
废话不多说,上一张STM32F10xx的时钟树图:
由图可知,STM32F10XX有两级时钟
第一级时钟
* 高速内部时钟(HSI)
* 锁相环时钟(PLLCLK)
* 高速外部时钟(HSE)
第二级时钟
* 低速内部时钟(LSI)
* 低速外部时钟(LSE)
又由图可知,
* HSE由外部晶振从“OSC_OUT”,“OSC_IN”两脚输入提供。
* LSE由外部晶振从“OSC32_OUT”,“OSC32_IN”两脚输入提供。
* HSI由8MHZ高速内部RC震荡电路提供。
* LSI由40kHZ低速内部RC震荡电路提供。
STM32F10XX还可通过MCO脚向外提供时钟输出。时钟来源有PLLCLK/HSI/HSE/SYSCLK,由MCO选择器来选择。
研究过时钟来源,再来研究时钟的去向,MCU自身要能正常运作,即需要一个时钟,这个时钟既是系统时钟(SYSCLK),而基本上所有外设的时钟均来自于这个系统时钟(SYSCLk)。然后由系统时钟对外提供各种外设时钟。详见图。
当然,也有例外,USB时钟必须为48MHZ,这里的USB时钟(USBCLK)由PLLCLK直接提供,RTC时钟(RTCCLK)也不是来源于系统时钟(SYSCLK),详见图。
时钟结构大体也就如此,不再深究,网上有许多更加深入的讲解,接下来说说如何去配置。用代码来说明问题:
先贴文件“system_stm32f10x.c”,此文件即库文件。里面有一个很重要的函数“SystemInit()”
解析过STM32启动代码的朋友都应该知道,这个函数跑在进入main函数之前,里面做的事情即是配置系统时钟。代码如下:
voidSystemInit(void){/*ResettheRCCclockconfigurationtothedefaultresetstate(fordebugpurpose)*//*SetHSIONbit
STM32F10主控芯片大全:
型号 | Description |
---|---|
STM32F103VB | Mainstream Performance line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103VE | Mainstream Performance line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103R6 | Mainstream Performance line, ARM Cortex-M3 MCU with 32 Kbytes Clash, 72 MHz CPU, motor control, USB and CAN |
STM32F103ZE | Mainstream Performance line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103ZG | Mainstream Performance line, ARM Cortex-M3 MCU with 1 Mbyte Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103CB | Mainstream Performance line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103R8 | Mainstream Performance line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F100C8 | Mainstream Value line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100R8 | Mainstream Value line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F103VC | Mainstream Performance line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103VG | Mainstream Performance line, ARM Cortex-M3 MCU with 1 Mbyte Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F105VC | Mainstream Connectivity line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 72 MHz CPU, CAN, USB 2.0 OTG |
STM32F100RB | Mainstream Value line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100VC | Mainstream value line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F103C6 | Mainstream Performance line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103RB | Mainstream Performance line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103VD | Mainstream Performance line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103ZC | Mainstream Performance line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103ZD | Mainstream Performance line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103ZF | Mainstream Performance line, ARM Cortex-M3 MCU with 768 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F105RC | Mainstream Connectivity line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 72 MHz CPU, CAN, USB 2.0 OTG |
STM32F100CB | Mainstream Value line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100R6 | Mainstream Value line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100RD | Mainstream Value line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100RE | Mainstream Value line, ARM Cortex-M3 MCU with 512 Kbytes, 24 MHz CPU, motor control and CEC functions |
STM32F100VD | Mainstream Value line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100VE | Mainstream Value line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F101C8 | Mainstream Access line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 36 MHz CPU |
STM32F101CB | Mainstream Access line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 36 MHz CPU |
STM32F101R6 | Mainstream Access line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 36 MHz CPU |
STM32F103C8 | Mainstream Performance line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103R4 | Mainstream Performance line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103RC | Mainstream Performance line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103RE | Mainstream Performance line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103RF | Mainstream Performance line, ARM Cortex-M3 MCU with 768 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103RG | Mainstream Performance line, ARM Cortex-M3 MCU with 1 Mbyte Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103T8 | Mainstream Performance line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103V8 | Mainstream Performance line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F105V8 | Mainstream Connectivity line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 72 MHz CPU, CAN, USB 2.0 OTG |
STM32F105VB | Mainstream Connectivity line, ARM Cortex-M3 MCU with 128 Kbytes Flash,72 MHz CPU, CAN, USB 2.0 OTG |
STM32F107VC | Mainstream Connectivity line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 72 MHz CPU, Ethernet MAC, CAN and USB 2.0 OTG |
STM32F100C4 | Mainstream Value line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100C6 | Mainstream Value line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100R4 | Mainstream Value line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100V8 | Mainstream Value line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100VB | Mainstream Value line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100ZE | Mainstream Value line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F101C6 | Mainstream Access line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 36 MHz CPU |
STM32F101RB | Mainstream Access line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 36 MHz CPU |
STM32F101RC | Mainstream Access line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 36 MHz CPU |
STM32F101T6 | Mainstream Access line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 36 MHz CPU |
STM32F102C6 | Mainstream USB Access line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 48 MHz CPU, USB FS |
STM32F103RD | Mainstream Performance line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103T6 | Mainstream Performance line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103TB | Mainstream Performance line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103VF | Mainstream Performance line, ARM Cortex-M3 MCU with 768 Kbytes Flash, 72MHz CPU, motor control, USB and CAN |
STM32F105R8 | Mainstream Connectivity line, ARM Cortex-M3 with 64 Kbytes Flash, 72 MHz CPU, CAN, USB 2.0 OTG |
STM32F105RB | Mainstream Connectivity line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 72 MHz CPU, CAN, USB 2.0 OTG |
STM32F107RB | Mainstream Connectivity line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 72 MHz CPU, Ethernet MAC, CAN and USB 2.0 OTG |
STM32F107RC | Mainstream Connectivity line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 72 MHz CPU, Ethernet MAC, CAN and USB 2.0 OTG |
STM32F107VB | Mainstream Connectivity line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 72 MHz CPU, Ethernet MAC, CAN and USB 2.0 OTG |
STM32F100RC | Mainstream Value line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F100ZD | Mainstream Value line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F101R8 | Mainstream Access line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 36 MHz CPU |
STM32F101RD | Mainstream Access line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 36 MHz CPU |
STM32F101RE | Mainstream Access line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 36 MHz CPU |
STM32F101RG | Mainstream Access line, ARM Cortex-M3 MCU with 1 Mbyte Flash, 36 MHz CPU |
STM32F101T4 | Mainstream Access line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 36 MHz CPU |
STM32F101T8 | Mainstream Access line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 36 MHz CPU |
STM32F101TB | Mainstream Access line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 36 MHz CPU |
STM32F101V8 | Mainstream Access line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 36 MHZ CPU |
STM32F101VB | Mainstream Access line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 36 MHz CPU |
STM32F101VC | Mainstream Access line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 36 MHz CPU |
STM32F101VD | Mainstream Access line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 36 MHz CPU |
STM32F101VE | Mainstream Access line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 36 MHz CPU |
STM32F102C4 | Mainstream USB Access line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 48 MHz CPU, USB FS |
STM32F102C8 | Mainstream USB Access line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 48 MHz CPU, USB FS |
STM32F102CB | Mainstream USB Access line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 48 MHz CPU, USB FS |
STM32F102RB | Mainstream USB Access line, ARM Cortex-M3 MCU with 128 Kbytes Flash, 48 MHz CPU, USB FS |
STM32F103C4 | Mainstream Performance line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F103T4 | Mainstream Performance line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 72 MHz CPU, motor control, USB and CAN |
STM32F101VF | Mainstream Access line, ARM Cortex-M3 MCU with 768 Kbytes Flash, 36 MHz CPU |
STM32F100ZC | Mainstream Value line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 24 MHz CPU, motor control and CEC functions |
STM32F101C4 | Mainstream Access line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 36 MHz CPU |
STM32F101R4 | Mainstream Access line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 36 MHz CPU |
STM32F101RF | Mainstream Access line, ARM Cortex-M3 MCU with 768 Kbytes Flash, 36 MHz CPU |
STM32F101VG | Mainstream Access line, ARM Cortex-M3 MCU with 1 Mbyte Flash, 36 MHz CPU |
STM32F101ZC | Mainstream Access line, ARM Cortex-M3 MCU with 256 Kbytes Flash, 36 MHz CPU |
STM32F101ZD | Mainstream Access line, ARM Cortex-M3 MCU with 384 Kbytes Flash, 36 MHz CPU |
STM32F101ZE | Mainstream Access line, ARM Cortex-M3 MCU with 512 Kbytes Flash, 36 MHz CPU |
STM32F101ZF | Mainstream Access line, ARM Cortex-M3 MCU with 768 Kbytes Flash, 36 MHz CPU |
STM32F101ZG | Mainstream Access line, ARM Cortex-M3 MCU with 1 Mbyte Flash, 36 MHz CPU |
STM32F102R4 | Mainstream USB Access line, ARM Cortex-M3 MCU with 16 Kbytes Flash, 48 MHz CPU, USB, FS |
STM32F102R6 | Mainstream USB Access line, ARM Cortex-M3 MCU with 32 Kbytes Flash, 48 MHz CPU, USB FS |
STM32F102R8 | Mainstream USB Access line, ARM Cortex-M3 MCU with 64 Kbytes Flash, 48 MHz CPU, USB FS |
责任编辑:David
【免责声明】
1、本文内容、数据、图表等来源于网络引用或其他公开资料,版权归属原作者、原发表出处。若版权所有方对本文的引用持有异议,请联系拍明芯城(marketing@iczoom.com),本方将及时处理。
2、本文的引用仅供读者交流学习使用,不涉及商业目的。
3、本文内容仅代表作者观点,拍明芯城不对内容的准确性、可靠性或完整性提供明示或暗示的保证。读者阅读本文后做出的决定或行为,是基于自主意愿和独立判断做出的,请读者明确相关结果。
4、如需转载本方拥有版权的文章,请联系拍明芯城(marketing@iczoom.com)注明“转载原因”。未经允许私自转载拍明芯城将保留追究其法律责任的权利。
拍明芯城拥有对此声明的最终解释权。