STM32中stm32f10x.h解析

来源:互联网 发布:热仿真软件flotherm 编辑:程序博客网 时间:2024/05/28 17:06
新版的固件库V3.0以上 main等源文件中不再直接包含stm32f10x_conf.h,而是stm32f10x.h,stm32f10x.h则定义了启动设置,以及所有寄存器宏定义,此文件中需要注意的有:

1、device选择

#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

  /* #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

此段代码在stm32f10x.h的开始处,根据所用的器件 取消合适的注释。我常用的是stm32f103c8t6  属于Medium density Value Line devices.

2、外部时钟频率选择

#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 */

注意STM32F10X_CL,STM32F10X_CL是stm32f105 和stm32f107 互联型的device,用到此器件外部要选用25MHz的晶体,由于前面的代买没有取消  /* #define STM32F10X_CL */     /*!< STM32F10X_CL: STM32 Connectivity line devices */的注释,所以此处默认的外部8MHz的晶体

3、外设宏定义USE_STDPERIPH_DRIVER

#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

如果不适用片内外设,则不要取消  /*#define USE_STDPERIPH_DRIVER*/的注释

注意stm32f10x.h文件的最后有这样的代码:

#ifdef USE_STDPERIPH_DRIVER

  #include "stm32f10x_conf.h"

#endif

stm32f10x_conf.h中包含了所有外设的头文件,因此任意源文件只要包含了stm32f10x.h,就可以在源文件调用任意外设的函数。

若有外设为使用到,在stm32f10x_conf.h注释相应部分,项目编译时就不会在编译去掉的外设。


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 椎基底动脉供血不足怎么办 颈椎压迫神经脑供血不足怎么办 脑部基底动脉轻度狭窄怎么办 胸壁疼痛我该怎么办 厂房面积小于泄压面积怎么办 江苏海门农村自建房房产证怎么办 颈总动脉斑块形成怎么办 颈椎引起腔梗头晕怎么办 魅族手机变成英文怎么办 员工失去了工作乐趣怎么办 古墓丽影9出bug怎么办 气炉子打不着火怎么办 下面人员不参加公司拓展怎么办 重点班的差生怎么办 江苏考生选修考d怎么办 眼睛里有虫子该怎么办 屋里毛絮特别多怎么办 信用卡人员核核查单位地址怎么办 红米note电源键失灵怎么办 红米note4x跳屏怎么办 红米开机键坏了怎么办 红米note2开关键不灵敏怎么办 大学生论文检测系统忘记密码怎么办 快手实验室没有k歌怎么办 皮肤一到冬天就会起皮脱落怎么办 嘴上的皮撕破了怎么办 身体皮肤干燥起皮怎么办 把公司数据库弄宕机了怎么办 地铁上临时变站怎么办 大学实践课挂了怎么办 军训的人长得矮怎么办 军训脸被晒黑了怎么办 晚上吃了油炸的怎么办 楼梯又陡又窄怎么办 小孩不认真做作业怎么办 水厂出水水质不达标怎么办 野猪铁夹子夹到怎么办 燃气灶开孔尺寸大了怎么办 苹果电脑视频显示缺少插件怎么办 安装拼多多显示校验失败怎么办 中央庭黑盒被抢怎么办