💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
这个想法是从K60上得出来的;今天再帮一哥们看程序的时候,他可以用串口看出来那个文件那一行文件出现问题了,于是很好奇,就问他,他也不知道,然后我就细心的研究了下他的库;发现一个不错的调试方法,其实这个在stm32里面本身也是设置好了的,但是大家一致都没有去用; 先看stm32f10x_conf.h里面的一些内容: ~~~ /* 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 */ ~~~ 默认情况下是: #define assert_param(expr) ((void)0) 明显,没有什么用,如果我们想调试的时候,可以加一个宏定义: ~~~ #define USE_FULL_ASSERT ~~~ 那么我们就可以用这个判断了; ~~~ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) ~~~ void assert_failed(uint8_t* file, uint32_t line); 不过还没有完,我们需要在再写一个assert_failed的函数,来实现他的功能: ~~~ #ifdef USE_FULL_ASSERT #include "stdio.h" void assert_failed(uint8_t* file, uint32_t line) { char buff[64]; sprintf(buff,"%s %d",file,line); RS232SendStr(buff); while(1); } #endif ~~~ 你还可以在里面加入其他调试信息; this all!