cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Data from M4 to A7 using OpenAMP without A7 Initiation – Need Help!

VedantK33
Associate II

Greetings everyone,

I’m currently working on inter-core communication between the Cortex-M4 and Cortex-A7 cores using OpenAMP and RPMsg. My goal is to send dummy sensor data from the M4 to the A7 periodically. I am using STM32MP157F-DK2.

However, I’ve noticed an issue:

  • The data from the M4 only gets flushed to the A7 after the A7 writes something first on the virtual channel.

  • In other words, the M4 seems to need some kind of trigger from the A7 before its messages are actually delivered.

What I want to achieve is:
Send data from the M4 to the A7 automatically, without any prior message or intimation from the A7.

Has anyone faced a similar situation or knows how to configure OpenAMP/RPMsg so the M4 can push data independently? Any guidance or code example would be highly appreciated.

I am attaching my main.c below.

int main(void)
{



  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */
  srand(HAL_GetTick());

  MX_IPCC_Init();
  /* OpenAmp initialisation ---------------------------------*/
  MX_OPENAMP_Init(RPMSG_REMOTE, NULL);
  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  /* USER CODE BEGIN 2 */
	/* ##-1- Create Virtual UART device
	 * defined by a rpmsg channel attached to the remote device
	 */
	huart0.rvdev = &rvdev;
	print_string("Virtual UART0 OpenAMP-rpmsg channel creation\r\n");
	if (VIRT_UART_Init(&huart0) != VIRT_UART_OK) {
		print_string("VIRT_UART_Init UART0 failed.\r\n");
		while (1) {
		}
	}


	huart1.rvdev = &rvdev;
	print_string("Virtual UART1 OpenAMP-rpmsg channel creation\r\n");
	if (VIRT_UART_Init(&huart1) != VIRT_UART_OK) {
		print_string("VIRT_UART_Init UART1 failed.\r\n");
		while (1) {
		}
	}
	/*Need to register callback for message reception by channels*/
	if (VIRT_UART_RegisterCallback(&huart0, VIRT_UART_RXCPLT_CB_ID,
			VIRT_UART0_RxCpltCallback) != VIRT_UART_OK) {
		while (1) {
		}
	}
	if (VIRT_UART_RegisterCallback(&huart1, VIRT_UART_RXCPLT_CB_ID,
			VIRT_UART1_RxCpltCallback) != VIRT_UART_OK) {
		while (1) {
		}
	}

    while (1) {
        OPENAMP_check_for_message();  // Handle any messages from A7

        // Generate dummy GPS and IMU values
        float latitude  = 12.9000f + ((float)(rand() % 1000) / 10000.0f);
        float longitude = 77.6000f + ((float)(rand() % 1000) / 10000.0f);
        float imu_angle = (float)(rand() % 360);

        char msg[128];

        // Send GPS
        snprintf(msg, sizeof(msg), "GPS:%.5f,%.5f\r\n", latitude, longitude);
        print_string(msg);
        HAL_GPIO_TogglePin(GPIOH, GPIO_PIN_7);

        // Send IMU
        snprintf(msg, sizeof(msg), "IMU:%.2f\r\n", imu_angle);
        print_string(msg);
        HAL_GPIO_TogglePin(GPIOH, GPIO_PIN_7);

        HAL_Delay(500); // 1Hz update rate
    }


	  /* USER CODE END 3 */
  }

void print_string(const char *s)
{
  int l;
    l = strlen(s);
	VIRT_UART_Transmit(&huart0, (uint8_t*) s, l);
}

void VIRT_UART0_RxCpltCallback(VIRT_UART_HandleTypeDef *huart)
{

   	print_string("Msg received on VIRTUAL UART0 channel \n\r");

    /* copy received msg in a variable to sent it back to master processor in main infinite loop*/
    VirtUart0ChannelRxSize = huart->RxXferSize < 100? huart->RxXferSize : 99;
    memcpy(VirtUart0ChannelBuffRx, huart->pRxBuffPtr, VirtUart0ChannelRxSize);
    VirtUart0RxMsg = SET;
}

void VIRT_UART1_RxCpltCallback(VIRT_UART_HandleTypeDef *huart)
{

	print_string("Msg received on VIRTUAL UART1 channel \n\r");
    /* copy received msg in a variable to sent it back to master processor in main infinite loop*/
    VirtUart1ChannelRxSize = huart->RxXferSize < 100? huart->RxXferSize : 99;
    memcpy(VirtUart1ChannelBuffRx, huart->pRxBuffPtr, VirtUart1ChannelRxSize);
    VirtUart1RxMsg = SET;
}

Thank you in advance!

0 REPLIES 0