chore: drain uart

This commit is contained in:
Kieran Klukas
2026-03-04 10:13:25 -05:00
parent acd1ff0112
commit e1fb2a10ba

View File

@@ -1,5 +1,6 @@
use std::fs::File;
use std::io::{Read, Write};
use std::os::fd::AsRawFd;
use anyhow::{Result, bail};
@@ -81,7 +82,10 @@ impl HSMIntf {
fn write_all(&mut self, data: &[u8]) -> Result<()> {
log::trace_hex("TX", data);
self.file.write_all(data)?;
self.file.flush()?;
// tcdrain ensures all written data is transmitted before returning.
// File::flush() is a no-op for std::fs::File, so without this,
// macOS CDC-ACM may buffer writes and cause protocol desync.
unsafe { libc::tcdrain(self.file.as_raw_fd()); }
Ok(())
}