Go Down

Topic: PORTENTA-H7, Where could be an example code for RPC and OpenAMP (Read 984 times) previous topic - next topic


PORTENTA-H7, Where could be an example code for RPC and OpenAMP,
to test the dual core communication on


From the standard Arduino IDE, there's an example: "RPC_m4" within the Portenta section. The name is misleading as it's actually written for both cores. Also, as the libraries are written, it will require the "-fexceptions" flag to be set to compile. With regards to the example itself, it produces a somewhat confusing Serial output with the combination of an rtos thread, main loop and delays. Nevertheless the RPC calls produce the desired results...

Additionally, there are some rpc library examples here: C:\Users\YourUser\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.0\libraries\rpclib\examples



I tried this RPC demo but found some issues (e.g. CM4 was not released).

Here is my Scatch (to demonstrate how CM4 could run two threads and use Serial, whereby CM4 sends RPC calls to CM7 to let this core do the UART).

Code: [Select]

#include "Arduino.h"
#include "RPC_internal.h"

//in order to compile this, you had to add -fexceptions in file 'platform.txt' as option !!

#ifdef CORE_CM7
int add(int a, int b) {
  ////printf(" M7: calling add\n");
  //-->this printf does not work on UART !!
  Serial.println(" M7: calling add\n");
  return a + b;
int subtract(int a, int b) {
  printf(" M7: calling subtract\n");
  return a - b;

#ifndef CORE_CM7
//this is just for CM4
rtos::Thread t;

void call_substract() {
  //this is a CM4 RTOS thread
  while (1) {
    RPC1.print(" M4: Calling subtract | ");
    auto res = RPC1.call("sub", 12, 45).as<int>();

void setup() {
  //for both cores using RPC
#ifdef CORE_CM7
  Serial.begin(115200); //never mind: TeraTerm will receive with any baudrate set there
  //while (!Serial) {}
  pinMode(LEDG, OUTPUT); //CM7 configures LED GPIO
  RPC1.bind("add", add);
  RPC1.bind("sub", subtract);
  Serial.println("CM7: release and boot CM4");
  //boot CM4
  //-->it has to be done in order to release CM4 !!

void loop() {
  // put your main code here, to run repeatedly:
#ifndef CORE_CM7
  //this is the CM4 main thread
  digitalWrite(LEDG, HIGH); //CM4 toggles the LED (GPIO)
  digitalWrite(LEDG, LOW);

  RPC1.print(" M4: Calling add | ");
  auto res = RPC1.call("add", 12, 45).as<int>();
  //let CM7 also do something, to see CM7 runs and prints as well
  add(10, 20);

  //CM7 will check for RPC calls and forward to UART
  while (RPC1.available()) {

Attention: you have to add compile option -fexceptions in (hidden) platform.txt file.

Go Up