這個想法是從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!