很荣幸收到瑞萨的RA2E1超低功耗开发板,现在开始写第一篇相关的试用报告,看到别人已经用RA2E1的串口实现了printf打印功能,我就不重复了,下面我就使用Jlink自带的RTT来实现printf打印功能,这个打印比串口打印更快更高新,不占用程序资源,可以放在中断服务函数中打印log日子而不影响性能。
*附件:RTT_printf.zip
下面开始讲干货,进入主题
1。打开rasc.exe程序

我给工程取名为RTT_printf

点击next

按照我上面的选项进行配置即可,48pin,点击next


点击finish,完成

我们先关闭rasc.exe。在文件家里打开keil工程

选择MCU型号

选择AC6编译器

选择jlink 下载器

模式一定要选SW,不能选JTAG,否则无法识别

最后的配置

然后先把keil工程编译一遍

没有错误

将Jlink的RTT文件夹复制到KEIL项目文件夹里面

我的是经过封装了一下宏操作的

在keil里面添加源文件c

在添加头文件目录

如下图

最后一步在hal_entry.c包含RTT.h文件

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "SEGGER_RTT.h"
#define BIT_SHIFT_8 (8u)
#define SIZE_64 (64u)
#define LVL_ERR (1u) /* error conditions */
#define RESET_VALUE (0x00)
#define SEGGER_INDEX (0)
#define print(fn_, ...) SEGGER_RTT_printf(SEGGER_INDEX,(fn_), ## VA_ARGS );
#define printf(fn_, ...) SEGGER_RTT_printf(SEGGER_INDEX,(fn_), ## VA_ARGS );
#define LOG(format, args...) SEGGER_RTT_printf(SEGGER_INDEX, "[%s:%d] "format, FILE , LINE , ##args)
#define APP_ERR_PRINT(fn_, ...) if(LVL_ERR)
SEGGER_RTT_printf (SEGGER_INDEX, "[ERR] In Function: %s(), %s", FUNCTION ,(fn_),## VA_ARGS );
#define APP_ERR_TRAP(err) if(err) {
SEGGER_RTT_printf(SEGGER_INDEX, "\r\nReturned Error Code: 0x%x \r\n", err);
__asm("BKPT #0\n");} /* trap upon the error */
#define APP_READ(read_data) SEGGER_RTT_Read(SEGGER_INDEX, read_data, sizeof(read_data));
#define APP_CHECK_DATA SEGGER_RTT_HasKey()
#endif /* COMMON_UTILS_H_ */

打开
这个是Jlink RTT的上位机

下面的信息表示连接上了,但是内容是空的,是因为我还没有烧录程序。接下来,我们直接用jlink烧录到板子上。
看看我的程序

如果正确,会打印出上面3条日志

烧录完成

结果正确,至此已经完成了Jlink的printf打印功能。
这个比MCU的硬件串口耗时低,可以直接放入中断不影响性能。us级别,硬件串口轻则几百毫秒,重则计秒绝对不能放入中断,这是Jlink RTT的优势之处。
以下是我的代码压缩包,使用KEIL可以打开编译
*附件:RTT_printf.zip