chnWriteTimeout with USB Serial - finish on buffer write or device write?

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
charlesrwest
Posts: 38
Joined: Sat Jan 10, 2015 10:12 pm
Has thanked: 1 time
Been thanked: 1 time

chnWriteTimeout with USB Serial - finish on buffer write or device write?

Post by charlesrwest »

Hello,

I have a few questions about using the Serial over USB Driver (SDU1 on STM32F072B).

If I may ask:
1. How thread safe is it?
a. Is it safe to have a writer thread (chnWriteTimeout) and a reader thread (chnReadTimeout) running at the same time?
b. Is it safe to have multiple writer threads doing chnWriteTimeout or will messages intermingle/corrupt?

2. Does the chnWrite/chnRead function return once the data in place into the appropriate buffer or does it wait until the data actually sent?
a. Would it be an acceptable pattern to have multiple threads do blocking writes or would this result in very long waits because it has to be sent over the wire before the functions returns?

3. How big is the efficiency difference of calling chnWriteTimeout vs repeated calls of chnPutTimeout?

Thanks!
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chnWriteTimeout with USB Serial - finish on buffer write or device write?

Post by Giovanni »

Hi,

1) Both are thread safe but operation atomicity is not assured. You need an external mutex/semaphore for that.

2) Data has been sent because it returns when USB completes the transaction.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chnWriteTimeout with USB Serial - finish on buffer write or device write?

Post by Giovanni »

Correction on point 2:

The function can return after simply writing in the buffer. If you need control over this then you may consider using the "raw" USB API without buffering, there is a demo about this: /testhal/STM32/STM32F7xx/USB_RAW

Giovanni
Post Reply