• 首页
  • 中国
  • stm32 官方例子main函数最后一段代码#ifdef USE_FULLASSERT

stm32 官方例子main函数最后一段代码#ifdef USE_FULLASSERT

2023-11-01 46浏览
百检网是一家专业的第三方检测平台,汇聚众多拥有权威资质的第三方检测机构为你提供一站式的检测服务,做检测就上百检网。百检网让检测从此检测,一份报告全国通用,专业值得信赖。

代码如下:

#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 %drn", file, line) */

/* Infinite loop */

while(1)

{

}

}

#endif

调试用的。在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 %drn", file, line);

就可以使用assert_param(expr) 来判断当前参数是够正确,如果不正确,就会打印出错的文件,以及出错的行。

这样就可以方面调试信息了。

百检网秉承“客户至上,服务为先,精诚合作,以人为本”的经营理念,始终站在用户的角度解决问题,为客户提供“一站购物式”的新奇检测体验,打开网站,像挑选商品一样简单,方便。打破行业信息壁垒,建构消费和检测机构之间高效的沟通平台