Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::string and FreeRTOS fails #47

Open
AlejandroGuirao opened this issue Nov 10, 2019 · 2 comments
Open

std::string and FreeRTOS fails #47

AlejandroGuirao opened this issue Nov 10, 2019 · 2 comments

Comments

@AlejandroGuirao
Copy link

AlejandroGuirao commented Nov 10, 2019

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
Copy link
Owner

What processor are you using?

@Ebola-Chan-bot
Copy link

Ebola-Chan-bot commented Nov 4, 2024

//In your StringTestTask
for(;;) {}

Infinite loop without side-effects is undefined behavior, which means that the compiler will output unpredictable results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants