RPC Pass variables and RPC.print

PORTENTA-H7, Where could be an example code for RPC and OpenAMP - Portenta / Portenta H7 - Arduino Forum

As per the post above, I modified the RPC1 --> RPC, and changed ther header to RPC.h (to allow compilation. The code is below:

#include "Arduino.h"
#include "RPC.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;
}
#endif

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

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

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

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)
  delay(1000);
  digitalWrite(LEDG, LOW);
  delay(1000);

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

  //CM7 will check for RPC calls and forward to UART
  while (RPC.available()) {
    Serial.write(RPC.read());
  }
#endif
}

There does not seem to be any variable or data passing between the two cores - all IO get as an output is:


 M7: calling add

 M7: calling add

 M7: calling add

 M7: calling add

 M7: calling add

I tried all the examples in the RPC section, as well as modifications of my own, and it is the same issue - not variables are passing. Any idea what I may be doing wrong?

Never mind - dumb mistake.

I did not realize that bother the M7 and M4 cores need to be separately compiled and uploaded, even when all present in a single sketch.

That does make the upload process more than twice as long.

In any case, attaching to the M4 core in the Board selction in the IDE, and recompiling - it then worked OK