你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

stm32f10x.h代码分析【原创】

[复制链接]
designerchs 发布时间:2014-4-1 08:07
   stm32f10x.h 这个头文件是STM32开发最为重要的一个头文件相当于我们入门51那会,那个 reg52.h 。但对于STM32来说,它的寄存器数量是非常多的,如果我们按照操作51一样的方法来操作32的话,查数据手册来配置寄存器是非常麻烦的。所以ST开发了这个库,方便大家开发,缩短开发周期。在 stm32f10x.h 中前面一开始就出现了:
 
#ifndef __STM32F10x_H #define __STM32F10x_H  #ifdef __cplusplus  extern "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 &quotlease select first the target STM32F10x device used in your application (in stm32f10x.h file)" #endif 如果没有定义器件的话,编译的时候就会出现以下错误:
&quotlease 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, you         can 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_TIMEOUT   ((uint16_t)0x0500) /*!< Time out for HSE start up */#define HSI_VALUE    ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/  标准外设库版本号的定义   /** * @brief STM32F10x Standard Peripheral Library version number    */#define __STM32F10X_STDPERIPH_VERSION_MAIN   (0x03) /*!< [31:24] main version */                                  #define __STM32F10X_STDPERIPH_VERSION_SUB1   (0x05) /*!< [23:16] sub1 version */#define __STM32F10X_STDPERIPH_VERSION_SUB2   (0x00) /*!< [15:8]  sub2 version */#define __STM32F10X_STDPERIPH_VERSION_RC     (0x00) /*!< [7:0]  release candidate */ #define __STM32F10X_STDPERIPH_VERSION       ( (__STM32F10X_STDPERIPH_VERSION_MAIN
收藏 评论0 发布时间:2014-4-1 08:07

举报

0个回答

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版