PlatformIO Community

STM32DUINO FreeRTOS doesn't work

Hi ,
I’m trying to use freeRTOS for my STM32F429ZI Nucleo board. Since I’m using Arduino framework I downloaded the stm32duino library from PIO Libraries.
I included STM32FreeRTOS.h to my sketch and use a simple serial print example .which i tested on Arduino board, but there is no output on the ST board using PIO.

#include <Arduino.h>
#include <STM32FreeRTOS.h>

TaskHandle_t Task_Handel1;
TaskHandle_t Task_Handel2;

void Task_Print1(void *pvParameters);
void Task_Print2(void *pvParameters);

void setup() {

   Serial.begin(9600);

  xTaskCreate(Task_Print1,"Task1",100,NULL,1,&Task_Handel1);
  xTaskCreate(Task_Print2,"Task2",100,NULL,1,&Task_Handel2);

 }

void Task_Print1(void *pvParameters)

{

  (void) pvParameters;

  while(1)

  {
  Serial.println("TASK1");
  vTaskDelay(1000/portTICK_PERIOD_MS);
  }

}

void Task_Print2(void *pvParameters)

{

  (void) pvParameters;

  while(1){
  Serial.println("TASK2");
  vTaskDelay(1000/portTICK_PERIOD_MS);

  }

}

void loop() {


}

Appreciate if someone can help .
Thanks.

  • Where do you start the task scheduler? Needs vTaskStartScheduler(); at the end of setup()
  • Not guarding the call to Serial.println() for multi-threaded access might be dangerous?

Hi Max ,
You 're right i got the sample codefrom the net and wonder how he didn’t add the vTaskStartScheduler(); and wonder how it works without that on Arduino ,but its working now .

Thanks.

It’s always safer to look directly at the example code that the concrete library gives you, e.g. at https://platformio.org/lib/show/2093/STM32duino%20FreeRTOS or the direct github. I’ve checked every single example .ino file and they all contain either vTaskStartScheduler() or the CMSIS-RTOSv2 wrapper function for it, osKernelStart(), at the end of setup().

If the code comes from a github repo you might want to consider to open an issue :smiley:

Good advice thanks Max :slight_smile: ,One more issue is that i try to add the freeRTOS sample code to my existing wifi101 sample code(ping example) to see if both works and seems like the wifi doesn’t get initialize .Is it because when we use freeRTOS it give first priorty to the freeRTOS tasks?

Thanks again.

Hi Max ,
It seems like as soon as i add freeRTOS library to the wifi example it doesn’t work .I even didn’t include STM32FreeRTOS.h to the wifi example sketch .
first what i did was , create a new project .Add the wifi101 library and use the example ping sketch .
it works .
then i add the freeRTOS library to the same project without even modifying the existing sketch it doesnt work .Stuck at " Attempting to connect to WPA SSID: ABC "

.ini is ;

[env:nucleo_f429zi]
platform = ststm32
board = nucleo_f429zi
framework = arduino
lib_deps = 
    arduino-libraries/WiFi101@^0.16.1
    stm32duino/STM32duino FreeRTOS@^10.2.1

Once i remove the freeRTOS from .ini it works again.
Also its not clear about the stack size you’re talking re wifi .

Thanks.

Okay if only adding this library causes the issue then it’s some kind of deeper problem that doesn’t have to do with code modifications at all.

Please file an issue at https://github.com/arduino-libraries/WiFi101/issues for the library authors.

If you had modified the code to use FreeRTOS and you would have created some FreeRTOS task that would run the WiFi stack, it would be important what stack size that task had been created with, because it may have run out of stack. As in

you’re allocating 100 integers (=400 bytes) of stack there for the task.

Thanks Max understood about the Stack size now ,but like i said even without including the library to sketch it doesn’t work ,so I will file an issue as per your advice .

thanks again .
Samson.

1 Like