调试的时候,通过IDE查看状态是最常用的手段,但如果不断地把运行过程信息通过串口输出来,也会是一种好办法。所以创建新项目后,可以先将调试信息输出功能写好,再慢慢做写其他代码,正所谓工欲善其事必先利其器嘛。
功能的实现非常简单,就是通过串口的TX把信息print出来,使用DMA传输可以降低MCU负担,为了简化,甚至把初始化也放在print函数中,在需要输出的地方直接调用DrvDebugInfoPrint(),例如在LED任务里调用:DrvDebugInfoPrint(“LED Start to flash!”);
头文件:
/* DrvUartTool, V1.0, 2018-7-4, Yangwb ****************************************/
/* Use USART1_TX:PA9, DMA2_Stream7, DMA_Channel_4 *****************************/
/*
set USE_DEBUG_INFO_AT_UART = 1 to use this module; 0 to disable, then the
function DrvDebugInfoPrint() define as null.
module need'n init, DrvDebugInfoPrint() auto call init function.
Example: when LED task start, DrvDebugInfoPrint("LED start to flash!").
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DrvDebug_H
#define __DrvDebug_H
/* Private functional switch -------------------------------------------------*/
#define USE_DEBUG_INFO_AT_UART 1
#if USE_DEBUG_INFO_AT_UART == 1
/* Private define ------------------------------------------------------------*/
#define DEBUG_INFO_UART_BAUDRATE 115200
#define DEBUG_INFO_UART_BUFF_SIZE 50
#define DEBUG_INFO_UART_TX_STATUS_NOT_INIT 0
#define DEBUG_INFO_UART_TX_STATUS_READY 12
#define DEBUG_INFO_UART_TX_STATUS_BUSY 123
/* Includes ------------------------------------------------------------------*/
#include "Common.h"
#include "stm32f4xx.h"
#include <stdio.h>
#include <string.h>
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
extern volatile INT8U g_u8DebugTxDmaStatus;
extern volatile INT8U g_au8DebugTxDmaBuff[DEBUG_INFO_UART_BUFF_SIZE];
#endif // end of USE_DEBUG_INFO_AT_UART
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --
通过STM32F407的串口输出运行状态信息
最新推荐文章于 2024-05-02 23:55:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)