You are on page 1of 20

By Informa Markets

STM32MP1 Primer
DAY 3 : STM32MP1 Interprocessor Communications

Sponsored by
Sponsored By

Webinar Logistics

• Turn on your system sound to hear the streaming presentation.


• If you have technical problems, click “Help” or submit a question
asking for assistance.
• Participate in ‘Attendee Chat’ by maximizing the chat widget in your
dock.

2
Sponsored By

Fred Eady
Visit ‘Lecturer Profile’ in your console for more details.

3
STM32MP1 Primer

Sponsored By

AGENDA
 IPCC Parts and Pieces
 Coding an STM32MP157D IPCC Project
 Coding an STM32MP157F IPCC Project

4
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Sponsored By

IPCC Parts and Pieces

5
STM32MP1 Primer
STM32MP1 Interprocessor Communications
IPCC Parts and Pieces Sponsored By

IPCC (Inter-Processor Communication Controller)


Device Tree Entry

&m4_rproc{
/*Restriction: "memory-region" property is not managed - please to use User-Section
if needed*/
mboxes = <&ipcc 0>, <&ipcc 1>, <&ipcc 2>;
mbox-names = "vq0", "vq1", "shutdown";
status = "okay";

/* USER CODE BEGIN m4_rproc */


memory-region = <&retram>, <&mcuram>, <&mcuram2>, <&vdev0vring0>,
<&vdev0vring1>, <&vdev0buffer>, <&mcu_rsc_table>;
interrupt-parent = <&exti>;
interrupts = <68 1>;
wakeup-source;
/* USER CODE END m4_rproc */
};

&ipcc{
status = "okay";

/* USER CODE BEGIN ipcc */


/* USER CODE END ipcc */
};

6
STM32MP1 Primer
STM32MP1 Interprocessor Communications
IPCC Parts and Pieces Sponsored By

OPENAMP Buffers and Vrings

MCUSRAM
RX and TX Vrings

Buffers

Device Tree Entry

vdev0vring0:vdev0vring0@10040000{
compatible = "shared-dma-pool";
reg = <0x10040000 0x1000>;
no-map;
};

vdev0vring1:vdev0vring1@10041000{
compatible = "shared-dma-pool";
reg = <0x10041000 0x1000>;
no-map;
};

vdev0buffer:vdev0buffer@10042000{
compatible = "shared-dma-pool";
reg = <0x10042000 0x4000>;
no-map;
};

7
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157D IPCC Project Sponsored By

HandleTypeDefs – Variables – Function Prototypes

//****************************************************************
//* STM32MP157D IPCC
//* VERSION 1.00 A
//* COMPILED USING OpenSTLinux
//* WRITTEN BY FRED EADY
//* LAST UPDATED 01/31/2022
//* CHANGES/ADDITIONS
//****************************************************************
#include "main.h"
#include "openamp.h"
#include "virt_uart.h"
#include "gpio.h"

VIRT_UART_HandleTypeDef huart0;
IPCC_HandleTypeDef hipcc;

#define MAX_BUFFER_SIZE RPMSG_BUFFER_SIZE

__IO FlagStatus VirtUart0RxMsgStatus = RESET;


uint8_t VirtUart0ChannelRxBuf[MAX_BUFFER_SIZE];
uint16_t VirtUart0ChannelRxMsgSize = 0;

// Private function prototypes -----------------------------------


void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_IPCC_Init(void);
int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb);
void VIRT_UART0_RxCpltCallback(VIRT_UART_HandleTypeDef *huart);
void LED_Init(void); 8
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157D IPCC Project Sponsored By

HAL/IPCC/OPENAMP/Virtual UART/Callback Initialization


//*********************************************************************
//* MAIN FUNCTION
//*********************************************************************
int main(void)
{
uint32_t counter = 0;
HAL_Init();

if(IS_ENGINEERING_BOOT_MODE())
{
/* Configure the system clock */
SystemClock_Config();
}

if(IS_ENGINEERING_BOOT_MODE())
{
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
}
else
{
__HAL_RCC_HSEM_CLK_ENABLE();
MX_IPCC_Init();
MX_OPENAMP_Init(RPMSG_REMOTE, NULL);
}
MX_GPIO_Init();
if (VIRT_UART_Init(&huart0) != VIRT_UART_OK)
{
Error_Handler();
}
//we need to register the callback for message reception by channels
if(VIRT_UART_RegisterCallback(&huart0, VIRT_UART_RXCPLT_CB_ID, VIRT_UART0_RxCpltCallback) != VIRT_UART_OK)
{
Error_Handler();
} 9
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157D IPCC Project Sponsored By

Operational Code

//* OPENAMP_check_For_message(); is called


//* if data is available, RxCplt callback is invoked
//* callback stores incoming data into VirtUart0ChannelRxBuf array
//* callback sets VirtUart0RxMsgStatus
//* if VirtUart0RxMsgStatus is SET, we check the data and switch accordingly
while (1)
{
OPENAMP_check_for_message();

if (VirtUart0RxMsgStatus)
{
VirtUart0RxMsgStatus = RESET;
switch(VirtUart0ChannelRxBuf[0])
{
case 0x31:
HAL_GPIO_WritePin(LED7_ORG_GPIO_PORT,LED7_ORG_PIN,SET);
break;
case 0x30:
HAL_GPIO_WritePin(LED7_ORG_GPIO_PORT,LED7_ORG_PIN,RESET);
break;
}
}

if(counter++ == 500000)
{
HAL_GPIO_TogglePin(LED5_GRN_GPIO_PORT,LED5_GRN_PIN);
counter = 0;
}
}
10
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157D IPCC Project Sponsored By

Receive Complete Callback

void VIRT_UART0_RxCpltCallback(VIRT_UART_HandleTypeDef *huart)


{
// copy received msg in a variable to send it back to master processor in main infinite loop
VirtUart0ChannelRxMsgSize = huart->RxXferSize < MAX_BUFFER_SIZE? huart->RxXferSize : MAX_BUFFER_SIZE-1;
memcpy(VirtUart0ChannelRxBuf, huart->pRxBuffPtr, VirtUart0ChannelRxMsgSize);
VirtUart0RxMsgStatus = SET;
}

11
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157D IPCC Project Sponsored By

Manual Control of LED7_ORG Using /dev/ttyRPMSG0

12
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157F IPCC Project Sponsored By

Open /dev/ttyRPMSG0 for Nonblocking Reading and Writing

//********************************************************
//* OPEN /dev/ttyRPMSG0
//********************************************************
void init(void)
{
sprintf(filename,"/dev/ttyRPMSG0");
fd_ipcc = open(filename,O_RDWR | O_NOCTTY | O_NONBLOCK);
if(fd_ipcc < 0)
{
puts("open /dev/ttyRPMSG0 failed\r\n");
exit(1);
}
else
{
puts("/dev/ttyRPMSG0 opened\r\n");
}
}

13
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157F IPCC Project Sponsored By

“Borrow” Some of the Accel 6 Project’s GTK Code


//****************************************************************************
//* GLOBAL GTK WIDGETS
//****************************************************************************
GtkWidget*windowAccel;
GtkWidget*gridAccelFixed1;
GtkWidget*lblAccelPitch;
GtkWidget*lblAccelRoll;
GtkWidget*lblAccelTemp;
GtkWidget*timer;
GtkBuilder*builder;

gboolean ipccTimer_handler(GtkWidget *);


//****************************************************************************
//* MAIN
//****************************************************************************
int main(int argc, char *argv[])
{
init();

gtk_init(&argc, &argv); // init Gtk


//****************************************************************************
//* REFERENCE XML CODE ASSOCIATED WITH WIDGETS
//****************************************************************************
builder = gtk_builder_new_from_file ("accelglade.glade");

windowAccel = GTK_WIDGET(gtk_builder_get_object(builder, "windowAccel"));

g_signal_connect(windowAccel, "destroy", G_CALLBACK(gtk_main_quit), NULL);

gtk_builder_connect_signals(builder, NULL);

gridAccelFixed1 = GTK_WIDGET(gtk_builder_get_object(builder, "gridAccelFixed1"));


lblAccelPitch = GTK_WIDGET(gtk_builder_get_object(builder, "lblAccelPitch"));
lblAccelRoll = GTK_WIDGET(gtk_builder_get_object(builder, "lblAccelRoll"));
lblAccelTemp = GTK_WIDGET(gtk_builder_get_object(builder, "lblAccelTemp"));
timer = GTK_WIDGET(gtk_builder_get_object(builder, "timer"));

gtk_widget_show(windowAccel);

g_timeout_add_seconds(1,(GSourceFunc)ipccTimer_handler, timer);

gtk_main();
return EXIT_SUCCESS; 14
}
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157F IPCC Project Sponsored By

“Borrow” Some of the Accel 6 Project’s GTK Code

gboolean ipccTimer_handler(GtkWidget *timer)


{
//read and display data coming from M4
bytesRead = read(fd_ipcc,rxBuf,1);
if(bytesRead == -1)
{
puts("fd_ipcc read failed");
}
//check if data was received from M4
if(bytesRead>0)
{
sprintf(lblmsg,"Byte from M4 = 0x%02X",rxBuf[0]);
gtk_label_set_text(GTK_LABEL(lblAccelPitch),lblmsg);
}
//send message to M4 toggle orange LED
if(txBuf[0] == 0x30)
{
txBuf[0] = 0x31;
}
else
{
txBuf[0] = 0x30;
}
write(fd_ipcc,txBuf,1);
//return true to keep the timer handler alive
return TRUE;
}

15
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157F IPCC Project Sponsored By

“Borrow” Some STM32MP157D IPCC Project Code


//* OPENAMP_check_For_message(); is called
//* if data is available, RxCplt callback is invoked
//* callback stores incoming data into VirtUart0ChannelRxBuf array
//* callback sets VirtUart0RxMsgStatus
//* if VirtUart0RxMsgStatus is SET, we check the data and switch accordingly
while (1)
{
OPENAMP_check_for_message();

if (VirtUart0RxMsgStatus)
{
VirtUart0RxMsgStatus = RESET;
switch(VirtUart0ChannelRxBuf[0])
{
case 0x31:
HAL_GPIO_WritePin(LED7_ORG_GPIO_PORT,LED7_ORG_PIN,SET);
break;
case 0x30:
HAL_GPIO_WritePin(LED7_ORG_GPIO_PORT,LED7_ORG_PIN,RESET);
break;
}

//send data to A7
if(scratch8++ == 0x39)
{
scratch8 = 0x30;
}
txBuf[0] = scratch8;
VIRT_UART_Transmit(&huart0,txBuf,1);
}
} 16
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157F IPCC Project Sponsored By

Kick Off the Cortex-M4 and Cortex-A7 Applications

17
STM32MP1 Primer
STM32MP1 Interprocessor Communications
Coding an STM32MP157F IPCC Project Sponsored By

Run the Cortex-M4 and Cortex-A7 Applications

18
Sponsored By

MORE TO COME…
Thank you for attending!!!

Please consider the resources below:


• Today’s Project Download Package
• Linux GTK Glade Tutorials
• STM32MP1 Wiki

To get today’s Project Download Package please send an email request to: therealfredeady@gmail.com
19
Thank You

Sponsored by

You might also like