ArduinoSTL
ArduinoSTL copied to clipboard
std::string and FreeRTOS fails
Hello, I am relatively new to Arduino and my C++ knowledge is a bit rusty so please excuse if i'm wrong with my post. There seems to be a memory allocation problem with strings in combination with FreeRTOS. The following code works fine:
#include <Arduino_FreeRTOS.h>
#include <Controllino.h>
#include <ArduinoSTL.h>
void StringTestTask(void *pvParameters);
void setup() {
Serial.begin(9600);
while(!Serial);
std::string s("Hello World!");
Serial.println(s.c_str());
xTaskCreate(
StringTestTask,
"StringTestTask",
512,
NULL,
2,
NULL);
}
void loop() {}
void StringTestTask(void *pvParameters) {
std::string s("Hello World!");
Serial.println(s.c_str());
for(;;) {}
}
I get "Hello World!" on my serial console. When I comment out the string in the setup() function like this:
#include <Arduino_FreeRTOS.h>
#include <Controllino.h>
#include <ArduinoSTL.h>
void StringTestTask(void *pvParameters);
void setup() {
Serial.begin(9600);
while(!Serial);
//std::string s("Hello World!");
//Serial.println(s.c_str());
xTaskCreate(
StringTestTask,
"StringTestTask",
512,
NULL,
2,
NULL);
}
void loop() {}
void StringTestTask(void *pvParameters) {
std::string s("Hello World!");
Serial.println(s.c_str());
for(;;) {}
}
Nothing is written to the console. The rest of the library seems to work (at least the parts I have tested). Any suggestions about this? Thank you for your help.
Alex
What processor are you using?