【原创】GD32库函数中关于 gd32f10x_conf.h 定义和使用的探究

[复制链接]
2214|14
 楼主| sunmeat 发表于 2015-6-13 09:23 | 显示全部楼层 |阅读模式
在GD32中有这么一个gd32f10x_conf.h文件,他里面默认包含了所有的GD32的外设库文件,如果我们不修改的话,编译就会出现下面的情况
QQ截图20150613092242.png
这样看着很别扭,因为很多外设的头文件是不会用到的。那么我们如何修改他呢?
 楼主| sunmeat 发表于 2015-6-13 09:33 | 显示全部楼层
首先找到gd32f10x_conf.h的定义是在gd32f10x.h中的,定义如下
  1. #ifdef USE_STDPERIPH_DRIVER
  2. #include "gd32f10x_conf.h"
  3. #endif

USE_STDPERIPH_DRIVER的定义,是在MDK的配置中完成的,配置如下
QQ截图20150613093227.png
这样,就通过调用gd32f10x.h的头文件实际调用了gd32f10x_conf.h的头文件
 楼主| sunmeat 发表于 2015-6-13 09:38 | 显示全部楼层
下面继续探究gd32f10x_conf.h的内容,gd32f10x_conf.h的内容如下
  1. #ifndef __GD32F10X_CONF_H
  2. #define __GD32F10X_CONF_H

  3. /* Includes ------------------------------------------------------------------*/
  4. #include "gd32f10x_adc.h"
  5. #include "gd32f10x_bkp.h"
  6. #include "gd32f10x_can.h"
  7. #include "gd32f10x_crc.h"
  8. #include "gd32f10x_dac.h"
  9. #include "gd32f10x_dma.h"
  10. #include "gd32f10x_eth.h"
  11. #include "gd32f10x_exmc.h"
  12. #include "gd32f10x_exti.h"
  13. #include "gd32f10x_fmc.h"
  14. #include "gd32f10x_gpio.h"
  15. #include "gd32f10x_i2c.h"
  16. #include "gd32f10x_iwdg.h"
  17. #include "gd32f10x_mcudbg.h"
  18. #include "gd32f10x_misc.h"
  19. #include "gd32f10x_pwr.h"
  20. #include "gd32f10x_rcc.h"
  21. #include "gd32f10x_rtc.h"
  22. #include "gd32f10x_sdio.h"
  23. #include "gd32f10x_spi.h"
  24. #include "gd32f10x_timer.h"
  25. #include "gd32f10x_usart.h"
  26. #include "gd32f10x_wwdg.h"

  27. #endif /* __GD32F10X_CONF_H */

我们可以通过修改这里面包含的外设的头文件,来达到引用外设库函数的作用,但是在大多数情况下,不是所有的外设都需要引用的,我们可以屏蔽他。然后在需要使用某个外设的时候,再引用之。例如,如要用到外部中断,我们引用下面四个头文件即可,其他的可以屏蔽
  1. #ifndef __GD32F10X_CONF_H
  2. #define __GD32F10X_CONF_H

  3. /* Includes ------------------------------------------------------------------*/
  4. //#include "gd32f10x_adc.h"
  5. //#include "gd32f10x_bkp.h"
  6. //#include "gd32f10x_can.h"
  7. //#include "gd32f10x_crc.h"
  8. //#include "gd32f10x_dac.h"
  9. //#include "gd32f10x_dma.h"
  10. //#include "gd32f10x_eth.h"
  11. //#include "gd32f10x_exmc.h"
  12. #include "gd32f10x_exti.h"
  13. //#include "gd32f10x_fmc.h"
  14. #include "gd32f10x_gpio.h"
  15. //#include "gd32f10x_i2c.h"
  16. //#include "gd32f10x_iwdg.h"
  17. //#include "gd32f10x_mcudbg.h"
  18. #include "gd32f10x_misc.h"
  19. //#include "gd32f10x_pwr.h"
  20. #include "gd32f10x_rcc.h"
  21. //#include "gd32f10x_rtc.h"
  22. //#include "gd32f10x_sdio.h"
  23. //#include "gd32f10x_spi.h"
  24. //#include "gd32f10x_timer.h"
  25. //#include "gd32f10x_usart.h"
  26. //#include "gd32f10x_wwdg.h"

  27. #endif /* __GD32F10X_CONF_H */

 楼主| sunmeat 发表于 2015-6-13 09:43 | 显示全部楼层
当我们需要操作别的外设,需要包含别的外设头文件的时候,在main函数下面可以找到所有包含的头文件,进而找到gd32f10x_conf.h,双击点开修改即可。
QQ截图20150613094223.png
 楼主| sunmeat 发表于 2015-6-13 10:08 | 显示全部楼层
对于大多数人来说,当gd32f10x_conf.h中包含的头文件够多的时候,想要从一堆头文件中找到gd32f10x_conf.h这个头文件,是一件头疼的事情,因此,我们为了修改方便,可以把gd32f10x_conf.h这个头文件像.c文件一样,在主页面显示出来,方便修改,如下所示:
QQ截图20150613100759.png
comeon201208 发表于 2015-6-13 22:37 | 显示全部楼层
sunmeat 发表于 2015-6-13 09:33
首先找到gd32f10x_conf.h的定义是在gd32f10x.h中的,定义如下

USE_STDPERIPH_DRIVER的定义,是在MDK的配置 ...

这个问题的是需要多注意的,不注意的话程序就不会被编译成功额。
comeon201208 发表于 2015-6-13 22:39 | 显示全部楼层
sunmeat 发表于 2015-6-13 09:43
当我们需要操作别的外设,需要包含别的外设头文件的时候,在main函数下面可以找到所有包含的头文件,进而找 ...

这个地方的一定要注意的,设计时用到哪个外设模块的,就相应的再者各头文件中打开相应的模块头文件的。
STM32初学者 发表于 2015-6-14 14:21 | 显示全部楼层
原来USE_STDPERIPH_DRIVERhi干这个用的,我说怎么有时候得加这个宏定义,有时候不用加了
angerbird 发表于 2015-6-15 21:10 | 显示全部楼层
sunmeat 发表于 2015-6-13 09:38
下面继续探究gd32f10x_conf.h的内容,gd32f10x_conf.h的内容如下

我们可以通过修改这里面包含的外设的头文 ...

这个是需要多注意的,不然在变异的时候会出现错误的。
Thefantasy 发表于 2015-6-16 09:12 | 显示全部楼层
楼主讲解的很详细,其实这个和STM32差不多,只不过GD修改了一下名字而已。
baimiaocun2015 发表于 2015-6-17 21:48 | 显示全部楼层
正如下边有些大侠提到的一样,在dg32f10x_conf.h中设置的,不用的直接屏蔽掉的。
 楼主| sunmeat 发表于 2015-6-26 09:42 | 显示全部楼层
STM32初学者 发表于 2015-6-14 14:21
原来USE_STDPERIPH_DRIVERhi干这个用的,我说怎么有时候得加这个宏定义,有时候不用加了 ...

恩恩,这个宏定义延续到了GD32中,依然有用
september7 发表于 2015-6-28 13:20 | 显示全部楼层
楼主,我这个不到这个芯片的型号,怎么办
Thor9 发表于 2015-7-3 21:01 | 显示全部楼层
设计时用到哪个外设模块的,就打开相应的模块头文件的
comeon201208 发表于 2015-7-11 16:47 | 显示全部楼层
这些在应用的时候注意的,需要啥的就调用相应的库函数的就可以啦。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

208

主题

2132

帖子

13

粉丝
快速回复 在线客服 返回列表 返回顶部