Rpmsg protocol failing with ims_rpmsg_tty on Linux

I am having trouble trying to use the imx_rpmsg_tty driver on Linux to receive data from the M4 core using rpmsg under FreeRTOS. This problem is really strange. My intention is to use the M4 core (running FreeRTOS) to collect some real time data, and send the data to the main core (running Linux) for processing and storage. It wasn’t working, so I simplified my software to the following for testing purposes:

The M4 core is running a simple task under FreeRTOS that sends a fixed 10 byte packet of data to the main core once per second.

The A5 core runs a simple program under Linux to receive incoming rpmsg data from the M4 core, and simply prints out the number of bytes of data in each packet it receives (should always be 10 bytes). The code to receive the data is as follows:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>	// file control
#include <termios.h>	// POSIX terminal control
#include <sched.h>

#define DEVICE "/dev/ttyRPMSG"
int main(void) {
	int fd;
	struct termios tty;
	char buf[100];
	int len;

	printf("Opening device...\n");
	fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);	// read/write, no console, no delay
	if (fd < 0) {
		printf("Error, cannot open device\n");
		return 1;
	}
	tcgetattr(fd, &tty);	// get current attributes
	cfmakeraw(&tty);	// raw input
	tty.c_cc[VMIN] = 0;	// non blocking
	tty.c_cc[VTIME] = 0;	// non blocking
	tcsetattr(fd, TCSANOW, &tty);	// write attributes
	printf("Device is open\n");
	for (;;) {
		len = read(fd, buf, sizeof(buf));
		if (len > 0) {
			printf("%d ", len);
		} else {
			printf(".");	// optional printf statement
			sched_yield();
		}
	}
	return EXIT_SUCCESS;
}    

I boot up my target system, do a “modprobe imx_rpmsg_tty” to load the driver, and run the above program on the Linux side. It reports “Opening device…”, “Device is open”, and starts to output long strings of “.” characters with a "10 " being printed once per second. In other words, it works perfectly.

But (and this is the strange part), if I delete the statement that reads “printf(”.“); // optional printf statement”, the program reports “Opening device…”, “Device is open”, and then I get absolutely NOTHING. This tells me that no data is being received. So I put the optional print statement back, and then I receive the data again.

This is really strange. I can’t seem to receive any data from the ttyRPMSG device unless I am printing something out to the console. I guess that is why I couldn’t receive any real-time data from the M4 core in my “real” application. I was just trying to receive data from ttyRPMSG for processing without sending anything to the console.

Am I doing something wrong here? Why can’t I receive any data from ttyRPMSG if I am not sending anything to the console? I would be happy to share my test code running on the M4 core if that would help.

I solved my problem. The problem was the printf("%d ", len); statement. Since no linefeed was included, the printf statement buffered the data and would not actually output anything until the output buffer was full. After adding a fflush(stdout) statement after the printf, everything started behaving as expected.

Perfect that you problem is solved. Thanks for the feedback.