From f78aa4f936b8bcdd8237f070125e60595f582eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Sat, 1 Apr 2023 14:31:24 +0200 Subject: [PATCH 1/2] rp: Allow zero len reads for buffered uart Prevents the read methods from getting stuck forever. --- embassy-rp/src/uart/buffered.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs index 1a573b31..9aa0b571 100644 --- a/embassy-rp/src/uart/buffered.rs +++ b/embassy-rp/src/uart/buffered.rs @@ -175,6 +175,10 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> { fn read<'a>(buf: &'a mut [u8]) -> impl Future> + 'a { poll_fn(move |cx| { + if buf.is_empty() { + return Poll::Ready(Ok(0)); + } + let state = T::state(); let mut rx_reader = unsafe { state.rx_buf.reader() }; let n = rx_reader.pop(|data| { @@ -202,6 +206,10 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> { } pub fn blocking_read(&mut self, buf: &mut [u8]) -> Result { + if buf.is_empty() { + return Ok(0); + } + loop { let state = T::state(); let mut rx_reader = unsafe { state.rx_buf.reader() }; From 7ef6a3cfb22ee1e497fcea37a019ca32d22298b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Sun, 2 Apr 2023 14:36:32 +0200 Subject: [PATCH 2/2] rp: Allow zero len writes for buffered uart Prevents the write methods from getting stuck forever. --- embassy-rp/src/uart/buffered.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs index 9aa0b571..c620ed08 100644 --- a/embassy-rp/src/uart/buffered.rs +++ b/embassy-rp/src/uart/buffered.rs @@ -301,6 +301,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { fn write<'a>(buf: &'a [u8]) -> impl Future> + 'a { poll_fn(move |cx| { + if buf.is_empty() { + return Poll::Ready(Ok(0)); + } + let state = T::state(); let mut tx_writer = unsafe { state.tx_buf.writer() }; let n = tx_writer.push(|data| { @@ -335,6 +339,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { } pub fn blocking_write(&mut self, buf: &[u8]) -> Result { + if buf.is_empty() { + return Ok(0); + } + loop { let state = T::state(); let mut tx_writer = unsafe { state.tx_buf.writer() };