我正在使用STM32 MP 157-DK2板,我正在创建一个与处理器通信的程序。为此,我创建了一个虚拟UART(ttyRPMSG 0通道),我能够从A7向M4发送消息,并采取诸如切换LED等操作。
A7侧:
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侧:
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));
}
}
但是当我从M4向A7发送消息时,我无法在linux端读取它。
A7侧:
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;
}
使用此代码,我可以在终端中看到从M4发送的消息,但我总是得到的是:
大小= -1数据=空
有人能帮帮我吗?
谢谢你!
特尔莫
1条答案
按热度按时间8yoxcaq71#
因此,您的错误为
11
:EAGAIN
从人读取
我相信您会得到一个错误,因为没有准备好读取的数据。
您可以尝试从
open
调用中删除O_NONBLOCK | O_NDELAY
,或者等待数据就绪。