Can the Portenta H7 M4 and M7 cores share variables?

I know (well I think) that both the M4 and M7 cores have access to the same memory locations, but can they share high level variables like Strings and Int etc? I assume not but thought I would ask.

If it can be done in a low level way can someone post some code.

My five cents: I would not try to do it, even it could be possible. There should be an RPC mechanism to share messages between both.
It depends not just on the memory layout, the linker scripts, so that both cores have the same addresses in SRAM to access.

The CM7 has an MPU: possible that this one is programmed in a way, that CM4 cannot access a part of the memory.
The CM7 has also DTCMs which can be seen only by the CM7, not the CM4. If linker places variables there, the CM4 cannot access.

The 'biggest' issue is the cache on CM7: even CM4 would write variable in SRAM (CM4 does not have caches, writes directly to SRAM), the CM7 would not update from SRAM, the variable is hold in Data Cache. It needs 'Cache Coherency' function calls so that CM7 can see if CM4 has updated (vise versa as well, CM7 variable sits still in cache and not updated on SRAM for CM4).

Using 'shared memory' between CM7 and CM4 is possible, but just if MPU and Caches are properly configured, handled etc. This is not really access-able in an Arduino Scatch.

Hey Tjaekel have you seen this issue

https://forum.arduino.cc/index.php?topic=694894.0

It seems that for me the M4 core can not serial output. just wondering how to show values used by the M4. If I can't share variables and can't serial output how can I debug?

Any ideas?

I have seen (and might give my five cents there).
Good question: how to debug M4?
I miss anyway a nice debugger in Arduino Pro IDE (it does not seem to be there yet if I click on the icon).
So, you (and we) might have just a chance to debug via printing variables content via UART terminal.

Assuming CM4 in Portenta does not seem to initialize Serial properly (see comments on other thread) - we might need a message handler, or really shared memory.
Even there is mbed OS running - not sure if the same is running on CM4, so that you can send via Queues. I could imagine, that just CM7 runs mbed, an RTOS, but not the CM4. The CM4 might be pretty bare-minimum in terms of libraries supported there, what CM4 would initialize when this starts etc.

I saw, there is an RPC mechanism (in source code) - but no idea if working as communication between CM7 and CM4. We might need such an approach, that CM4 can talk to CM7 and CM7 will do the 'Serial Server'.

So, we might need a 'server' running on CM7 which waits for messages (like printf's) sent by CM4. CM7 will then forward to Serial (UART).

Maybe, I will try a bit in the evenings.

BTW: I am just a regular user of Portenta (just a bit familiar with ARM, Multi-Core systems). So, I cannot support and all is based on my guesses (how Portenta, the mbed, the software work).

I did get the M4 sharing a variable with the M7 using RPC. Code is here

Basically the M4 core sends a variable to an M7 function. The M7 function puts the variable into an M7 global variable.

Not sure if this is useful, just happy it works.

6 Likes