OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 18087|回复: 7

官方例子main函数最后一段代码#ifdef USE_FULLASSERT 。。。。是什么意思?

[复制链接]

5

主题

36

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
369
金钱
369
注册时间
2013-10-15
在线时间
107 小时
发表于 2014-6-13 09:40:07 | 显示全部楼层 |阅读模式
5金钱
[mw_shl_code=c,true]#ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif[/mw_shl_code]
这段代码有什么作用?

 

最佳答案

查看完整内容[请看2#楼]

调试用的。在stm32f10x_conf.h文件中,有如下宏定义 #ifdef  USE_FULL_ASSERT /**   * @brief  The assert_param macro is used for function's parameters check.   * @param  expr: If expr is false, it calls assert_failed function which reports   & ...
非知之难,行之惟难;非行之难,终之斯难
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

38

主题

2061

帖子

6

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
3273
金钱
3273
注册时间
2012-1-16
在线时间
37 小时
发表于 2014-6-13 09:40:08 | 显示全部楼层
调试用的。在stm32f10x_conf.h文件中,有如下宏定义

#ifdef  USE_FULL_ASSERT

/**
  * @brief  The assert_param macro is used for function's parameters check.
  * @param  expr: If expr is false, it calls assert_failed function which reports 
  *         the name of the source file and the source line number of the call 
  *         that failed. If expr is true, it returns no value.
  * @retval None
  */
  #define assert_param(expr) ((expr) ? (void)0: assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
  void assert_failed(uint8_t* file, uint32_t line);
#else
  #define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */

如果你定义了USE_FULL_ASSERT

就可以在assert_failed,加入:
printf("Wrong parameters value: file %s on line %d\r\n", file, line);
就可以使用assert_param(expr) 来判断当前参数是够正确,如果不正确,就会打印出错的文件,以及出错的行。
这样就可以方面调试信息了。
站在巨人的肩膀上不断的前进。。。
回复

使用道具 举报

5

主题

36

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
369
金钱
369
注册时间
2013-10-15
在线时间
107 小时
 楼主| 发表于 2014-6-14 12:24:56 | 显示全部楼层
回复【2楼】xiaoyan:
---------------------------------原来是这样的,谢谢
非知之难,行之惟难;非行之难,终之斯难
回复

使用道具 举报

81

主题

1002

帖子

0

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1876
金钱
1876
注册时间
2014-9-10
在线时间
208 小时
发表于 2014-10-17 10:36:05 | 显示全部楼层
回复【2楼】xiaoyan:
---------------------------------
我找不到在哪里加入printf。
小小蜗牛
回复

使用道具 举报

11

主题

1044

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
3720
金钱
3720
注册时间
2011-5-23
在线时间
2012 小时
发表于 2014-10-17 10:57:06 | 显示全部楼层
回复【4楼】jiutianshenjian:
---------------------------------
在while(1)之前加就好,把文件名和行号打出来即可。
RT-Thread RTOS 音频,WIFI,蓝牙
回复

使用道具 举报

81

主题

1002

帖子

0

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1876
金钱
1876
注册时间
2014-9-10
在线时间
208 小时
发表于 2014-10-17 10:59:31 | 显示全部楼层
回复【5楼】aozima:
---------------------------------
找不到这个函数,我自己在main.c里面写了一个一样的,没反应。
小小蜗牛
回复

使用道具 举报

2

主题

47

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
293
金钱
293
注册时间
2014-11-26
在线时间
29 小时
发表于 2016-5-3 09:59:33 | 显示全部楼层
我都是直接删除了  没用到过。。。
努力让自己独立坚强,这样才能有底气告诉我爱的人,我爱她。
回复

使用道具 举报

0

主题

3

帖子

0

精华

新手入门

积分
19
金钱
19
注册时间
2018-9-28
在线时间
6 小时
发表于 2019-12-10 10:18:57 | 显示全部楼层
很有些,感谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-23 10:12

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表