How to synchronize the two task in UART interrupt mode

I am craeting two task and A ,B and i want to send data on same UART and i am using preemtive scheduling with 1ms systick below is my code i have written

uint8_t TX_Buffer_1[] = "MADY\n\r";
uint8_t TX_Buffer_2[] = "Hello_2";

void main()
{

    xTaskCreate( vUART_1_Task, ( signed portCHAR * ) "LED1", 100, NULL, 2, &UART_1_handle1 );

    xTaskCreate( vUART_2_Task, ( signed portCHAR * ) "LED2", 100, NULL, 2, &UART_2_handle2 );

    vTaskStartScheduler();
}

static void  vUART_1_Task(void *pvParameters)
{
    BaseType_t  status;

    for( ;; )
    {
       UART_Write((HalUartHandle_t *)&g_Uart_1, UART_1, (uint8_t *) TX_Buffer_1, sizeof(TX_Buffer_1));

       vTaskDelay( 10);
    }
}

static void  vUART_2_Task(void *pvParameters)

{
    BaseType_t  status;

    for( ;; )
    {
       UART_Write((HalUartHandle_t *)&g_Uart_1, UART_1, (uint8_t *) TX_Buffer_2, sizeof(TX_Buffer_2));

       vTaskDelay( 10);
    }
}

Output is as follows

MAHello_2

MAHello_2

continuesly print

we have had this several times before, for example here: Synchronizing UART TX - Kernel - FreeRTOS Community Forums

I generally recommend to employ the forum search function before posting questions.

The first part of the answer is that very likely UART_Write is NOT designed to be RTOS aware, and thus not suitable. It likely also “spin-waits” as it is sending, and thus isn’t really appropriate for use in an RTOS, even if you added the sycronization needed to make it uable in an RTOS.

Studying a bit to understand those questions will help you emensly to answer the question you are asking.

UART_Write function write in UART Interrupt mode and both the task access that UART RX,TX functionality

but i am not able to synchronise the task in interrupt mode first task write after that my code stuck into the config_assert of xSemaphoreGiveFromISR

It would help to know which assert was triggered, but a common one is due to not assigning the interrupt a valid priority. They often default to a non-suitable priority.

Which synchronization primitive are you using for synchronizing? Can you share code snippet?

Which assert is getting triggered?

Why not create 3 tasks.
TAsk A/B to write to a Queue
Tasks 3 that reads the queue and sent to a UART…
Unless you want to have some order, but then it sounds like you are doign something wrong…

If the write to the parts is using an interrupt based driver, then you don’t really need a third task to do the operations, but they can be done at the task level.

There will need to be a Semaphore or Mutex to block access while the operation is in progress (it needs to be a semaphore if it will be cleared by an ISR).

If the ISR asserted in the xSemaphoreGiveFromISR, as reported, my guess is that the interrupt priority of the ISR was never set right (and on many machines it defaults to being just too high). That, or the file with the ISR isn’t getting the right handle for the Semaphore.

I have rarely found a uart driver from a vendor that worked the way I wanted, as they almost always take a buffer that needs to be maintained with the data until the sending is complete, and then you can give them another buffer. I tend to write my own that stores the data to send into a Queue or Streambuffer, and that is pulled off in an ISR. The sending end of the Queue/Streambuffer is guarded with a Mutex so tasks can fill the buffer with a full message, at which point they give it up.