這個想法是從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!
- 前言
- 【菜鳥入門】stm32的第一個程序--LED
- 【菜鳥入門】stm32 之 掃描按鍵
- 【菜鳥入門】stm32 之 中斷按鍵
- 【菜鳥入門】stm32 之 USART
- 【菜鳥入門】stm32 之 iic
- 【菜鳥入門】stm32 之 eeprom
- 【菜鳥入門】stm32 之 pwm
- 【菜鳥入門】stm32 之 ADC 模數轉換
- 【菜鳥入門】stm32 之 實時時鐘
- 【菜鳥入門】stm32 之 DMA
- 【菜鳥入門】stm32 之 DAC
- 【STM庫應用】stm32 之 USART
- 中斷源去抖辦法
- stm32 啟動代碼應用技巧
- 【STM庫應用】stm32 之 IIC應用
- 【STM庫應用】stm32 之 中斷按鍵初始化(注意事項)
- 關于結構體初始化
- 【STM庫應用】stm32 之 TIM (詳解一 通用定時器)
- 【STM庫應用】stm32 之 TIM (詳解二 脈沖寬度、周期測量)
- 【stm32庫應用】SD驅動移植(基于SDIO外設)
- SD卡fat文件系統移植
- stm32 DMA初始化選項研究
- stm32 靈活靜態存儲控制器(FSMC)(NORFLASH\PSRAM)
- 【stm32+uC/OS-II】ucosii移植簡單詳細步驟
- STM32 加入調試信息來調試代碼
- NRF24L01 無線通信模塊使用