S32K148 - Running 3 task at different frequency using FreeRTOS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K148 - Running 3 task at different frequency using FreeRTOS

Jump to solution
2,108 Views
Chandra13
Contributor I

Hello,

I have a S32K148EVB-Q176, and I modified the freertos_s32k148 SDK to run a small project. I would like to run 3 tasks at different frequencies.

  • Task 1 at 500ms
  • Task 2 at 1000ms
  • Task 3 at 2000ms

With the sample code below, whenever the scheduler starts, it executes only the task with higher priority and that too only once. In this case, the output on the PE console is always, "Task 3 counter : 1".

What am I missing here?

#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "sdk_project_config.h"
#include <stdio.h>

//void rtos_start(void);
void task1_500ms(void *parameters);
void task2_1000ms(void *parameters);
void task3_2000ms(void *parameters);
int count1 = 0;
int count2 = 0;
int count3 = 0;
int main(void)
{
   //rtos_start();
   printf("Hello World\n\n");

   xTaskCreate(task1_500ms,  "Task1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
   xTaskCreate(task2_1000ms, "Task2", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
   xTaskCreate(task3_2000ms, "Task3", configMINIMAL_STACK_SIZE, NULL, 3, NULL);

   vTaskStartScheduler();
}
void task1_500ms(void *parameters)
{
   while(1)
   {
      printf("Task 1 counter : %d\n", ++count1);
      vTaskDelay(500/portTICK_PERIOD_MS);
   }
}
void task2_1000ms(void *parameters)
{
   while(1)
   {
      printf("Task 2 counter : %d\n", ++count2);
      vTaskDelay(1000/portTICK_PERIOD_MS);
   }
}
void task3_2000ms(void *parameters)
{
   while(1)
   {
      printf("Task 3 counter : %d\n", ++count3);
      vTaskDelay(2000/portTICK_PERIOD_MS);
   }
}

 

Thanks!

0 Kudos
Reply
1 Solution
2,101 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @Chandra13 

Everything looks correct in your code. The only thing missing from the main function is the infinite loop after calling vTaskStartScheduler(), which is why the task with the highest priority is executed once, and after that, the program ends. Try to add for( ;; ) after starting the scheduler; if all is well, the scheduler will be running.

Also, for vTaskDelay, I suggest you use pdMS_TO_TICKS(xTimeInMs) as the received parameter, this macro converts a time in milliseconds to a time in ticks.

vTaskDelay(pdMS_TO_TICKS(500));

 

B.R.

VaneB

View solution in original post

0 Kudos
Reply
3 Replies
2,102 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @Chandra13 

Everything looks correct in your code. The only thing missing from the main function is the infinite loop after calling vTaskStartScheduler(), which is why the task with the highest priority is executed once, and after that, the program ends. Try to add for( ;; ) after starting the scheduler; if all is well, the scheduler will be running.

Also, for vTaskDelay, I suggest you use pdMS_TO_TICKS(xTimeInMs) as the received parameter, this macro converts a time in milliseconds to a time in ticks.

vTaskDelay(pdMS_TO_TICKS(500));

 

B.R.

VaneB

0 Kudos
Reply
2,087 Views
Chandra13
Contributor I

Hello @VaneB ,

Thank you for the feedback.
Even with your suggestion, the program still didn't respond after one execution. But after I removed the "printf" statements, the program is working fine.
Do you know why the printf statement is stalling the program?

Also, is there any option in the Design Studio to turn off the compiler optimizations?

 

0 Kudos
Reply
2,080 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @Chandra13 

You can change the optimization level in the project's properties. Please refer to the attached image.

VaneB_0-1674254568706.png

Regarding the printf issue take a look this post: Function printf in S32 Design Studio 

0 Kudos
Reply