文章目录
- 标准库下载
- 一、CMSIS标准及库层次关系
-
- [ 内核函数层:](# 内核函数层:)
- [ 设备外设访问层:](# 设备外设访问层:)
- 二、STM32F10x_StdPeriph_Lib_V3.5.0库目录、文件夹简介
-
- [ Libraries:](# Libraries:)
- [ Project :](# Project :)
- [ Utilities:](# Utilities:)
- [ stm32f10x_stdperiph_lib_um.chm:](# stm32f10x_stdperiph_lib_um.chm:)
- 三、Libraries目录
-
- [ 1、CMSIS](# 1、CMSIS)
- [ 2、STM32F10x_StdPeriph_Driver](# 2、STM32F10x_StdPeriph_Driver)
- [ 3、 stm32f10x_it.c、 stm32f10x_it.h、 stm32f10x_conf.h和system_stm32f10x.c文件](# 3、 stm32f10x_it.c、 stm32f10x_it.h、 stm32f10x_conf.h和system_stm32f10x.c文件)
- 四、文件间的关系
- 五、帮助文档
-
- [ 《STM32F10X-中文参考手册》](# 《STM32F10X-中文参考手册》)
- [ 《STM32规格书》](# 《STM32规格书》)
- [ 《Cortex™-M3内核编程手册》](# 《Cortex™-M3内核编程手册》)
- [ 《Cortex-M3权威指南》](# 《Cortex-M3权威指南》)
- [ 《stm32f10x_stdperiph_lib_um.chm》](# 《stm32f10x_stdperiph_lib_um.chm》)
标准库下载
通过网盘分享的文件:STM32F10x_StdPeriph_Lib_V3.5.0.zip
链接: https://pan.baidu.com/s/1DTjreRvcZ7-JN_O8mTYVsw?pwd=dq5m
提取码: dq5m
一、CMSIS标准及库层次关系

内核函数层:
其中包含用于访问内核寄存器的名称,地址定义,主要由ARM公司提供。
设备外设访问层:
提供了片上的核外外设的地址和中断定义,主要由芯片生产商提供。
二、STM32F10x_StdPeriph_Lib_V3.5.0库目录、文件夹简介

Libraries:
文件夹下是驱动库的源代码及启动文件,这个非常重要,我们要使用的固件库就在这个文件夹里面。
Project :
文件夹下是用驱动库写的例子和工程模板,其中那些为每个外设写好的例程对我们非常有用, 我们在学习的时候就可以参考这里面的例程,非常全面,简直就是穷尽了外设的所有功能。
Utilities:
包含了基于ST官方实验板的例程,不需要用到,略过即可。
stm32f10x_stdperiph_lib_um.chm:
库帮助文档。
三、Libraries目录
1、CMSIS
Libraries\CMSIS\

内核相关文件
在CoreSupport文件夹中有core_cm3.c和core_cm3.h两个文件。
Core_cm3.h头文件里面实现了内核的寄存器映射,对应外设头文件stm32f10x.h, 区别就是一个针对内核的外设,一个针对片上(内核之外)的外设。
core_cm3.c文件实现了一下操作内核外设寄存器的函数,用的比较少。
core_cm3.h头文件中包含了"stdint.h" 这个头文件,这是一个ANSI C 文件,是独立于处理器之外的, 就像我们熟知的C语言头文件 "stdio.h" 文件一样。
c
//stdint.h文件中的类型定义
/* exact-width signed integer types */
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
typedef signed __int64 int64_t;
/* exact-width unsigned integer types */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
启动文件
启动文件放在startup/arm这个文件夹下面,我们使用的是startup_stm32f10x_hd.s。

Stm32f10x.h
这个头文件实现了片上外设的所有寄存器的映射,是一个非常重要的头文件,在内核中与之想对应的头文件是core_cm3.h。
system_stm32f10x.c
ystem_stm32f10x.c文件实现了STM32的时钟配置,操作的是片上的RCC这个外设。
统在上电之后,首选会执行由汇编编写的启动文件, 启动文件中的复位函数中调用的SystemInit函数就在这个文件里面定义。调用完之后,系统的时钟就被初始化成72M。
2、STM32F10x_StdPeriph_Driver
Libraries\STM32F10x_StdPeriph_Driver

inc(include的缩写)跟src(source的简写)两个文件夹,这里的文件属于CMSIS之外的、 芯片片上外设部分。
在src 和inc 文件夹里的就是ST公司针对每个STM32外设而编写的库函数文件,每个外设对应一个 .c 和 .h 后缀的文件。 我们把这类外设文件统称为:stm32f10x_xxx.c或stm32f10x_xxx.h文件。

misc.c文件,提供了外设对内核中的NVIC(中断向量控制器)的访问函数, 在配置中断时,我们必须把这个文件添加到工程中。
3、 stm32f10x_it.c、 stm32f10x_it.h、 stm32f10x_conf.h和system_stm32f10x.c文件
STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template
建立工程时我们需要这四个文件。
stm32f10x_it.c、 stm32f10x_it.h:
用来编写中断服务函数的,在我们修改前,这个文件已经定义了一些系统异常(特殊中断)的接口, 其它普通中断服务函数由我们自己添加。
system_stm32f10x.c:
这个文件包含了STM32芯片上电后初始化系统时钟、扩展外部存储器用的函数, 例如我们前两章提到供启动文件调用的"SystemInit"函数,用于上电后初始化时钟,该函数的定义就存储在system_stm32f10x.c文件。
stm32f10x_conf.h:
这个文件被包含进stm32f10x.h 文件。
包含该外设的头文件: stm32f10x_xxx.h
c
//stm32f10x_conf.h文件配置软件库
#include "stm32f10x_adc.h"
#include "stm32f10x_bkp.h"
#include "stm32f10x_can.h"
#include "stm32f10x_cec.h"
#include "stm32f10x_crc.h"
#include "stm32f10x_dac.h"
#include "stm32f10x_dbgmcu.h"
#include "stm32f10x_dma.h"
#include "stm32f10x_exti.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_fsmc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_i2c.h"
#include "stm32f10x_iwdg.h"
#include "stm32f10x_pwr.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_rtc.h"
#include "stm32f10x_sdio.h"
#include "stm32f10x_spi.h"
#include "stm32f10x_tim.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_wwdg.h"
#include "misc.h"
还可以配置是否使用"断言"编译选项
c
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ---------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
四、文件间的关系

五、帮助文档
《STM32F10X-中文参考手册》
这个文件全方位介绍了STM32芯片的各种片上外设,它把STM32的时钟、存储器架构、及各种外设、寄存器都描述得清清楚楚。 当我们对STM32的外设感到困惑时,可查阅这个文档。以直接配置寄存器方式开发的话,查阅这个文档寄存器部分的频率会相当高,但这样效率太低了。
《STM32规格书》
本文档相当于STM32的datasheet,包含了STM32芯片所有的引脚功能说明及存储器架构、芯片外设架构说明。 后面我们使用STM32其它外设时,常常需要查找这个手册,了解外设对应到STM32的哪个GPIO引脚。
《Cortex™-M3内核编程手册》
本文档由ST公司提供,主要讲解STM32内核寄存器相关的说明,例如系统定时器、NVIC等核外设的寄存器。 这部分的内容是《STM32F10X-中文参考手册》没涉及到的内核部分的补充。相对来说,本文档虽然介绍了内核寄存器, 但不如以下两个文档详细,要了解内核时,可作为以下两个手册的配合资料使用。
《Cortex-M3权威指南》
这个手册是由ARM公司提供的,它详细讲解了Cortex内核的架构和特性,要深入了解Cortex-M内核,这是首选, 经典中的经典。这个手册也被翻译成中文,出版成书,我们配套的资料里面有提供中文版的电子版。
《stm32f10x_stdperiph_lib_um.chm》
这个就是本章提到的库的帮助文档,在使用库函数时,我们最好通过查阅此文件来了解标准库提供了哪些外设、 函数原型或库函数的调用的方法。也可以直接阅读源码里面的函数的函数说明。