Hi All,
I've been using a Giga R1 for about 3+ months with RPC successfully implemented between the two cores. The M7 core runs the main program (over 500 lines of code) which primarily controls a stepper motor along with a number of other electronics (i.e. RS485 board), sensors, buttons, etc. I coded my own pulse timer sending signals to a stand-alone stepper driver about every 40 microseconds.
As part of the of a trade show demo that I developed, I use the M4 core to run the display shield information. The two cores "communicate" with each other via GPIO pins high/low signals to know what parts of the code are being activated. This has worked well except for one aspect: the M4 core need one variable from the M7 in order to update the stepper motor positional information. I successfully implemented the RPC protocol and everything has been working.
I was disappointed by the how long it took for the RPC to transfer one integer variable between the two cores. It seems to be longer than 40 microseconds of CPU time because my stepper motor pulse timer was getting effected by the PRC call. So, I began researching methods to transfer a single variable between the two cores without the RPC protocol. After trying numerous ideas published on this forum and other locations, with the great help of a work colleague, I was able to successfully implement a very simple solution.
In my research, I came across a number of people trying to do the same thing, so I thought I'd share my code in the hopes of helping others. The credit for this code goes to PCMaster2165 and his code published here: SDRAM to Share Variables Between M7 & M4 Cores. I wasn't able to get the code working for my demo by myself. A work colleage did a deep dive into PCMaster2165's code and created test sketches for me to try. I'm happy (SO HAPPY) to report that PCMaster2165's code is awesome and beautifully transfer's variables between both cores without RPC.
For my usage, I only need the M7 core to write and the M4 core to read, so I decided to eliminate a number of the flags in PCMaster2165's original code. While my version of his code is very simple (4 or 5 lines of code within the main loop), I caution others that my version of his code doesn't prevent collisions between the two cores. I have a very unique and simple usage / implementation, so it works for me. Before doing this on your Giga, please research and consider PCMaster2165's flags for collision protection, etc.
Attached are three files for anyone that would like to test sharing a variable between the two Giga cores without the RPC transfer procedure:
- Put the .ino sketches into a folder.
- Open each sketch and allow the IDE to create subfolders.
- In BOTH subfolders, place a copy of the SharedStructs.h file.
- Compile and upload the M4 sketch to the M4 core and the M7 sketch to the M7 core. I used the 1MB M7 + 1MB M4 flash split. I didn't test other flash splits.
My code transfers a number from 1 to 85 from the M4 to the M7 core and then prints it to the serial monitor. In my actual trade show demo code, the opposite is used: M7 writes and M4 reads, so the code works both ways (must switch the read / write sections correctly).
I hope this is useful for the Giga community.
Robert
M4_Core_Shared_Variables_Ver_1_4.ino (1.6 KB)
SharedStructs.h (520 Bytes)
M7_Core_Shared_Variables_Ver_1_4.ino (1.6 KB)