cancel
Showing results for 
Search instead for 
Did you mean: 

How read data from rpmsg-sdb device with A7 of STM32MP157A-DK1?

ASega.1
Associate III

Hi,

I'm using STM32MP157A-DK1 and I built the image adding the logicanalyser layer (https://github.com/STMicroelectronics/meta-st-stm32mpu-app-logicanalyser).

I follow the tutorial "How to exchange data buffers with the coprocessor".

I add the rpmsg_hdr code to send message from the M4 to the DDR memory.

The message is "Hello\r\n".

I would like to see this message with A7.

In the folder /dev there is the device rpmsg-sdb.

For the code I follow the section "rpmsg_sdb driver" of https://wiki.st.com/stm32mpu/wiki/How_to_exchange_data_buffers_with_the_coprocessor#cite_note-sdb-driver-2

I have no problem to open the file descritpor but when I use the command mmap occurs an error that I get with strerror(errno): "Invalid Argument".

This is the code:

void *buff0_id;
int fd;
size_t size;
 
int main(void)
{
	printf("Hello OpenSTLinux World!\n");
 
	size = 7;
 
	fd = open("/dev/rpmsg-sdb", O_RDWR);
	if(fd < 0)
	{
		printf("Error descriptor\n");
		printf("%s\n", strerror(errno));
	}
 
	buff0_id = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
	if(buff0_id == MAP_FAILED)
	{
		printf("Error map\n");
		printf("%s\n", strerror(errno));
	}
 
	close(fd);
}

What I get on terminal is:

Hello OpenSTLinux World!

Error map

Invalid Argument

I don't understand why it returns me this error.

Is it correct the way to communicate with the DDR memory?

Is there some code example used to manage the memory for the A7?

Thanks in advance.

Best Regards,

Andrea Segalla

1 ACCEPTED SOLUTION

Accepted Solutions

Dear Andrea,

You're welcome.

Happy to heard all is ok now for implementation of your example of data exchange between A7 and M4.

I note from this discussion that we have to update the wiki page to highlight that a call of the IOCTL RPMSG_SDB_IOCTL_SET_EFD is needed before the mmap, otherwise error is seen.

Source code example for the logicanalyser app is not enough.

Thank you

BR

Jean-Philippe

View solution in original post

7 REPLIES 7
JeanPhilippeR
ST Employee

Dear @ASega.1​ 

Could you please check for any error message in the dmesg?

If you have a look at the code example meta-st-stm32mpu-app-logicanalyser\recipes-graphics\st-software\logic-analyser-backend\backend.c, you will see that that there is a call of the IOCTL RPMSG_SDB_IOCTL_SET_EFD before the mmap, and because calling this ioctl allow to create an entry in the buffer list on the driver side.

Thank you

BR

Jean-Philippe

ASega.1
Associate III

Dear @JeanPhilippeR​ ,

Thank you for the reply.

I check the error message using dmesg and the following is what I get:

[20322.518497] misc rpmsg-sdb: No existing buffer entry exist in the list !!!

I made some changes using the IOCTL that you suggest me:

void *buff0_id;
int fd;
size_t size;
// ADD FROM HERE ------------------------------------------ 
typedef struct
{
	int bufferId, eventfd;
} rpmsg_sdb_ioctl_set_efd;
 
rpmsg_sdb_ioctl_set_efd q_set_efd;
 
#define RPMSG_SDB_IOCTL_SET_EFD _IOW('R', 0x00, struct rpmsg_sdb_ioctl_set_efd *)
// TO HERE ------------------------------------------
 
int main(void)
{
	printf("Hello OpenSTLinux World!\n");
 
	size = 7;
 
	fd = open("/dev/rpmsg-sdb", O_RDWR);
	if(fd < 0)
	{
		printf("Error descriptor\n");
		printf("%s\n", strerror(errno));
	}
 	//ADD IOCTL
	ioctl(fd, RPMSG_SDB_IOCTL_SET_EFD, &q_set_efd);
 
	buff0_id = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
	if(buff0_id == MAP_FAILED)
	{
		printf("Error map\n");
		printf("%s\n", strerror(errno));
	}
 
	printf("Closing fd\n");
	close(fd);
}

The result on terminal is:

Hello OpenSTLinux World!

Closing fd

But occurs the following error:

[20807.461212] rpmsg_sdb(ERROR): Extract of buffer id failed(-22)

Is it correct the way I used IOCTL or I have to add something?

I find only this link https://wiki.st.com/stm32mpu/wiki/How_to_exchange_data_buffers_with_the_coprocessor#cite_note-sdb-driver-2 as documentation for the communication between M4 and A7 with rpmsg-sdb.

Do you know others, by chance?

Thanks in advance,

Andrea

Dear Andrea,

You point the right and unique documentation.

Regarding the latest error you mention, is there a firmware running on the M4 side?

If you look at the stm32_rpmsg_sdb driver, you will see that it occurs in callback function which is called by the M4 activity.

Thank you

BR

Jean-Philippe

ASega.1
Associate III

Dear Jean,

The code running in the M4 is the following: https://github.com/STMicroelectronics/logicanalyser.

But I made some changes.

In the main while I comment the call to the state machine and I add the transmission of the message "Hello\r\n".

RPMSG_HDR_StatusTypeDef status;
 
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    //LAStateMachine();
	OPENAMP_check_for_message();
	if (VirtUart0RxMsg)
	{
		status = RPMSG_HDR_Transmit(&hsdb0, (uint8_t*)"Hello\n\r",(uint16_t) 7);
	}
	HAL_Delay(1000);
  }

I notice from your driver and also in the last part of section "Dynamic view" of the documentation that the template required is in the following format:

BxLyyyyyyyy

and so instead of send "Hello\n\r" I try with "B1L000000001" and no error occurs.

But now I'm not able to understand how send data from M4 to the shared memory and get these data from A7 side.

Thanks in advance,

Andrea

Dear Andrea

For data exchange between A7 and M4, some buffers are allocated on memory for sharing data.

M4 will write in them, then A7 will read.

if you look at the Dynamic view paragraph How to exchange data buffers with the coprocessor - stm32mpu you will see that when the buffer are created, information of buffer ID and size are given to the M4 via a string like B<id>AxxxxxxxxLxxxxxxxx, where "Axxxxxxxx" is the address of the buffer to write data from M4, and Lxxxxxxxx the associated lenght.

As soon as M4 has written some data on a buffer <id>, it will call a callback with string B<id>L<lenght> to notified the A7 side that some data are present, which could be read of lenght <lenght>.

Hope it help.

Thank you

BR

Jean-Philippe

ASega.1
Associate III

Dear Jean,

Thank you so much for your explanation.

It is very useful and I understand well what happens between A7, driver and M4.

I changed my code and now it works and I can see the "hello" message.

Thank you so much for your time and for the helping.

Best Wishes,

Andrea

Dear Andrea,

You're welcome.

Happy to heard all is ok now for implementation of your example of data exchange between A7 and M4.

I note from this discussion that we have to update the wiki page to highlight that a call of the IOCTL RPMSG_SDB_IOCTL_SET_EFD is needed before the mmap, otherwise error is seen.

Source code example for the logicanalyser app is not enough.

Thank you

BR

Jean-Philippe