Short delay to ensure port is flushed in OS X (and prevent download h…
I was running into an occasional download failure on a SAMD51 platform only on OS X.
[ ] 0% (0/361 pages)write(addr=0x20004034,size=0x1000)
SAM-BA operation failed
An error occurred while uploading the sketch
After digging in a bit, it appears that occasionally the _port->flush() may not always complete before writeBinary() is called in Samba::write(). This results in an exception and an error during download (as it looks like we're running into the "SAM firmware bug" mentioned in the comments).
Adding this short delay helps ensure that the flush() command competes before the binary write is called. After adding this delay, I'm no longer getting occasional download failures.
@shumatech Would really appreciate this PR - flashing on mac os X for a few architectures has been a huge pain.
Hmm, this change just adds another (rather random) delay, while there is already an existing one in the same call in the flush() routine: https://github.com/shumatech/BOSSA/blob/master/src/PosixSerialPort.cpp#L291
Could you try just the change below, if it improves the situation?
--- a/src/PosixSerialPort.cpp
+++ b/src/PosixSerialPort.cpp
@@ -290,10 +290,7 @@ PosixSerialPort::put(int c)
void
PosixSerialPort::flush()
{
- // There isn't a reliable way to flush on a file descriptor
- // so we just wait it out. One millisecond is the USB poll
- // interval so that should cover it.
- usleep(1000);
+ tcdrain(_devfd);
}
bool
It seems to work fine here, submitted it as a pull request: https://github.com/shumatech/BOSSA/pull/150