与非网论坛

标题: GD32固件库中对gd32f1x0_conf.h的修改优化 [打印本页]

作者: sky-Hawk where     时间: 2015-7-21 10:26
标题: GD32固件库中对gd32f1x0_conf.h的修改优化
gd32固件库里这个文件把所有的外围设备驱动全部包含进来,原代码如下:
  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 */
复制代码
如果把这个文件include文件里,那么就会把所有的外设驱动引入到项目里,有的同学通过注释掉不用的模块来使用,这样每次都要修改这个文件很是不科学。我对这个文件进行修改如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    gd32f1x0_conf.h
  4.   * @author  MCU SD
  5.   * @version V1.0
  6.   * @date    6-Sep-2014
  7.   * @brief   Library configuration file.
  8.   ******************************************************************************
  9.   */

  10. /* Define to prevent recursive inclusion -------------------------------------*/
  11. #ifndef __GD32F1X0_CONF_H
  12. #define __GD32F1X0_CONF_H


  13. /* Run Time Environment will set specific #define for each selected module below */
  14. #include "RTE_Components.h"

  15. #ifdef RTE_DEVICE_STDPERIPH_ADC
  16. #include "gd32f1x0_adc.h"
  17. #endif
  18. #ifdef RTE_DEVICE_STDPERIPH_CMP
  19. #include "gd32f1x0_cmp.h"
  20. #endif
  21. #ifdef RTE_DEVICE_STDPERIPH_SYSCFG
  22. #include "gd32f1x0_syscfg.h"
  23. #endif
  24. #ifdef RTE_DEVICE_STDPERIPH_CEC
  25. #include "gd32f1x0_cec.h"
  26. #endif
  27. #ifdef RTE_DEVICE_STDPERIPH_CRC
  28. #include "gd32f1x0_crc.h"
  29. #endif
  30. #ifdef RTE_DEVICE_STDPERIPH_DAC
  31. #include "gd32f1x0_dac.h"
  32. #endif
  33. #ifdef RTE_DEVICE_STDPERIPH_MCUDBG
  34. #include "gd32f1x0_mcudbg.h"
  35. #endif
  36. #ifdef RTE_DEVICE_STDPERIPH_DMA
  37. #include "gd32f1x0_dma.h"
  38. #endif
  39. #ifdef RTE_DEVICE_STDPERIPH_EXTI
  40. #include "gd32f1x0_exti.h"
  41. #endif
  42. #ifdef RTE_DEVICE_STDPERIPH_TSI
  43. #include "gd32f1x0_tsi.h"
  44. #endif
  45. #ifdef RTE_DEVICE_STDPERIPH_FMC
  46. #include "gd32f1x0_fmc.h"
  47. #endif
  48. #ifdef RTE_DEVICE_STDPERIPH_GPIO
  49. #include "gd32f1x0_gpio.h"
  50. #endif
  51. #ifdef RTE_DEVICE_STDPERIPH_I2C
  52. #include "gd32f1x0_i2c.h"
  53. #endif
  54. #ifdef RTE_DEVICE_STDPERIPH_IWDG
  55. #include "gd32f1x0_iwdg.h"
  56. #endif
  57. #ifdef RTE_DEVICE_STDPERIPH_PWR
  58. #include "gd32f1x0_pwr.h"
  59. #endif
  60. #ifdef RTE_DEVICE_STDPERIPH_RCC
  61. #include "gd32f1x0_rcc.h"
  62. #endif
  63. #ifdef RTE_DEVICE_STDPERIPH_RTC
  64. #include "gd32f1x0_rtc.h"
  65. #endif
  66. #ifdef RTE_DEVICE_STDPERIPH_SDIO
  67. #include "gd32f1x0_sdio.h"
  68. #endif
  69. #ifdef RTE_DEVICE_STDPERIPH_SPI
  70. #include "gd32f1x0_spi.h"
  71. #endif
  72. #ifdef RTE_DEVICE_STDPERIPH_TIM
  73. #include "gd32f1x0_timer.h"
  74. #endif
  75. #ifdef RTE_DEVICE_STDPERIPH_USART
  76. #include "gd32f1x0_usart.h"
  77. #endif
  78. #ifdef RTE_DEVICE_STDPERIPH_WWDG
  79. #include "gd32f1x0_wwdg.h"
  80. #endif
  81. #ifdef RTE_DEVICE_STDPERIPH_FRAMEWORK
  82. #include "gd32f1x0_misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
  83. #endif


  84. #endif /* __GD32F1X0_CONF_H */

  85. /******************* (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
复制代码
如果需要使用USART,那么就定义一个RTE_DEVICE_STDPERIPH_USART就可以了。
但是这样还是不太方便,那么就使用Keil.GD32F1xx_DFP.1.0.4 开发包,让软件来帮我们做这件事吧,只需要在Run-Time Environment选择相应的外设,其它的交给Keil去做吧。如图所示:
(, 下载次数: 16)
不再需要去注释不用的include,不再需要定义宏。






欢迎光临 与非网论坛 (https://www.eefocus.com/forum/) Powered by Discuz! X3.5