外观
AMP 出厂示例
2025-10-29
本文将详细介绍如何通过使用 RPMSG ( Remote Processor Messaging ), 在 Linux 与 RT-Thread 操作系统之间进行多核异构核间通信。目的是帮助用户掌握 RPMSG 模块的使用流程。
RPMSG
RPMSG( Remote Processor Messaging )是一种基于共享内存的进程间通信(IPC) 机制,它允许在非对称多处理( AMP ) 系统中的不同处理器核心之间进行通信。 这些核心通常运行着完全独立的操作系统(例如,一个核心运行 Linux,另一个运行实时操作系统如 RT-Thread 或裸机程序
硬件连接
AMP 下 rtt 终端串口为 uart9

核心示例代码
AMP 示例相关 API
rt_device_open(rpmsg, RT_DEVICE_OFLAG_OPEN);:以可读可写的方式打开 rpmsg 设备;rt_device_control(rpmsg, RT_DEVICE_CTRL_CONFIG, &rpmsg_remote_echo):设置 rpmsg 的源目的地址rt_thread_create("rpmsg_echo", rpmsg_echo_thread, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);:创建 rpmsg_echo 线程rt_thread_startup(thread):启动 rpmsg_echo 线程
- 初始化和操作 rpmsg
applications/rpmsg_echo.c
int rpmsg_echo()
{
uint32_t ret = RT_EOK;
rpmsg = rt_device_find("rpmsg");
if (rpmsg == RT_NULL)
{
rt_kprintf("Unable to find rpmsg device.\r\n");
return RT_ERROR;
}
rt_device_open(rpmsg, RT_DEVICE_OFLAG_OPEN); // 打开 rpmsg 设备
rt_device_control(rpmsg, RT_DEVICE_CTRL_CONFIG, &rpmsg_remote_echo); // 设置 rpmsg 源目的地址
static rt_thread_t thread = RT_NULL;
// 创建 rpmsg_echo 线程
thread = rt_thread_create("rpmsg_echo",
rpmsg_echo_thread, RT_NULL,
THREAD_STACK_SIZE,
THREAD_PRIORITY, THREAD_TIMESLICE);
if (thread != RT_NULL)
rt_thread_startup(thread); // 启动 rpmsg_echo 线程
if (ret != RT_EOK)
{
return RT_ERROR;
}
rt_kprintf("rpmsg echo init end.\r\n");
return RT_EOK;
}- 创建 rpmsg 线程
rpmsg_echo.c
struct rt_rpmsg_ep_addr rpmsg_remote_echo = {
"rpmsg_chrdev", 0x3000U, 0x1000
};
static void rpmsg_echo_thread(void *parameter)
{
rt_uint32_t len = 0;
rt_uint8_t buff[BUF_SIZE];
// 读取 linux 侧发来的 rpmsg 消息
while ((len = rt_device_read(rpmsg, rpmsg_remote_echo.src, buff, BUF_SIZE - 1)) >= 0)
{
buff[len] = 0;
rt_kprintf("message:%s len:%d\r\n", buff, len);
// 给 rtt 侧发送相同的消息
rt_device_write(rpmsg, rpmsg_remote_echo.dst, buff, len);
}
}运行示例
操作步骤
RT-Thread 和 Linux 建立
rpmsg通道上电启动后,RT-Thread 和 Linux 建立
rpmsg通道,才能做后续的发送消息,在 RT-Thread 侧串口的终端输入rpmsg_echo命令,然后能在 Linux 侧串口输入dmesg | grep rpmsg看到如下打印, 代表已经建立好rpmsg通道RT-Thread 串口终端msh />rpmsg_echo [D/drv.rpmsg] rpmsg_chrdev is OK! src is 0x3000 dst is 0x1000 rpmsg echo init end. msh />Linux 串口终端dmesg | grep rpmsg rtt_reserved (0x0000000003f00000--0x000000000bf00000) overlaps with rpmsg@7a00000 (0x0000000007a00000--0x0000000007b00000) amp-shmem@7b00000 (0x0000000007b00000--0x0000000007c00000) overlaps with rpmsg-dma@7b00000 (0x0000000007b00000--0x0000000007c00000) [ 2.256773] OF: reserved mem: initialized node rpmsg-dma@7b00000, compatible id shared-dma-pool [ 4.316256] rockchip-rpmsg 7a00000.rpmsg: rockchip rpmsg platform probe. [ 4.316333] rockchip-rpmsg 7a00000.rpmsg: assigned reserved memory node rpmsg-dma@7b00000 [ 4.316341] rockchip-rpmsg 7a00000.rpmsg: rpdev vdev0: vring0 0x7a00000, vring1 0x7a08000 [ 4.316942] virtio_rpmsg_bus virtio0: rpmsg host is online [ 35.335601] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev addr 0x3000Linux 和 RT-Thread 之间互发消息
在 Linux 侧串口的终端输入
rpmsg_echo命令,RT-Thread 侧看到的发送和接收消息日志Linux 串口终端root@ido:~# rpmsg_echo Sending message #0: hello there 0!, len: 14 Receiving message #0: hello there 0!, len: 14 Sending message #1: hello there 1!, len: 14 Receiving message #1: hello there 1!, len: 14 Sending message #2: hello there 2!, len: 14 Receiving message #2: hello there 2!, len: 14 Sending message #3: hello there 3!, len: 14 Receiving message #3: hello there 3!, len: 14 Sending message #4: hello there 4!, len: 14 Receiving message #4: hello there 4!, len: 14 Sending message #5: hello there 5!, len: 14 Receiving message #5: hello there 5!, len: 14 Sending message #6: hello there 6!, len: 14 Receiving message #6: hello there 6!, len: 14 Sending message #7: hello there 7!, len: 14 Receiving message #7: hello there 7!, len: 14 Sending message #8: hello there 8!, len: 14 Receiving message #8: hello there 8!, len: 14 Sending message #9: hello there 9!, len: 14 Receiving message #9: hello there 9!, len: 14RT-Thread 串口终端message:hello there 0! len:14 message:hello there 1! len:14 message:hello there 2! len:14 message:hello there 3! len:14 message:hello there 4! len:14 message:hello there 5! len:14 message:hello there 6! len:14 message:hello there 7! len:14 message:hello there 8! len:14 message:hello there 9! len:14
