I have FreeRTOS running on the STM32F4DISCOVERY board, and I have this code:
xTaskCreate( vTask1, "Task 1", 200, NULL, 1, NULL ); xTaskCreate( vTask2, "Task 2", 200, NULL, 1, NULL ); vTaskStartScheduler();
where vTask1 is a function:
void vTask1( void *pvParameters ) { volatile unsigned long ul; for( ;; ) { LED_On(0); for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ ) { } LED_On(2); LED_Off(0); } }
vTask2 has almost the same code:
void vTask2( void *pvParameters ) { const char *pcTaskName = "Task 2 is running\n"; volatile unsigned long ul; for( ;; ) { LED_On(3); LED_Off(2); for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ ) { } LED_Off(3); } }
When I run the program, I see that LED0 and LED3 are always on (switching them too quickly for my eyes, which is good), and LED2, the “common resource”, flashes very quickly. The problem is this: when I cancel the order of the xTaskCreate calls, I get the same situation with the other flashing LED2 behavior, which is much slower. Why does this happen, because the tasks must have equal priority and, therefore, follow a circular schedule? Shouldn't they get the same amount of time? Why does their behavior change after creation only in a different order?
Thanks in advance.