STM32库函数配置
使用V3.0以上版本固件库的方法如下:
1.选择device(配置函数STM32F10x.h,具体配置方法如下)
在STM32F10x.h中有如下代码:
#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
该代码的是让用户根据自己所使用的芯片的存储器(flash)大小,选择相应的flash编程算法,如果用户使用的是大容量存储芯片(如STM32F103VCT6),则只需要将对应大大容量存储器前面的屏蔽符去掉即可,去掉后为:
#define STM32F10X_HD/*!< STM32F10X_HD: STM32 High density devices */
其它部分代码不变。
如果使用的是中等容量的存储器芯片(如stm32f103c8t6),同样是将对应代码前面的屏蔽符去掉即可,如:
#define STM32F10X_MD/*!< STM32F10X_MD: STM32 Medium density devices */
2.时钟频率配置(配置函数:system_stm32f10x.c,具体配置方法如下:)
#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
/* #define SYSCLK_FREQ_HSEHSE_VALUE */
#define SYSCLK_FREQ_24MHz24000000
#else
/* #define SYSCLK_FREQ_HSEHSE_VALUE */
/* #define SYSCLK_FREQ_24MHz24000000 */
/* #define SYSCLK_FREQ_36MHz36000000 */
/* #define SYSCLK_FREQ_48MHz48000000 */
/* #define SYSCLK_FREQ_56MHz56000000 */
#define SYSCLK_FREQ_72MHz72000000
#endif
由上述代码可见默认是使用72MHz的时钟频率,如果需要使用其它频率,只需做相应的修改即可,如果使用的是72MHz时钟频率可以不用配置此项。
3.选择外部时钟(配置函数stm32f10x.h,具体配置方法如下:)
#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是stm32f105和stm32f107互联型的device,用到此器件外部要选用25MHz的晶体,由于前面的代买没有取消/* #define STM32F10X_CL */ /*!< STM32F10X_CL: STM32 Connectivity line devices */的注释,所以此处默认的外部8MHz的晶体。
4.开启外设总开关USE_STDPERIPH_DRIVER(配置函数:stm32f10x.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 co
be based on direct access to peripherals registers
*/
/*#define USE_STDPERIPH_DRIVER*/
#endif
默认情况下STM32的标准是关闭的,如果不适用片内外设,则不要取消/*#define USE_STDPERIPH_DRIVER*/的注释
,如果需要使用STM32的标准外设则需要开启固件外设,即去掉前面的屏蔽符,修改后如下:
#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 co
be based on direct access to peripherals registers
*/
#define USE_STDPERIPH_DRIVER
#endif
5.最后一步是开启需要使用的外设(配
STM32库函数配 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)