assert_failed 全局搜索
在hal_config.h看到:
【config就是可裁剪-全部放置宏开关】
#ifdef USE_FULL_ASSERT
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((char *)__FILE__, __LINE__))
void assert_failed(char *file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif
也就是 若定义了USE_FULL_ASSERT 会比较expr的值 是1就OK 是0就调函数! 若没有定义 就空空如也 也不必写函数
在main.c
void assert_failed(char *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
范例就是打印
这就是一个小例子
而hal_config.h #define USE_FULL_ASSERT 1U 默认没有打开!
可以对比 打开前后的文件大小!