I am using STM32MP157-DK2 board and I am creating a program to communicate with processor. To do this, I have created a VIRTUAL UART (ttyRPMSG0 channel) and I am able to send messages from A7 to M4 and take actions like switching leds.
A7 side:
static void LED_ON (GtkWidget *widget, gpointer data)
{
fd = open("/dev/ttyRPMSG0", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd < 0) {
printf("CA7 : Error opening "/dev/ttyRPMSG0"\n");
}
write(fd, "start", 5);
close(fd);
}
M4 side:
while (1)
{
OPENAMP_check_for_message();
if (VirtUart0RxMsg) {
VirtUart0RxMsg = RESET;
if (!strncmp((char *)VirtUart0ChannelBuffRx,"start",5))
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_14, GPIO_PIN_RESET);
sprintf ((char*)SendMsgVirt0, "LED green ON\n");
}
else if (!strncmp((char *)VirtUart0ChannelBuffRx,"stop",4))
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_14, GPIO_PIN_SET);
sprintf ((char*)SendMsgVirt0, "LED green OFF\n");
}
else if (!strncmp((char *)VirtUart0ChannelBuffRx,"xValue",6))
{
sprintf ((char*)SendMsgVirt0, "X value is: %d\n", x);
}
VIRT_UART_Transmit(&huart0, SendMsgVirt0, SendMsgVirt0Size);
memset(SendMsgVirt0, '\0', sizeof(SendMsgVirt0));
}
}
But when I send a message from M4 to A7, I can't read it in the linux side.
A7 side:
static gboolean update_M4_variable (gpointer user_data)
{
char data [32];
char msg[128];
fd = open("/dev/ttyRPMSG0", O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY);
if (fd < 0) {
g_print("CA7 : Error opening "/dev/ttyRPMSG0"\n");
}
write(fd, "xValue", 6);
int size = read(fd, &data, 32);
if(size < 0)
{
sprintf (msg, "Cannot read the message: %s\n", data);
}
else
{
sprintf (msg, "The message has been received: %s\n", data);
}
gtk_label_set_text(GTK_LABEL(text_status), msg);
close (fd);
return TRUE;
}
With this code, I can see the message that has been sent from M4 in the terminal but what I always get is:
Size = -1 data = empty
Can someone help me?
Thanks!
Telmo
CodePudding user response:
So your error is 11
: EAGAIN
From man read
EAGAIN The file descriptor fd refers to a file other than a socket and has been marked nonblocking (O_NONBLOCK), and the read would block. See open(2) for further details on the O_NONBLOCK flag.
I believe you get an error because no data is ready to read.
You can try to remove O_NONBLOCK | O_NDELAY
from the open
call, or wait for a data to be ready.