一、 在工程中添加RTT库,并包含头文件:
二、mian.c中添加如下代码:
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#define PRINTF SEGGER_RTT_printf
#define LOGF(tag, format, ...) \
do { \
PRINTF(0, "Fatal: [" tag "] " format "", ##__VA_ARGS__); \
} while (0)
#define LOGE(tag, format, ...) \
do { \
PRINTF(0, "Error: [" tag "] " format "", ##__VA_ARGS__); \
} while (0)
#define LOGW(tag, format, ...) \
do { \
PRINTF(0, "Warn: [" tag "] " format "", ##__VA_ARGS__); \
} while (0)
#define LOGI(tag, format, ...) \
do { \
PRINTF(0, "Info: [" tag "] " format "", ##__VA_ARGS__); \
} while (0)
#define LOGD(tag, format, ...) \
do { \
PRINTF(0, "Debug: [" tag "] " format "", ##__VA_ARGS__); \
} while (0)
#define LOG(format, ...) \
do { \
PRINTF(0, format, ##__VA_ARGS__); \
} while (0)
三、调用初始化函数
SEGGER_RTT_Init();
四、在需要的位置调用LOG()函数打印
LOG("12345vbdngn\r\n");
五、编译下载程序,打开RTT上位机