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

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
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?

Postby charlesrwest » Tue Jul 02, 2019 4:52 pm

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: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

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

Postby Giovanni » Tue Jul 02, 2019 5:00 pm

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: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

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

Postby Giovanni » Thu Jul 04, 2019 9:47 am

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


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 23 guests