linux STM32MP1无法读取M4消息

oxalkeyp  于 2022-11-22  发布在  Linux
关注(0)|答案(1)|浏览(129)

我正在使用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数据=空
有人能帮帮我吗?
谢谢你!
特尔莫

8yoxcaq7

8yoxcaq71#

因此,您的错误为11EAGAIN
从人读取

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.

我相信您会得到一个错误,因为没有准备好读取的数据。
您可以尝试从open调用中删除O_NONBLOCK | O_NDELAY,或者等待数据就绪。

相关问题