STM32调试时打开assert_failed
发布日期:2021-06-30 22:01:42 浏览次数:3 分类:技术文章

本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:分析 : BSOD案例 2013-0821
下一篇:STM32F407串口操作

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月16日 11时38分13秒