Trouble using RPC to pass Arrays or Vectors from M4 to M7

Hey!

Im having some trouble trying to pass an array from the M4 core to the M7 core with RPC.
I've looked at https://forum.arduino.cc/t/passing-variable-from-cm7-to-cm4-using-rpc/692026, but I need to pass arrays or vectors that have a size of 10000> every second.

My goal is that I'm reading an analog signal on the M4, putting that in a bufferarray. Sending it after a second has passed (or array reaches a certain size) to the M7. Receiving it on the M7, copying it to an array on the M7 core and then do calculations on the array.

Any suggestions are appreciated!

Start by posting posting a complete sketch illustrating the problem

#include <Arduino.h>
#include "RPC_internal.h"  // comes with the mbed board installation

// Global variables used by both cores
const long BAUD = 115200;

/*---------------------------M7_CORE---------------------------*/

#ifdef CORE_CM7 

// Set an M7 core global variable

float globArray[18100];

void setArray(float a[]){
  memcpy(a, globArray, sizeof(a));
}

void setup() {
  RPC1.begin();
  LL_RCC_ForceCM4Boot();

  Serial.begin(BAUD);

  RPC1.bind("setArray", setArray);
}

void loop() {
  while (RPC1.available()) {
     Serial.write(RPC1.read()); // check if the M4 has sent an RPC println
  }
  
  /*
  Do something with the globArray
  */
}

#endif

/*---------------------------M4_CORE---------------------------*/

#ifdef CORE_CM4 

// Set an M4 core global variable
float bufferArray[18100];

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;
int count = 0;

void setup() {
  RPC1.begin();
  startMillis = millis();
}

void loop() {

  bufferArray[count] = analogRead(A0);
  count++;

  currentMillis = millis();
  if (currentMillis - startMillis >= period)
  {
    auto res = RPC1.call("setArray", bufferArray); //Sends vector over RPC to the M7 Core
    RPC1.println("From M4 arraysize : " + String(sizeof(bufferArray)));
    memset(bufferArray, 0, sizeof(bufferArray));
    count = 0;
    startMillis = currentMillis;
  }
}

#endif

I've also tried using Vector.h library and std::vector with no real success.

I am not entirely clear what you are trying to do, but when you pass an array to a function what is actually passed is a pointer to the array. So, if in the function you use sizeof() to determine the size of the array what you are actually doing is to find the size of the pointer to the array

void setArray(float a[])
{
  memcpy(a, globArray, sizeof(a));
}

Try printing the value of sizeof(a) in this function. What value do you see printed ?

I might have actually had a little mistake in that function

void setArray(float a[])
{
  memcpy(globArray, a, sizeof(a));
}

I want to copy a to globArray
This doesn't have to be done with arrays, I would prefer vectors, as seen below.
The code below compiles for both cores, but as soon as the M4 code is executed the onboard LEDs blinks red. I suspect it is the stack that is getting overflowed?

Does a vector containing ~20000 floats take up that much space?

#include <Arduino.h>
#include "RPC_internal.h"  // comes with the mbed board installation
#include <vector>

// Global variables used by both cores
const long BAUD = 115200;
int myLED;

/*---------------------------M7_CORE---------------------------*/

#ifdef CORE_CM7 

// Set an M7 core global variable

std::vector<float> globArray(20000);

std::vector<float> setArray(std::vector<float> a){
  globArray = a;
  return a;
}

void setup() {
  RPC1.begin();
  LL_RCC_ForceCM4Boot();
  myLED = LEDB;
  Serial.begin(BAUD);

  RPC1.bind("setArray", setArray);
  pinMode(myLED, OUTPUT);
}

void loop() {
  while (RPC1.available()) {
     digitalWrite(myLED, !digitalRead(myLED)); //Switches LED state
     Serial.write(RPC1.read()); // check if the M4 has sent an RPC println
  }

  delay(200);
  /*
  Do something with the globArray
  */
}

#endif

/*---------------------------M4_CORE---------------------------*/

#ifdef CORE_CM4 

// Set an M4 core global variable
std::vector<float> bufferArray(20000);

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;

void setup() {
  RPC1.begin();
  pinMode(myLED, OUTPUT);
  startMillis = millis();
}

void loop() {

  bufferArray.push_back(analogRead(A0)); //Reads from pin A0 and adds the value to the bufferArray

  currentMillis = millis();
  if (currentMillis - startMillis >= period) // Executes every 1000 ms
  {
    auto res = RPC1.call("setArray", bufferArray); //Sends vector over RPC to the M7 Core
    RPC1.println("From M4 arraysize : " + String(bufferArray.size()));
    bufferArray.clear();
    digitalWrite(myLED, !digitalRead(myLED)); //Switches LED state
    startMillis = currentMillis;
  }
}

#endif

Try this example

float a[100];

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  copyArray(a);
}

void loop()
{
}

void copyArray(float b[])
{
  Serial.print("sizeof(a) ");
  Serial.println(sizeof(a));
  Serial.print("sizeof(b) ");
  Serial.println(sizeof(b));
  memcpy(a, b, sizeof(b));
}

What do expect to be printed ?
What is actually printed ?
How many bytes will be copied into the destination array ?
What values will be in the destination array ?