1

I'm running into an issue with the Pico W device where it hangs when using the second core. I am trying to parse through a config file using Regex and the code halts at the following:

smatch match;
for (auto it = sregex_iterator(data.cbegin(), data.cend(), rx), end = sregex_iterator(); it != end; it++)
{
    match = *it;
    // handle the match;
}

I'm loading a simple INI config for some settings that can be flashed on and opened with LittleFS. This program runs perfectly fine on core_0 with core_1 not activated. I want core_1 to monitor a temperature sensor (super basic) and send temperature status to core_0 via the core fifo, but as soon as a I add the setup1() and loop1() functions to main.cpp my original code fails at the above for-loop.

Right now core_1 does nothing but print "core_1 loop" to Serial and delay for 1 second. Super simple, but as soon as I initiate the second core, my core_0 will halt when it tries to parse the ini file during setup_0().

Here is my main.cpp:

#include <Arduino.h>
#include <Log.h>
#include <WaterSystem.h>
WaterSystem waterSystem;

void setup()
{
    // Initialize SPI and load config.ini
    waterSystem.setup_0();
    // notify core_1 it can continue
    rp2040.fifo.push(1);
}
void loop()
{
    Log::d("core_0 loop");
    delay(1000);
}
void setup1()
{
    // Wait until core_0 setup completes
    rp2040.fifo.pop();
}
void loop1()
{
    Log::d("core_1 loop");
    delay(1000);
}

Note: the Log class is just a helper that appends a millis() timestamp and a "level" character to the start of each Serial message.

My only theory right now is that I'm maybe somehow hitting a stack-memory limit while trying to regex parse a 743Byte file on the stack instead of the heap? Maybe I'm getting a stack overflow because the cores are splitting the stack memory size? The only alternative I can think of is to do a more specific file parsing instead of regex (which I know has a lot of overhead but only affects setup() and not loop(), and I'm fine having a slower startup time). Again all of my code runs perfectly fine until I add the setup1() and loop1() functions to main.cpp.

flamewave000
  • 547
  • 5
  • 12

0 Answers0