From 7a1a4fd92bcfe6b236b98f6ff44e814ddd4ec8d8 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Thu, 22 Aug 2024 18:36:07 +0000 Subject: [PATCH] Let UART write return some bytes were written embedded_io::Write::write(buf) should not block until the full buffer was written. Instead, it should only block until at least one byte was written. --- rp2040-hal/CHANGELOG.md | 4 ++++ rp2040-hal/src/uart/writer.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index 967f2dc5a..d957a9447 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -16,6 +16,10 @@ The Minimum-Supported Rust Version (MSRV) for the next release is 1.77 - Support for *binary info*, which is metadata that `picotool` can read from your binary. - Bump MSRV to 1.77, because *binary info* examples need C-Strings. +### Fixed + +- Let UART embedded\_io::Write::write return some bytes were written. + ## [0.10.0] - 2024-03-10 ### Added diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index 747e1d620..2d2e08ed2 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -214,8 +214,8 @@ impl> embedded_io::ErrorType for Writer> embedded_io::Write for Writer { fn write(&mut self, buf: &[u8]) -> Result { - self.write_full_blocking(buf); - Ok(buf.len()) + let remaining = nb::block!(write_raw(&self.device, buf)).unwrap(); // Infallible + Ok(buf.len() - remaining.len()) } fn flush(&mut self) -> Result<(), Self::Error> { nb::block!(transmit_flushed(&self.device)).unwrap(); // Infallible