微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > stm32f10x.h文件分析理解

stm32f10x.h文件分析理解

时间:11-10 来源:互联网 点击:
 今天再看过半年前自己写的这篇发现自己当时理解有误,stm32f10x.h与库开发并未存在太大关系,只是一个最为重要的寄存器地址到寄存器结构体变量的映射。

stm32f10x.h 这个头文件是STM32开发最为重要的一个头文件相当于我玩51那会,那个 reg52.h 。但对于STM32来说,它的寄存器数量是非常多的,如果按照操作51一样的方法来操作32的话,查数据手册来配置寄存器是非常麻烦的。所以ST开发了这个库,方便大家开发,缩短开发周期。在stm32f10x.h 中前面一开始就出现了:

#ifndef __STM32F10x_H#define __STM32F10x_H#ifdef __cplusplusextern "C" {#endif

一开始我不解 extern "C" { 这个语句的意思,经度娘,了解到原来是用来说明后面的定义都是使用C语言写的。这个__cplusplus 是指C++来的,4、5句的意思就是说如果用C++编译器的话,它里面是定义有__cplusplus 这个的,而通过extern "C" { 告知编译器,这段代码是用C编写的,要按照C语言编译。这是因为C++里面有函数重载,编译的时候把参数也编译了,而C的话,编译只编译函数名。

go on:下面这段是用来定义器件容量,可以通过自己取消注释来选择,也可以在KEIL里面设置全局宏定义,2种方式。

#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL) /* #define STM32F10X_LD */     /*!< STM32F10X_LD: STM32 Low density devices *//* #define STM32F10X_LD_VL */  /*!< STM32F10X_LD_VL: STM32 Low density Value Line devices */  /* #define STM32F10X_MD */     /*!< STM32F10X_MD: STM32 Medium density devices *//* #define STM32F10X_MD_VL */  /*!< STM32F10X_MD_VL: STM32 Medium density Value Line devices */  /* #define STM32F10X_HD */     /*!< STM32F10X_HD: STM32 High density devices *//* #define STM32F10X_HD_VL */  /*!< STM32F10X_HD_VL: STM32 High density value line devices */  /* #define STM32F10X_XL */     /*!< STM32F10X_XL: STM32 XL-density devices *//* #define STM32F10X_CL */     /*!< STM32F10X_CL: STM32 Connectivity line devices */#endif#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL)#error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)"#endif

如果没有定义器件的话,编译的时候就会出现以下错误:

"Please select first the target STM32F10x device used in your application (in stm32f10x.h file)"

go on:

用于定义是否使用外设驱动,如果注释掉或者keil中没设全局宏定义的话,则代表不使用ST库提供的外设驱动库,在本文倒数第二段代码中有句

#ifdef USE_STDPERIPH_DRIVER

 #include "stm32f10x_conf.h"

#endif

stm32f10x_conf.h用于外设注释配置。

#if !defined  USE_STDPERIPH_DRIVER/*** @brief Comment the line below if you will not use the peripherals drivers.In this case, these drivers will not be included and the application code will be based on direct access to peripherals registers *//*#define USE_STDPERIPH_DRIVER*/#endif

下面应该是对于器件HSE的设置

/*** @brief In the following line adjust the value of External High Speed oscillator (HSE)used in your application Tip: To avoid modifying this file each time you need to use different HSE, youcan define the HSE value in your toolchain compiler preprocessor.*/           #if !defined  HSE_VALUE#ifdef STM32F10X_CL   #define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */#else #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */#endif /* STM32F10X_CL */#endif /* HSE_VALUE */

设置启动超时值和HSI

/*** @brief In the following line adjust the External High Speed oscillator (HSE) Startup Timeout value */#define HSE_STARTUP_T

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top