mike-matera / ArduinoSTL

An STL and iostream implementation based on uClibc++ that supports my CS-11M class.
GNU General Public License v3.0
320 stars 79 forks source link

std::string and FreeRTOS fails #47

Open AlejandroGuirao opened 4 years ago

AlejandroGuirao commented 4 years ago

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

mike-matera commented 2 years ago

What processor are you using?