Uart.flush() issue

From the uart.flush() documentation:

This methods waits for the output FIFO to drain, i.e. for all bytes to be sent on the wire.
Could I please get some clarity around this statement? I had assumed that it meant that the method will block until all data had been clocked out. I'm using an output on the imp device to enable the transmitter.

function send(data){ // package request and send through uart txEnable.configure(DIGITAL_OUT); txEnable.write(1); bus.write(data); // wait for all data to be sent bus.flush(); txEnable.write(0); // should go low after ALL bytes have been clocked out. }

This routine works fine for any baud rate from 4800 upwards. Any serial byte sequence (of any length >1) below 4800 is truncated prematurely by the transmit enable dropping low. Should I instead assume that uart.flush() returns when the last byte in the FIFO is loaded into the transmit register but is not yet sent?

I’ve tested code extensively at 600bps, 1200, 2400 and up. I’m forced to add an imp.sleep() delay dependent on the baud rate to be sure of reliable transmission. If uart.flush() is working as intended, it might help if the documentation is updated to say that the method returns when the last byte is loaded into the transmitter (which is, IMO, less useful).

PS. I’m using E,8,1 at various data rates.

The intent is as documented, i.e. flush should block until all data has been clocked out.

However, there’s a bug in the released impOS where this operation can erroneously time out at low baud rates. A fix is in the pipeline! We’re also looking into providing asynchronous flush.

Thanks, good to know, especially about asynchronous flush too.