stm32编程相关文件了解

User下的文件:

stm32f10x.h:这个文件类似于51的reg51.h,但功能更多一些,具体内容看文件开头的注释,如下

 /* @brief   CMSIS Cortex-M3 Device Peripheral Access Layer Header File. 
  *          This file contains all the peripheral register's definitions, bits 
  *          definitions and memory mapping for STM32F10x Connectivity line, 
  *          High density, High density value line, Medium density, 
  *          Medium density Value line, Low density, Low density Value line 
  *          and XL-density devices.
  *
  *          The file is the unique include file that the application programmer
  *          is using in the C source code, usually in main.c. This file contains:
  *           - Configuration section that allows to select:
  *              - The device used in the target application
  *              - To use or not the peripheral’s drivers in application code(i.e. 
  *                code will be based on direct access to peripheral’s registers 
  *                rather than drivers API), this option is controlled by 
  *                "#define USE_STDPERIPH_DRIVER"
  *              - To change few application-specific parameters such as the HSE 
  *                crystal frequency
  *           - Data structures and the address mapping for all peripherals
  *           - Peripheral's registers declarations and bits definition
  *           - Macros to access peripheral’s registers hardware
  */

简单来说,此为外设接口层头文件,包括了各个型号的单片机寄存器定义和位定义及内存映射,通过宏定义可以进行一些配置,具体如下

通过宏定义选择符合自己单片机的存储空间版本

#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

所以前面定义了STM32F10X_HD

当然除啦在工具链里设置,也可以直接修改这个文件,如下

/* Uncomment the line below according to the target STM32 device used in your
   application 
  */

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

通过宏定义选择正确的外部晶振频率,注意这并不是可以随便改的,连的是8M或25M就要选择相应的

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

通过宏定义设置晶振启动等待时间

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

晶振起振后到输出稳定信号之间的等待时间就是在这里设置

后面是各个型号中断号的定义、库函数用到的结构体的定义,寄存器地址的定义,位定义

最后,如果定义了USE_STDPERIPH_DRIVER

#ifdef USE_STDPERIPH_DRIVER
  #include "stm32f10x_conf.h"
#endif

需要include上述头文件

stm32f10_conf.h:将所有库函数的头文件include进来,以及定义了个检查参数的宏定义

stm32f10x_it.c:这是一个中断处理文件,_it结尾,就是interrupt(中断)的意思,说明这个是整个工程的中断处理函数,要是没有用到中断的话就可以不添加进去,还有,也可以去掉,将中断函数添加到其它.c文件里也行

StartUp文件夹里的其余文件:

core_cm3.h:这个文件写了stm32内核相关的定义及声明,这里顺便补充下一些基本的概念:单片机个人理解是将本来计算机的基本组成部分进行简化然后全都集成在一块芯片上,众所周知,计算机分为五个部分:运算器,存储器,控制器,输入设备,输出设备,如果单片机IO口看作输入输出设备,那么单片机就具备了这五个部分,而运算器的架构应该就是常说的内核

core_cm3.c:这个文件提供了一些汇编级函数实现,例如提供了中断屏蔽的汇编实现,因为你没使用这些函数所以删除它不会影响编译,例如你要做软复位函数时,你就会使用中断屏蔽在那个时候你删除它就会编译失败。

猜你喜欢

转载自www.cnblogs.com/otaganyuki/p/10310979.html