STM32调试时打开assert_failed
发布日期:2021-06-30 22:01:42
浏览次数:2
分类:技术文章
本文共 1372 字,大约阅读时间需要 4 分钟。
前言
在改一个工程,发现STM32F407工程,将6个串口全打开时,串口2发送数据时,等发送完成标志那死循环了,等不到发送完成的状态位(那个状态位是硬件设置的).
有点怀疑工程中调用库函数时,参数设置错了。
想打开STM32库函数中, 自带的参数检查机制。试验
stm32f4xx_conf.h 有宏 USE_FULL_ASSERT,默认是关闭的
/* Uncomment the line below to expanse the "assert_param" macro in the Standard Peripheral Library drivers code *//* #define USE_FULL_ASSERT 1 */ // 默认是关闭的#define USE_FULL_ASSERT 1 // 打开调试宏 USE_FULL_ASSERT, 使assert_failed生效/* Exported macro ------------------------------------------------------------*/#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 */#endif /* __STM32F4xx_CONF_H */
增加 assert_failed 实现
void assert_failed(uint8_t* file, uint32_t line){ // 这里就为断点能停下,然后返回, 看看,哪里参数设置错了 while (0) { }}
用SWD调试时,用的4线制, 没接SWO. 看不到ITM输出.
只能在assert_failed()内下断点,如果有库函数参数设置的不对,就从assert_failed()返回,看调用处,是什么参数设置的不对。转载地址:https://lostspeed.blog.csdn.net/article/details/101597180 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月22日 04时46分17秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
40.与传输层有关的基本知识
2019-05-01
8.Makefile路径搜索使用案例
2019-05-01
9.Makefile隐含规则
2019-05-01
10.Makefile ifeq、ifneq、ifdef和ifndef
2019-05-01
GDB下载和安装教程
2019-05-01
MySQL 还是 ES
2019-05-01
CentOS已死,Rocky Linux 重生
2019-05-01
Base64到底是个啥编码? 我熬夜把它整明白了
2019-05-01
拜托了,别再说Base64是加密算法了
2019-05-01
牛逼,这个PDF库比其它工具好用99倍
2019-05-01
神器 Jupyter,终于来了!
2019-05-01
火了,Python「抢茅台脚本」开源
2019-05-01
40个 python 奇技淫巧
2019-05-01
1010个Pycharm快捷键
2019-05-01
13条编程习惯
2019-05-01
不用微信QQ,用Pillow裁剪图片
2019-05-01
如何系统的自学python
2019-05-01
用 pyppeteer 制作 PDF文件
2019-05-01
最新电脑版微信可以刷朋友圈啦
2019-05-01
29个chrome灵魂插件!
2019-05-01