STM32F0xx的头文件USE_STDPERIPH_DRIVER宏的作用

[复制链接]
 楼主| sunmeat 发表于 2014-8-27 08:35 | 显示全部楼层 |阅读模式
本帖最后由 sunmeat 于 2014-8-27 08:40 编辑

【转载】在网上找到的一篇**,完美的解决我上个帖子的问题
https://bbs.21ic.com/icview-790448-1-1.html
ST公司提供STM32F0xx的头文件STM32F0xx.h,编译器都要定义一个宏:USE_STDPERIPH_DRIVER,如果不定义它 ----  照ST公司的做法,就会出现问题,如

实际上,打开头文件研究一下就知道,关系到这个宏的地方只有两处:
 楼主| sunmeat 发表于 2014-8-27 08:36 | 显示全部楼层
本帖最后由 sunmeat 于 2014-8-27 08:37 编辑

第一处是:
  1. #if !defined USE_STDPERIPH_DRIVER
  2. /**
  3. * [url=home.php?mod=space&uid=247401]@brief[/url] Comment the line below if you will not use the peripherals drivers.
  4. In this case, these drivers will not be included and the application code will
  5. be based on direct access to peripherals registers
  6. */
  7. /*#define USE_STDPERIPH_DRIVER*/
  8. #endif /* USE_STDPERIPH_DRIVER */

 楼主| sunmeat 发表于 2014-8-27 08:37 | 显示全部楼层
第二处是:
  1. 第二处是:

  2. #ifdef USE_STDPERIPH_DRIVER
  3.   #include "stm32f0xx_conf.h"
  4. #endif
 楼主| sunmeat 发表于 2014-8-27 08:38 | 显示全部楼层
大家一看就应该明白,使用这个宏的目的只有一个,就是把头文件stm32f0xx_conf.h包含进来。

而stm32f0xx_conf.h头文件的除了包含所有硬件资源的头文件外,还包含有一个宏定义:
  1. #include "stm32f0xx_adc.h"
  2. #include "stm32f0xx_cec.h"
  3. #include "stm32f0xx_crc.h"
  4. ……


  5. /* Exported macro ------------------------------------------------------------*/
  6. #ifdef  USE_FULL_ASSERT

  7. /**
  8.   * [url=home.php?mod=space&uid=247401]@brief[/url]  The assert_param macro is used for function's parameters check.
  9.   * @param  expr: If expr is false, it calls assert_failed function which reports
  10.   *         the name of the source file and the source line number of the call
  11.   *         that failed. If expr is true, it returns no value.
  12.   * @retval None
  13.   */
  14.   #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
  15. /* Exported functions ------------------------------------------------------- */
  16.   void assert_failed(uint8_t* file, uint32_t line);
  17. #else
  18.   #define assert_param(expr) ((void)0)
  19. #endif /* USE_FULL_ASSERT */
 楼主| sunmeat 发表于 2014-8-27 08:38 | 显示全部楼层
可见,如果知道了它的使用目的,用户完全可以根据自己的喜好,随意更改之。
grace75 发表于 2014-8-31 21:01 | 显示全部楼层
学习了!
haolaishi 发表于 2014-8-31 23:02 | 显示全部楼层
学习了,终于知道这个怎么用了
shuiqinghan2012 发表于 2016-1-24 16:57 | 显示全部楼层
mark,
shuiqinghan2012 发表于 2016-1-24 16:57 | 显示全部楼层
可是如何用 void assert_failed(uint8_t* file, uint32_t line);打印需要的错误信息
sherryqueen 发表于 2017-4-7 10:39 | 显示全部楼层
mark!
铁匠之锤 发表于 2019-7-17 09:39 | 显示全部楼层
学习了,Mark
lvben5d 发表于 2019-7-17 11:09 | 显示全部楼层
GD32也是一样的,所有库要用到,就必须在预编译选项里,加这个宏!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

208

主题

2132

帖子

13

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