UART driver & threads

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

UART driver & threads

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: UART driver & threads

Post 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
mikeprotts
Posts: 166
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 19 times
Been thanked: 31 times

Re: UART driver & threads

Post 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
sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Re: UART driver & threads

Post 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.
Post Reply