Is it safe to read and write UART from different tasks?
Posted: Wed Mar 27, 2019 9:02 am
Just a small doubt that hit me recently.
I have an ESP32 project where I answer to a custom communication protocol on UART0. I have a task receiving interrupts when there is data to read that elaborates the requests and in turn sends (through a message queue) valid messages to a second task. The second task then answer those requests, eventually by writing to the UART in turn.
Is is safe to have a task reading the uart while another one writes it (concurrently)? Rx and Tx lines are separated, and up until now there was no problem, but you never know. Should I use a semaphore or have both communication directions in a single thread?
I have an ESP32 project where I answer to a custom communication protocol on UART0. I have a task receiving interrupts when there is data to read that elaborates the requests and in turn sends (through a message queue) valid messages to a second task. The second task then answer those requests, eventually by writing to the UART in turn.
Is is safe to have a task reading the uart while another one writes it (concurrently)? Rx and Tx lines are separated, and up until now there was no problem, but you never know. Should I use a semaphore or have both communication directions in a single thread?