When more than one task Executing and send string using UART communication, Tasks are executed in out of order.

In STM32H743ZI, I have created two tasks(Task1, Task2) with **equal prirority ** and each task will send “paticular string” in UART communication. Here we faced two problem that are, 1)Task2 will send string to UART before Task1 but Task1 was created before Task2. 2)In Round Robin scheduling, while using the delay function (VTASKDELAY) in both tasks, the task1 send string to UART, then task2 will send string to UART. But in the case if no delay function(VTaskDelay) was used in any of the task, task2 always send string to UART continuously, Task1 will not able to send string to UART.

When more than one task Executing and send string using UART communication, Tasks are executed in out of order.

That is normal, expected behaviour. You have to synchronize your tasks sharing a resource (UART) yourself in case it’s needed e.g. using a mutex or a semaphore. 1) Since both tasks have the same prio it’s perfectly right that task2 is scheduled first once the scheduler is activated. Creation time is not really important. 2) Verify your configUSETIMESLICING and configUSE_PREEMPTION settings (see https://www.freertos.org/a00110.html) according to your needs. RoundRobin scheduling scheme without time sliced preemption being enabled is co-operative scheduling where each task has to yield the CPU by itself. This is implicetely done when a task is going to sleep or block.

When more than one task Executing and send string using UART communication, Tasks are executed in out of order.

When more than one task Executing and send string using UART communication, Tasks are executed in out of order.

Thanks for your response I understand that I need to sync my UART resource myself but when I did the exact same program in premptive sheduling : Same 2 tasks , When one runs I increase the other tasks’s priority inside the first task and visa versa and it keeps running. In terminal I got both the strings from both the tasks displayed alternatively, although here also I did not Sync my UART resource but the task running did it by itlsef. I expected the same behaviour when I try it with round robin sheduling, but only task 2 string is printed and UART does not free itslef when the task is switched at the specified time slice. I am not able to understand this.

When more than one task Executing and send string using UART communication, Tasks are executed in out of order.

Properly using RoundRobin without time sliced preemption is a possibility to share a resource without additional synchronization. Again: Each task has to give up/yield (e.g. using taskYIELD()) the CPU when appropriate e.g. after completion of sending a string via UART. You did basically the same by patching the task priorities and let the scheduler switch the tasks accordingly. When using time sliced preemption (do you ?) you need to protect the shared resource yourself because it’s out of your control when exactly a task is running. The scheduler does. The resulting behaviour of the config-defines is pretty well documented and support various scheduling schemes. First you should find the scheme you need.