Page 1 of 1

Is it safe to read and write UART from different tasks?

Posted: Wed Mar 27, 2019 9:02 am
by maldus
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?

Re: Is it safe to read and write UART from different tasks?

Posted: Sun Mar 31, 2019 12:27 am
by fivdiAtESP32
There's an esp-idf example called "UART Asynchronous Example with Separate Receive and Transfer Tasks" at https://github.com/espressif/esp-idf/tr ... _rxtxtasks so it looks like it can be done.

Re: Is it safe to read and write UART from different tasks?

Posted: Wed Apr 24, 2019 8:41 pm
by urbanze
Looking just at uart.c, apparently YES, but anyone can really confirm if all uart tx are safe?