FreeRTOS priority not working

Working libraries, libraries being ported and related hardware
Post Reply
paksoft
Posts: 13
Joined: Sun Apr 10, 2016 3:16 am

FreeRTOS priority not working

Post by paksoft » Wed Nov 01, 2017 7:50 am

Hello Dude,

I'm new to FreeRTOS and studying the book from FreeRTOS. I have some problem with FreeRTOS priority.
My hardware is STM32F103C8T6 blue pill from ebay and my code is as follow:

Code: Select all

//#include <MapleFreeRTOS821.h>
#include <MapleFreeRTOS900.h>

#define pinLED  PC13   //For STM32F103C8T6

void vTaskFunction(void *pvParameters)  // This is a task.
{
  char *pcTaskName;
  /* The string to print out is passed in via the parameter. Cast this to a
  character pointer. */
  pcTaskName = (char *) pvParameters;
  for (;;)
  {
    digitalWrite(pinLED, HIGH); vTaskDelay(100);
    digitalWrite(pinLED, LOW);
    Serial.println(pcTaskName);  /* Print out the name of this task. */
    vTaskDelay(1000);  // one tick delay (15ms) in between reads for stability
  }
}


void setup()
{
  static const char *pcTextForTask1 = "Task 1 is running\n";
  static const char *pcTextForTask2 = "Task 2 is running\n";

  // initialize the digital pin as an output:
  pinMode(pinLED, OUTPUT);
  Serial.begin(11520);      

  // Now set up two tasks to run independently.
  xTaskCreate(
      vTaskFunction   /* Pointer to the function that implements the task. */
    ,  (const portCHAR *) "Task 1"   /* Text name for the task.  This is to facilitate debugging only. */
    ,  configMINIMAL_STACK_SIZE   /* Stack depth - most small microcontrollers will use much less stack than this. */
    ,  (void*)pcTextForTask1 /* Pass the text to be printed into the task using the task parameter. */
    ,  1     /* Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.*/
    ,  NULL );/* We are not using the task handle. */

  xTaskCreate(
      vTaskFunction   /* Pointer to the function that implements the task. */
    ,  (const portCHAR *) "Task 2"   /* Text name for the task.  This is to facilitate debugging only. */
    ,  configMINIMAL_STACK_SIZE   /* Stack depth - most small microcontrollers will use much less stack than this. */
    ,  (void*)pcTextForTask2 /* Pass the text to be printed into the task using the task parameter. */
    ,  2     /* Change priority looks at what happens*/
    ,  NULL );/* We are not using the task handle. */


  // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
  vTaskStartScheduler();
  /* If all is well we will never reach here as the scheduler will now be
  running.  If we do reach here then it is likely that there was insufficient
  heap available for the idle task to be created. */
  for( ;; );
}

void loop()
{
    // Insert background code here
}
I've set low and high priority for "Task 1" and "Task 2" respectively. So that, the expected output should be "Task 2 is running" as "Task 1" never enter the Running state, but output is
Task 2 is running

Task 1 is running

Task 2 is running

Task 1 is running
Any suggestion and advice are greatly appreciated.

pak

edogaldo
Posts: 285
Joined: Fri Jun 03, 2016 8:19 am

Re: FreeRTOS priority not working

Post by edogaldo » Wed Nov 01, 2017 11:47 am

Hi, I'd say the vTaskDelay() in the task code grants Task 1 cpu time to execute

paksoft
Posts: 13
Joined: Sun Apr 10, 2016 3:16 am

Re: FreeRTOS priority not working

Post by paksoft » Wed Nov 01, 2017 12:09 pm

Thank you for advice, it's working now.
Time to read more and more.

pak

Post Reply