利用好断言机制

来源:互联网 发布:vue.js源码 编辑:程序博客网 时间:2024/06/08 07:06

在调试STM32F429+emWin+rt-thread系统时出现的一个问题:

裸机移植emWin运行正常,demo程序什么的都是正常的,然后加入rt-thread系统,出现程序跑飞,使用st-link也无法定位问题,很是郁闷!!


然后手动一步步定位问题位置,发现是配置TFT lcd的FSMC函数问题!将此函数屏蔽后能系统能正常运行,但在裸机时这个函数运行时正常的,没道理加了rt-thread就不行了!!一时间没法定位问题!

        为了排除问题!!特意将emWin等代码去除,仅将配置lcd的代码提取出来,,用以前一个专门移植rt-thread的工程来调试,通过终端打印,发现FSMC参数FMC_NORSRAMInit函数中几个参数配置错误!!通过断言函数打印出来了!修改后这几个参数,后程序运行正常。。。。。。!!

        原因:因为配置lcd时,这几个参数是用不上的,所以忽略没配置!

/* #define USE_FULL_ASSERT    1 */


/* 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 */

之前由于USE_FULL_ASSERT    宏没有打开,使得执行了assert_param(expr) ((void)0)这句,在裸机程序中没出现问题,在加了rt-thread后程序跑飞!!

为啥执行这句程序会跑飞的原因暂时不清楚,期盼大神给解释下!!


经验教训:

    断言是一个很好的调试手段,好好利用对程序开发很有大帮助!!吸取教训!!

原创粉丝点击