Accessing Preferencs from core task
Posted: Thu Apr 14, 2022 10:38 am
Hi
I have been unable to access the Preferences object from within a core task. I crashes the chip.
Any attemp to read or write to the Preferences object fails. Although, the same code works as expected when in setup or loop.
I tried different core and the task can read and write to other globals.
I also tried to pass it to the task as a parmater but could get this to work either.
Any thoughts would be appreciated.
regards
steve
#######################################
#include <Preferences.h>
Preferences preferences;
TaskHandle_t TaskCore0;
int counter;
void setup() {
Serial.begin(115200);
///////////////////// this works fine //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from setup: %i\n", counter);
// preferences.end();
xTaskCreatePinnedToCore(
neoTrigger,
"TaskCore0",
1000,
NULL,
0,
&TaskCore0,
0); // this is the core where it will run
delay(500);
}
void neoTrigger( void * parameter) {
///////////////////// this crashes the chip //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from inside core task: %i\n", counter);
// preferences.end();
for (;;) {
///////////////////// this crashes the chip //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from inside loop: %i\n", counter);
// preferences.end();
delay(3000);
}
}
void loop() {
///////////////////// this works fine //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from inside loop: %i\n", counter);
// preferences.end();
delay(3000);
}
I have been unable to access the Preferences object from within a core task. I crashes the chip.
Any attemp to read or write to the Preferences object fails. Although, the same code works as expected when in setup or loop.
I tried different core and the task can read and write to other globals.
I also tried to pass it to the task as a parmater but could get this to work either.
Any thoughts would be appreciated.
regards
steve
#######################################
#include <Preferences.h>
Preferences preferences;
TaskHandle_t TaskCore0;
int counter;
void setup() {
Serial.begin(115200);
///////////////////// this works fine //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from setup: %i\n", counter);
// preferences.end();
xTaskCreatePinnedToCore(
neoTrigger,
"TaskCore0",
1000,
NULL,
0,
&TaskCore0,
0); // this is the core where it will run
delay(500);
}
void neoTrigger( void * parameter) {
///////////////////// this crashes the chip //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from inside core task: %i\n", counter);
// preferences.end();
for (;;) {
///////////////////// this crashes the chip //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from inside loop: %i\n", counter);
// preferences.end();
delay(3000);
}
}
void loop() {
///////////////////// this works fine //////////////////////////
// preferences.begin("ESP32Pref", false);
// preferences.putInt("counter", 4);
// counter = preferences.getInt("counter", 0);
// Serial.printf("the value of counter from inside loop: %i\n", counter);
// preferences.end();
delay(3000);
}