stm32f10x_conf.h 与 stm32f10x.h(转载)

本文详细介绍了STM32固件库V3.0以上版本的配置方法,包括如何选择设备类型、设定外部时钟频率及启用标准外设驱动等内容。对于STM32初学者和开发者来说,正确配置这些参数至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

摘自:http://blog.chinaunix.net/uid-24671805-id-3168404.html

新版的固件库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注释相应部分,项目编译时就不会在编译去掉的外设。


 

转载:http://hi.baidu.com/ancient2008/blog/item/ea0ea30d4aa59cd53bc7638c.html

 

### STM32F10x_conf.h 文件详解 #### 配置文件的作用 `stm32f10x_conf.h` 是用于配置外设驱动的关键文件之一。该文件允许开发者通过调整包含的头文件来选择固件库支持的具体外设模块[^1]。 #### 示例代码结构 下面展示了一个典型的 `stm32f10x_conf.h` 的简化版本: ```c #ifndef __STM32F10X_CONF_H #define __STM32F10X_CONF_H /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" /* Uncomment the line corresponding to the selected assert parameter */ //#define USE_FULL_ASSERT 1 /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @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) #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ /* Uncomment or comment out lines below based on required peripheral support */ #define USE_STDPERIPH_DRIVER // #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_gpio.h" // #include "stm32f10x_i2c.h" // #include "stm32f10x_iwdg.h" // #include "stm32f10x_pwr.h" // #include "stm32f10x_rcc.h" // #include "stm32f10x_rng.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" /* High level functions for NVIC and SysTick configuration */ #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif /* __STM32F10X_CONF_H */ ``` 此段代码展示了如何定义外部高速振荡器 (`HSE`) 值以及哪些外设应该被编译到项目中。未注释掉的部分表示默认启用的功能;如果不需要某些特定功能,则可以将其对应行前加上 `//` 来禁用它们。 #### 使用注意事项 为了确保最佳性能并减少不必要的内存占用,建议仅保留当前应用所需的最少数量的外设头文件。这不仅有助于优化资源利用效率,还能使代码更加简洁易读[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值