Hello,
I am starting to work with Cortex-M4 of the iMX7, sending and receiving RPMsg and I was wondering If I could get any tip on what I am doing wrong, here it is what I am doing:
On Cortex-M4:
Following these articles:
- FreeRTOS on the Cortex-M4 of a Colibri iMX7
- First steps with Heterogeneous Multicore Processing on the NXP® i.MX 7
- Communicating between cores with RPMsg
I was able to get running the str_echo_freertos
example
In Linux side:
I was able to send and recieve message with the following:
root@b2qt-colibri-imx7-emmc:~# modprobe imx_rpmsg_tty
[ 20.817876] imx_rpmsg_tty virtio0.rpmsg-openamp-demo-channel.-1.0: new channel: 0x400 -> 0x0!
[ 20.826821] Install rpmsg tty driver!
root@b2qt-colibri-imx7-emmc:~# stty -F /dev/ttyRPMSG0 -echo && exec 3<> /dev/ttyRPMSG0
root@b2qt-colibri-imx7-emmc:~# echo Test from command line >&3
root@b2qt-colibri-imx7-emmc:~# cat <&3
Test from command line
^C
root@b2qt-colibri-imx7-emmc:~#
And now, I created a simple C program that could send and receive messages, but is not working properly, here it is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#define TTY_RPMSG "/dev/ttyRPMSG0"
int main(int argc, char *argv[])
{
int fd, len;
struct termios tty_settings;
char buf[100] = {0};
if (argv[1] == NULL)
{
printf("error: needs to specify a message to send\n");
return EXIT_FAILURE;
}
printf("Start '%s'\r\n", __TIME__);
fd = open(TTY_RPMSG, O_RDWR | O_NOCTTY | O_SYNC | O_NDELAY);
if(fd < 0)
{
printf("error: port could not be opened '%s'\n", TTY_RPMSG);
return EXIT_FAILURE;
}
/* Get the current attributes of the Serial port */
tcgetattr(fd, &tty_settings);
/* Set raw mode */
cfmakeraw(&tty_settings);
tcsetattr(fd, TCSANOW, &tty_settings);
printf("to write: '%s'\n", argv[1]);
/* Original line that was getting the wrong length of argv[1] */
/* write(fd, argv[1], sizeof(argv[1])); */
/* Getting the correct length with strlen */
write(fd, argv[1], strlen(argv[1]));
tcdrain(fd);
/* Sleep not needed */
/* sleep(1); */
while (1)
{
len = read(fd, buf, sizeof(buf));
if (len > 0)
{
buf[len] = 0;
printf("received:\r\n");
printf(" len = %d\r\n", len);
printf(" buf = %s\r\n\r\n", buf);
fflush(stdout);
}
}
close(fd);
return EXIT_SUCCESS;
}
I compile, run my code and I get this:
root@b2qt-colibri-imx7-emmc:~# modprobe imx_rpmsg_tty
[ 36.076102] imx_rpmsg_tty virtio0.rpmsg-openamp-demo-channel.-1.0: new channel: 0x400 -> 0x0!
[ 36.084932] Install rpmsg tty driver!
root@b2qt-colibri-imx7-emmc:~# ./send_rpmsg_linux_g 1234567890
Start '15:58:05'
to write: '1234567890'
received:
len = 4
buf = 1234
^C
root@b2qt-colibri-imx7-emmc:~#
It looks like the full message was not sent.
From the output of the Cortex-M4 terminal:
RPMSG String Echo FreeRTOS RTOS API Demo...
RPMSG Init as Remote
Name service handshake is done, M4 has setup a rpmsg channel [0 ---> 1024]
Get Message From Master Side : "1234" [len : 4]
Any tip on how to get the full message sent?
Thanks