Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short delay to ensure port is flushed in OS X (and prevent download h… #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dledge
Copy link

@dledge dledge commented Feb 18, 2020

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.

…ang)

on OS X, it appears that occasionally the _port->flush() may not always complete before writeBinary() is called.  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.
@johmathe
Copy link

@shumatech Would really appreciate this PR - flashing on mac os X for a few architectures has been a huge pain.

@kaysievers
Copy link

kaysievers commented Dec 21, 2020

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

@kaysievers
Copy link

kaysievers commented Jan 13, 2021

It seems to work fine here, submitted it as a pull request: #150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants