Page 1 of 1

UART driver & threads

Posted: Tue Oct 15, 2019 10:56 am
by sntnjrg
Hi,

I have two threads that read from the serial port:

thread A:

Code: Select all

uartStartReceive(&UARTD3, BUFFER_SIZE_A, rx_buffer_A);

thread B:

Code: Select all

uartStartReceive(&UARTD2, BUFFER_SIZE_B, rx_buffer_B);

In both threads, after I run the uartStart() function, I start reading on both ports.

The ports are assigned the following callbacks:

UARTD3:
- callback txend1_cb: set A_txend1_cb() function.
- callback rxend_cb: set A_rxend_cb() function.
- callback rxerr_cb: set A_rxerr_cb() function.
- callback timeout_cb: set A_timeout_cb() function.

UARTD2:
- callback rxend_cb: set B_rxend_cb() function.
- callback rxerr_cb: set B_rxerr_cb() function.
- callback timeout_cb: set B_timeout_cb() function.

The thread A sends commands to a device and waits for a response. When I run thread B, I have observed that the response is lost.
I have checked that in the txend1_cb() callback the command has been sent but I never receive anything through the UARTD3 port. If I only execute thread A, I receive the response associated with the command that I sent.

Is this problem because I have different functions assigned to each callback?

Thank you

Re: UART driver & threads

Posted: Tue Oct 15, 2019 1:12 pm
by Giovanni
Hi,

Callback functions should not have an impact on UART operations, it must be something else.

I recommend to activate assertions and state checker in chconf.h and to compile using -O0 until the problem is cleared.

Giovanni

Re: UART driver & threads

Posted: Wed Oct 16, 2019 8:47 am
by mikeprotts
It may be worth using a diuagnostic rxchar callback in case it's a buffering issue. Possibly also worth reducing buffer size to less than the data size to ensure an end of buffer occurs.

Mike

Re: UART driver & threads

Posted: Thu Oct 17, 2019 8:43 am
by sntnjrg
Hi,

After several tests, I have observed that the problem is when I set the transmission mode (wiring) in the device associated with the thread B. When I remove the wiring, everything works perfectly.

Thank you for the help.