I have FreeRTOS running on a 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 this 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 nearly 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 (their switching is too fast for my eye, which is fine), and that LED2, the "shared resource", is blinking very fast.
The problem is this: when I reverse the order of the xTaskCreate
calls, I get the same situation with a different blinking behavior of LED2, which is much slower.
Why would this happen, since the tasks should have equal priority and therefore follow a round-robin schedule? Shouldn't they get the same amount of time? Why is their behavior changing after only having created them in different order?
Thanks in advance.