Skip to main content

Linux communication (RPMsg)

RPMsg carries messages between Linux and a remote core over shared-memory buffers (VRINGs) and a hardware mailbox interrupt. It defines addressing, not your payload: the two sides agree on an endpoint number and a message format. In TI's terms the R5F endpoint is a server port and the Linux program a client (IPC guide).

Tested

Everything on this page was run on Mo62A image V1.1.0 against the TI ipc_rpmsg_echo_linux firmware on endpoint 14: the copy shipped in the image, and the rebuild from Build and run firmware, which is what the screenshot shows.

How Linux user space reaches the R5F​

LayerOn Mo62A
Kernelrpmsg_char driver creates /dev/rpmsg_ctrlN per core and a /dev/rpmsgN per endpoint you open
LibraryTI ti-rpmsg-char 0.6.9: /opt/ti/edgeai/lib/libti_rpmsg_char.so (headers are not installed)
FirmwareAnnounces rpmsg_chrdev on endpoint 14 and replies on the sender's endpoint

The library finds the right control device for a core, creates a local endpoint, and gives you a file descriptor that you write() to and read() from. Each message is at most 512 bytes in total, including the RPMsg header, so keep payloads at or below 496 bytes.

Device nodes are root-only on the image. Run the programs below with sudo rather than relaxing the permissions on /dev/rpmsg*.

Get the library headers​

The library in the image matches TI tag 0.6.9. Fetch the same source on the board (or copy it from a host) to get ti_rpmsg_char.h, rproc_id.h and the example program:

git clone --branch 0.6.9 --depth 1 https://git.ti.com/git/rpmsg/ti-rpmsg-char.git
cd ti-rpmsg-char

rproc_id.h names the cores. On AM62A the MCU R5F is R5F_MCU0_0 (0) and the C7x is DSP_C71_0 (8).

Exchange messages​

Build TI's example on the board with the preinstalled GCC and run it against the MCU R5F:

gcc -O2 -Iinclude examples/rpmsg_char_simple.c -o rpmsg_char_simple \
-L/opt/ti/edgeai/lib -lti_rpmsg_char -Wl,-rpath,/opt/ti/edgeai/lib -lpthread
sudo ./rpmsg_char_simple -r 0 -n 10
SSH session on Mo62A listing the MCU R5F RPMsg channels, a passing rpmsg_char_simple run and 1000 matched messages from rpmsg_echo_latency
Sending message #9: hello there 9!
Received message #9: round trip delay(usecs) = 35160
hello there 9!

Communicated 10 messages successfully on rpmsg-char-0-3288

TEST STATUS: PASSED

-p selects the remote endpoint (default 14) and -n the message count.

note

The delay printed by rpmsg_char_simple is the difference of the tv_nsec fields only. It is in nanoseconds despite the usecs label, and is wrong whenever the second changes between send and receive. The line above therefore means about 35 µs. Use the program in the next section for measurements.

Measure the round trip​

rpmsg_echo_latency.c sends numbered messages, waits for each reply with a 1 s timeout, checks that the reply matches, and reports the distribution of full CLOCK_MONOTONIC round-trip times. Build it in the ti-rpmsg-char folder:

gcc -O2 -Wall -Iinclude rpmsg_echo_latency.c -o rpmsg_echo_latency \
-L/opt/ti/edgeai/lib -lti_rpmsg_char -Wl,-rpath,/opt/ti/edgeai/lib
sudo ./rpmsg_echo_latency 0 1000 # rproc id, message count [, endpoint]

Result on the test board with Linux otherwise idle:

rproc 0, remote port 14, local port 1025, 1000 messages
round trip us: min 29.2 median 33.5 avg 34.7 p99 59.7 max 124.5
RESULT: PASS 1000/1000 replies matched

Longer runs of 10000 messages, idle and with all four Cortex-A53 cores kept busy by four shell loops (timeout 60 sh -c 'while :; do :; done' &, four times):

Linux loadMessages matchedMedianp99Max
Idle10000/1000037.9 µs100.9 µs1988.4 µs
4 busy loops10000/1000035.1 µs485.6 µs6306.1 µs

This is the time from a Linux write() to the matching read(), including two kernel crossings and Linux scheduling. It is not the R5F's response time: the median hardly changes under load, while the tail grows with Linux scheduling. Ordinary-priority loops already raise the maximum to several milliseconds. Design the protocol so that the R5F never waits on Linux inside a time-critical loop.

A wrong endpoint fails cleanly instead of hanging:

$ sudo ./rpmsg_echo_latency 0 3 99
cannot open rproc 0 port 99

Find which core owns an endpoint​

/dev/rpmsgN numbers are assigned in creation order. Resolve the owner through sysfs instead of assuming a number:

for e in /sys/class/rpmsg/rpmsg[0-9]*; do
printf '%s %s\n' "${e##*/}" "$(readlink -f "$e/device")"
done

A path containing 79000000.r5f belongs to the MCU R5F; 78000000.r5f and 7e000000.dsp belong to the Device Manager and the C7x. The C7x also answers on endpoint 14 (-r 8), but its firmware serves the AI stack; do not use it as a test target while AI applications run.

Designing your own protocol​

  • Fix the endpoint number and announce it from the firmware with RPMessage_announce() after RPMessage_waitForLinuxReady().
  • Put a command ID and a length or version field at the start of every payload; reply on the sender's endpoint with a status.
  • Use a timeout on every Linux read, as rpmsg_echo_latency.c does with poll(), and handle the core being restarted: the endpoint disappears and must be reopened.
  • For data larger than one message, place it in a shared buffer agreed between both sides and send only its offset.

The MCU console applies this to a small text-command protocol on endpoint 15.

Source: inhandnet/mo-docs · 7ba0dc46