关于STM32 MDK中USE_STDPERIPH_DRIVER问题的解释

本文解决初学者使用STM32固件库在RealViewMDK环境下编译时遇到的警告与错误,介绍如何正确配置预编译宏以启用标准外设驱动。

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

  初学STM32,在RealView MDK 环境中使用STM32固件库建立工程时,初学者可能会遇到编译不通过的问题。出现如下警告或错误提示:

  warning: #223-D: function "assert_param" declared implicitly;assert_param(IS_GPIO_ALL_PERIPH(GPIOx));

  这时候我们需要在“Target Options”中的“C/C++”选项卡中如图-2所示红框中添加USE_STDPERIPH_DRIVER、STM32F10X_HD。这样才能使编顺利通过。

图-2

  知其然了,我们还得知其所以然。下面就听Herison给大家一一道来。我们知道,程序的执行是从“main.c”文件开始的,其中必须包含有头文件“stm32f10x.h”。我们打开“stm32f10x.h”,按下“Ctrl+F”键,查找USE_STDPERIPH_DRIVER,在“Find What”栏中输入“USE_STDPERIPH_DRIVER”。如图-3所示。点击“Find Next”,出现“USE_STDPERIPH_DRIVER”对应的代码行,重复上边操作三次,第三次的时候我们能在第8296-8298行找到如图-4所示代码段。

图-3

图-4

 

  这段代码的意思是,只有用预编译指令预定义了“USE_STDPERIPH_DRIVER”,才会将"stm32f10x_conf.h"包含进“stm32f10x.h”中,从而被"main.c"用到。这就解释了,为什么我们没有在“main.c”中包含"stm32f10x_conf.h",而在编译之后却被包含进了"main.c"中,出现如图-5所示的情况。        "stm32f10x_conf.h"文件相当于一个开关文件,如果要用到STM32固件库驱动标准外设,则外设驱动头文件是必不可少的,如“stm32f10x_gpio.h”。在"stm32f10x_conf.h"中我们通过代码#include "stm32f10x_gpio.h"来实现这个操作。

图-5

  说到这儿估计大家已经对“USE_STDPERIPH_DRIVER”的来龙去脉有个清晰的认识了吧?其实单从字面意思理解就是“使用标准外设驱动”,在C/C++预定义中加入“USE_STDPERIPH_DRIVER”就是允许“使用标准外设驱动”了。至于加入的“STM32F10X_HD“同样能在文件”stm32f10x.h“通过如上所述的方法通过功能查找来进行解释,其实它也是对于对应硬件的某些定义起开关作用罢了。

 

修改错误 #include “sys.h” compiling stm32f10x_spi.c… D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_spi.c(22): error: #5: cannot open source input file “stm32f10x_spi.h”: No such file or directory #include “stm32f10x_spi.h” D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_spi.c: 0 warnings, 1 error compiling stm32f10x_flash.c… D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_flash.c(22): error: #5: cannot open source input file “stm32f10x_flash.h”: No such file or directory #include “stm32f10x_flash.h” D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_flash.c: 0 warnings, 1 error compiling stm32f10x_dma.c… D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dma.c(22): error: #5: cannot open source input file “stm32f10x_dma.h”: No such file or directory #include “stm32f10x_dma.h” D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dma.c: 0 warnings, 1 error compiling stm32f10x_gpio.c… D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_gpio.c(22): error: #5: cannot open source input file “stm32f10x_gpio.h”: No such file or directory #include “stm32f10x_gpio.h” D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_gpio.c: 0 warnings, 1 error compiling misc.c… D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\misc.c(23): error: #5: cannot open source input file “misc.h”: No such file or directory #include “misc.h” D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\misc.c: 0 warnings, 1 error compiling stm32f10x_usart.c… D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_usart.c(22): error: #5: cannot open source input file “stm32f10x_usart.h”: No such file or directory #include “stm32f10x_usart.h” D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_usart.c: 0 warnings, 1 error compiling stm32f10x_adc.c… D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_adc.c(22): error: #5: cannot open source input file “stm32f10x_adc.h”: No such file or directory #include “stm32f10x_adc.h” D:\C52\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_adc.c: 0 warnings, 1 error “.\Objects\000.axf” - 8 Error(s), 0 Warning(s).
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值