SAM3 Tasks not Switching

Hi, Im new to FreeRTOS and Im trying to run 2 tasks with the same priority running on ATMEL SAM3 arm cortex m3 evaluation board
Im creating the two tasks with simple command to print some text, the problem is that the tasks are not switching if I don’t add taskYIELD or vTaskDelay in both tasks ,
Can you help with that
here is the code static void task1(void *pvParameters)
{
UNUSED(pvParameters);
while (1)
{ LED_Toggle(LED0);
printf(”Task 1 : 1nr”);
printf(”Task 1 : 2nr”);
printf(”Task 1 : 3nr”);
//taskYIELD();
}
} static void task2(void *pvParameters)
{
UNUSED(pvParameters);
while (1)
{
printf(”Task 2 : 1nr”);
printf(”Task 2 : 2nr”);
printf(”Task 2 : 3nr”);
//taskYIELD();
}
}

SAM3 Tasks not Switching

Have you enabled preemption in FreeRTOSConfig.h? Without preemption being enabled, task switches only happen on API calls. Note also, that with these two tasks, no tasks of lower priority will ever be run (even with the yields) so hopefully these are set to priority 0.

SAM3 Tasks not Switching

…also, your printf() calls could cause any number of problems. If the printf() output is using something slow, or something like semi-hosting, then it is likely that the output will interfer with the workings of the scheduler (semi hosting and the RTOS trying to control the hardware at the same time).  When this is the case it is often found that context switches don’t happen unless you put a *lot* of time space between each printf() call. If the printf() outout is not so crude, and is instead using some sort of buffering, DMA, etc. then you will at least need to use some mutual exclusion on the printf() calls so both tasks cannot access the output channel (be that a UART, or any other console IO) at the same time.  Mutual exclusion should not be removed until the buffered output has actually been sent (the buffer is empty) which is very inefficient. Generally speaking using printf() from more than one place in a very small embedded system is just a bad idea.  For one thing, if you are using newlib (which some people still do, although the new nano newlib is a lot better) then you will use a *lot* of stack and add 10s of K to your code size. Regards.

SAM3 Tasks not Switching

Thank you Richard,
I see now the switching is working fine , my question is why when i enabled the preemption mode I had to increase the stack size to 1024 at least otherwise i got overflow ?