FreeRTOS Problem

Dear friends, Hi I have a simple code that turn on two LED in two seprated task. It doesn’t work. I debuge an i found that only one task execute. In fact execute the tast which was made first. please help me. I’m new in FreeRTOS
/* Includes ------------------------------------------------------------------*/

include "stm32f4x7_eth.h"

include "netconf.h"

include "main.h"

include "tcpip.h"

include "Serial.h"

include "LED.h"

include "task.h"

/--------------- Tasks Priority -------------/

define MAINTASKPRIO ( tskIDLE_PRIORITY + 1 )

define LED1TASKPRIO ( tskIDLE_PRIORITY + 3)

define LED2TASKPRIO ( tskIDLE_PRIORITY + 4)

/* Private function prototypes -----------------------------------------------*/ void Main_task(void * pvParameters); void ToggleLed1(void * pvParameters); void ToggleLed2(void * pvParameters); xTaskHandle ToggleLedHandle1; xTaskHandle ToggleLedHandle2; int main(void) { /* Configures the priority grouping: 4 bits pre-emption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); /* Init task */ xTaskCreate(Main_task, (int8_t *)"Main", configMINIMAL_STACK_SIZE * 2, NULL,MAIN_TASK_PRIO, NULL); /* Start scheduler */ vTaskStartScheduler(); /* We should never get here as control is now taken by the scheduler */ for( ;; ); } void Main_task(void * pvParameters) { SERInit(); LEDInit(); /* Start toogleLed4 task : Toggle LED4 every 250ms */ xTaskCreateStatic(ToggleLed1, (int8_t *)"LED1", configMINIMAL_STACK_SIZE, NULL, LED1_TASK_PRIO, &ToggleLedHandle1); xTaskCreateStatic(ToggleLed2, (int8_t *)"LED2", configMINIMAL_STACK_SIZE, NULL, LED2_TASK_PRIO, &ToggleLedHandle2); for( ;; ) { vTaskDelete(NULL); } } /** * @brief Toggle Led4 task * @param pvParameters not used * @retval None */ void ToggleLed1(void * pvParameters) {
  while(1){
        LED_On(1);
          }
} void ToggleLed2(void * pvParameters) {
  while(1){
        LED_On(0);
          }
}

FreeRTOS Problem

Neither task enters the Blocked state, so are always able to run, that means the scheduler will always select the task that has the highest priority, starving the task that has the lowest priority of any CPU time. I would recommend reading through the first chapters of the free book you can download here: https://www.freertos.org/Documentation/RTOS_book.html They take you through the scheduling algorithm, with some diagrams etc. that will show the behaviour you are observing. Hope this helps.

FreeRTOS Problem

Thanks for your quick answer I'm using FreeRTOS V7.3... In my program task2(ToggleLed2) has higher priority but task1(ToggleLed1) is always running... it confuse me... xTaskCreate(ToggleLed2, (int8t *)"LED2", configMINIMALSTACKSIZE, NULL, LED2TASKPRIO, &ToggleLedHandle2); xTaskCreate(ToggleLed1, (int8t *)"LED1", configMINIMAL_STACK_SIZE, NULL, LED1_TASK_PRIO, &ToggleLedHandle1); in this case ToggleLed2 task is always running and xTaskCreate(ToggleLed1, (int8t *)"LED1", configMINIMALSTACKSIZE, NULL, LED1TASKPRIO, &ToggleLedHandle1); xTaskCreate(ToggleLed2, (int8t *)"LED2", configMINIMAL_STACK_SIZE, NULL, LED2_TASK_PRIO, &ToggleLedHandle2); in this case ToggleLed1 task is always running .

FreeRTOS Problem

As Richard said, you should read the freeRTOS documentation and something general about the usage of tasks. But I'll give you a little hint. One solution could be working with delays (e.g. vTaskDelay).