This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: MSP432P401R
Hello,
I'm working on a application where two tasks are utilizing UART peripheral. I'm facing uart blocking issue when both the tasks try to read at same time. (Uart readTimeout = 200)
For simplicity I have replicated the problem as below:
UART_read() is blocking the task1 after I post a sem by a button press. Even a readTimeout = 200 is already set.
Task1's while(1) loop should continue to run regardless of Task2, as a readTimeout is already defined.
Kindly refer the below code snippet.
void Task1() { while (1) { UART_read(uart, input1, 10); usleep(1000*100); } } void Task2() { while (1) { Semaphore_pend(sem_handle, 0xFFFFFFFF); UART_read(uart, input2, 10); } } void button_isr(uint_least8_t index) { Semaphore_post(sem_handle); }
Any help is appreciated.
Regards,
Keshav Aggarwal
Hey Keshav,
Let me check with the TI-RTOS team and see if they can provide some insight here.
Thanks,
JD
Hi Keshav,
In blocking mode, UART_read() will not check if there is another UART_read() currently in progress. If you call UART_read() from one task, and a second task calls UART_read(), the second read will overwrite the internal state of the UART driver. You will need to add a semaphore to synchronize access to the UART.
Best regards,
Janet
Hi Janet,
Yes we need synchronization. If other thread tries UART_read() when an previous UART_read() is in progress, then the internal clock module stucks and it keeps on waiting on semaphore. That's a bug I guess. It is blocking the UART_read(). It should report error on the second UART_read() if previous UART_read() is in progress.
Regards,
Keshav Aggarwal
Hi Keshav,
The UART driver only returns an error in callback mode if you try to do a read while another read is in progress. It probably should have returned an error in blocking mode too. The UART driver documentation is not clear about this, though, and just says you need to check the return status of UART_read() or synchronize access.
Best regards,
Janet
**Attention** This is a public forum