I am using the Arduino IDE and all code is in C/C++.
My old configuration was a Pro Micro as the master talking to a second Pro Micro as a slave over the I2C bus. It works fine except I ran out of program store on the master. Upgrading to the Pro Micro RP2040 solved that problem nicely. I am now eyeing that second core and want to move the code running on the slave to it. I copied and pasted the slave code and, to no surprise, ran into a massive number of duplicate defined variables. The variables that are constants aren’t a problem but many have different values over time on each processor. Before I go through the pain of renaming these variables on my slave, is there a way to tell the compiler to isolate the code on each core?
Thanks in advance,
Rick
I also wonder what will happen with the master-slave communications. Will the master send an I2C command from core 0 and core 1 see it on the same I2C interface? That would save me changing some code.
Do you really need to rename every variable? How about wrapping them in a namespace?
It sure looks like namespace should solve my problem but I’m confused by the examples I found.
If I say:
namespace qaz
{
-my entire program which is self contained-
}
will this work or must I add qaz:: in front of each variable and function?
Thanks,
Rick
You can use two isolated namespaces.
namespace core0 {
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Core0 running");
delay(1000);
}
}
namespace core1 {
int counter = 100;
void loop() {
while (true) {
counter++;
delay(500);
}
}
}
void setup() {
core0::setup();
multicore_launch_core1(core1::loop);
}
void loop() {
core0::loop();
}
Each namespace will have its own variables and functions. No variable renaming will be needed. Functions and variables will be accessed only via namespace prefixes.
For me, namespace didn’t isolate the groups of variables. I ended up finding each duplicate definition and resolving it. I also found that multicore_launch_core1(core1::loop) caused the processors to brick. If I just ran setup(), loop(), setup1(), and loop1() it worked fine. I do have in loop() the call to loop1();
Good work - happy to hear it’s goin’ now
I think the coders have done amazing things to make the dual core architecture easier to use. However, the supporting documentation has not caught up yet as far as I can tell.
Here is a dual core Hello World:
void setup()
{
Serial.begin(19200); // USB
}
void loop()
{
Serial.println(“hello world from core 0”);
delay(2000);
}
void setup1()
{
delay(1000);//to offset prints
}
void loop1()
{
Serial.println(“hello world from core 1”);
delay(2000);
}