Featured image of post 瑞萨RA6M4开发板在RT-Thread中使用segger_rtt软件包

瑞萨RA6M4开发板在RT-Thread中使用segger_rtt软件包

瑞萨RA6M4开发板使用示例<RT-Thread的版本为v4.1.0及以上>

一、创建工程,选择SEGGER_RTT软件包

image-20221003133030692

image-20221003133219108

2、添加jlinkRtt初始化函数[ 路径:/rt-thread/src/kservice.c ]

rt_console_set_device前调用rt_hw_jlink_rtt_init初始化函数

image-20221003133721333

3、控制台对接上jlinkRtt

1
2
3
rtconfg.h

// 修改RT_CONSOLE_DEVICE_NAME为空

image-20221003134935152

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
shell.c [ 路径:D:\rt-thread\components\finsh\shell.c]

/* 1、首先添加以下头文件 */
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"

/* 2、修改finsh_getchar */
int finsh_getchar(void)
{
#ifdef RT_USING_DEVICE
    char ch = 0;
#ifdef RT_USING_POSIX_STDIO
    if(read(STDIN_FILENO, &ch, 1) > 0)
    {
        return ch;
    }
    else
    {
        return -1; /* EOF */
    }
#else
    rt_device_t device;

    RT_ASSERT(shell != RT_NULL);

    device = shell->device;
    if (device == RT_NULL)
    {
        extern char rt_hw_console_getchar(void);
        return rt_hw_console_getchar();
    }

    while (rt_device_read(device, -1, &ch, 1) != 1)
    {
        rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
        if (shell->device != device)
        {
            device = shell->device;
            if (device == RT_NULL)
            {
                return -1;
            }
        }
    }

    return ch;
#endif /* RT_USING_POSIX_STDIO */
#else
    extern char rt_hw_console_getchar(void);
    return rt_hw_console_getchar();
#endif /* RT_USING_DEVICE */
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
kservice.c [ 路径:\rt-thread\src\kservice.c ]
// 另外我们还需要完成对控制台字符读取的对接,修改rt_hw_console_output 

RT_WEAK void rt_hw_console_output(const char *str)
{
    /* empty console output */
    rt_size_t i = 0, size = 0;

    size = rt_strlen(str);
    for (i = 0; i < size; i++)
    {
        if (*(str + i) == '\n')
        {
           break;
        }
    }
    SEGGER_RTT_printf(0,"%s",str);
}
RTM_EXPORT(rt_hw_console_output);

4、实验效果

首先确保已经下载好J-Link RTT Viewer,直接去官网下载最新版本即可

然后编译和下载工程,注意下载方式为J-Link

双击打开rtthread.map[ 路径: /Debug/rtthread.map ]文件,查看_SEGGER_RTT变量地址(全局搜索即可,找到.bss._SEGGER_RTT)

image-20221003140449806

打开J-Link RTT Viewer

image-20221003140736161

此时就可以正常使用segger_rtt了!

image-20221003140911791

Licensed under CC BY-NC-SA 4.0
Last updated on Aug 22, 2022 00:00 UTC
顺颂时祺,秋绥冬禧
Built with Hugo
Theme Stack designed by Jimmy