在uVision中新建STM32工程后,需要从STM32标准库中拷贝标准外设驱动到自己的工程目录中,此时需要在工程设置->C/C++选项卡下的Define文本框中键入这两个全局宏定义。
STM32F40_41xxx,USE_STDPERIPH_DRIVER
USE_STDPERIPH_DRIVER
这个说明你在使用标准外设驱动,有自己的外设配置文件,即stm32f10x_conf.h,详细可查看stm32f4xx.h中12026-12017行。关于stm32f4xx_conf.h
文件中的内容,是有选择的#inlude 'stm32f4xx_conf.h',这样只编译需要的外设文件,减少hex文件的体积。如果没有使用这个宏,或没有stm32f10x_conf.h文件,那么编译时会有一大堆莫名奇妙地错误,这是因为MDK中也自带了stm32f40x_xxxx.h文件,使得编译器使用MDK中.h文件,而.c文件和.h文件版本是不匹配的。
注意,如果是库文件的错误,那一定是你工程配置有问题。
Use Standard Peripheral Driver
在Keil MDK环境中使用STM32固件库建立工程时,可能会遇到编译不通过的问题。出现如下警告或错误提示:
warning:#223-D:function'assert_param'declaredimplicitly;assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
这时候我们需要在设置面板的“TargetOptions”中“C/C++”选项卡添加STM32F40_41xxx,USE_STDPERIPH_DRIVER。这样才能使编顺利通过。
知其然了,我们还得知其所以然。下面就一一道来。我们知道,程序的执行是从main.c文件开始的,其中必须包含有头文件stm32f4xx.h。打开stm32f4xx.h,查找USE_STDPERIPH_DRIVER,在第12026-12017行找到
#ifdef USE_STDPERIPH_DRIVER #include 'stm32f4xx_conf.h'
相关文章









