您的位置 首页 5G

STM32库函数装备

stm32固件库V3.0以上的版本,main等源文件中不再直接包含stm32f10x_conf.h,而是stm32f10x.h,stm32f10x.h则定义了启动设置,以及所有寄存…

stm32固件库V3.0以上的版别,main等源文件中不再直接包括stm32f10x_conf.h,而是stm32f10x.h,stm32f10x.h则界说了发动设置,以及一切寄存器宏界说,此文件中需求留意的有:

运用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 code will

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 code will

be based on direct access to peripherals registers

*/

#define USE_STDPERIPH_DRIVER

#endif

5.最终一步是敞开需求运用的外设(装备函数:stm32f10x_config.h,详细装备过程如下:)

/* Includes ——————————————————————*/

/* Uncomment the line below to enable peripheral header file inclusion */

/* #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_fsmc.h” */

/*#include “stm32f10x_gpio.h” */

/* #include “stm32f10x_i2c.h” */

/* #include “stm32f10x_iwdg.h” */

/* #include “stm32f10x_pwr.h” */

/*#include “stm32f10x_rcc.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 (add-on to CMSIS functions) */

默许是封闭一切外设的,用户需求运用哪个外设,就将该外设前面的注释去掉即可。

到这儿库函数的装备就悉数介绍结束了,建一个工程需求修正这么多装备是不是太费事了呢,的确是比较费事,最终再给我们介绍一种简略的装备办法,用宏界说装备这些参数,keil MDk支撑在编译器中增加宏界说,这儿就以keil MDK为例,给我们介绍。

先在keil MDK中点击tagart option选项,弹出如下图所示窗口:

然后点击C/C++选项,弹出如下窗口:

最终在Difine的方框中增加上需求声明的宏界说即可。

这儿总结一下一般工程中需求增加的宏界说:

1.STM32F10X_HD//挑选用户所运用芯片的存储器容量(这儿挑选的是大容量存储)

2.USE_STDPERIPH_DRIVER//翻开规范外设总开关

3.SYSCLK_FREQ_72MHz//挑选时钟频率(默许也是该选项)

4.HSE_VALUE//挑选运用外部高速时钟(默许也是该选项)

留意:stm32f10x.h文件的最终有这样的代码:

#ifdef USE_STDPERIPH_DRIVER

#include “stm32f10x_conf.h”

#endif

stm32f10x_conf.h中包括了一切外设的头文件,因而恣意源文件只需包括了stm32f10x.h,就能够在源文件调用恣意外设的函数。

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

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/5g/254903.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部