Hi,
I have been trying to create a shared structure between the M7 and M4 cores. I have found this post describing a couple of implementations of a tx/rx buffer. I have tried a number of the implementations outlined in the post, however, they did not work, or worked for only one loop.
Here is a number of things I have tried:
- Create a uint8_t flag variable for when the buffer is being written to (same as in the linked post). This didn't cause a crash but ceased execution after a single loop. (i.e it passed the variable back and forth once)
- Use `PlatformMutex' instead of the uint8_t and use .lock and .unlock() - This caused a crash on start up.
- Tried loop instead of thread - did not alter anything.
- Allocated at different SRAM addresses (SRAM3/4) same result as within structs.
- Tried creating the flag variables separate from the struct that is shared between the cores.
I would use the RPC, but it is simply too slow for what I want to do.
M7 code:
#include "mbed.h"
#include "Arduino.h"
using namespace mbed;
using namespace rtos;
Thread txrx;
struct shared_data
{
PlatformMutex flag0;
PlatformMutex flag1;
int M4toM7;
int M7toM4;
};
int localm7m4 = 0;
int localm4m7 = 0;
static struct shared_data * const xfr_ptr = (struct shared_data *)0x30040000;
void setup() {
delay(3000);
LL_RCC_ForceCM4Boot();
Serial.begin(2000000);
txrx.start(callback(txrxThread));
}
void txrxThread() {
//flag1.lock(); or xfr_ptr -> flag1.lock(); ?
Serial.println("Writing M7 to M4");
digitalWrite(LEDR, LOW);
localm7m4 = rand() % 99;
xfr_ptr -> M7toM4 = localm7m4;
//flag1.unlock(); or xfr_ptr -> flag1.unlock(); ?
//flag0.lock(); or xfr_ptr -> flag0.lock();
Serial.println("Reading M4 to M7");
digitalWrite(LEDB, HIGH);
localm4m7 = xfr_ptr -> M4toM7;
//flag0.unlock(); or xfr_ptr -> flag0.unlock(); ?
Serial.println("Loop!");
}
void loop(){
delay(100);
}
M4 code:
// inter-core buffers
#include "mbed.h"
#include "Arduino.h"
using namespace mbed;
using namespace rtos;
struct shared_data
{
PlatformMutex flag0;
PlatformMutex flag1;
int M4toM7;
int M7toM4;
};
int localm7m4 = 0;
int localm4m7 = 0;
// pointer to shared_data struct (inter-core buffers and status)
static struct shared_data * const xfr_ptr = (struct shared_data *)0x30040000;
Thread txrx;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
txrx.start(callback(txrxThread));
}
void txrxThread() {
//xfr_ptr -> flag0.lock();
digitalWrite(LEDB, LOW);
localm4m7 = rand() % 99;
xfr_ptr -> M4toM7 = localm4m7;
//xfr_ptr -> flag0.unlock();
//xfr_ptr -> flag1.lock();
digitalWrite(LEDR, HIGH);
localm7m4 = xfr_ptr -> M7toM4;
//xfr_ptr -> flag1.unlock();
}
void loop()
{
}
Any pointers to what else I can try would be greatly appreciated
Edit: Github issue link: Fastest way to share data between cores (SRAM3/4 usage)? · Issue #145 · arduino/ArduinoCore-mbed · GitHub