From 9fb2eb7470d56d94bd8687b7566d60c3837df3a2 Mon Sep 17 00:00:00 2001 From: Peter Hansen Date: Sun, 3 Dec 2023 16:35:39 -0500 Subject: [PATCH] nrf52/qspi: avoid infinite busy-wait on QSPI read/write with zero-len buffer, fixes #2115 --- embassy-nrf/src/qspi.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) mode change 100644 => 100755 embassy-nrf/src/qspi.rs diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs old mode 100644 new mode 100755 index add093b6..5e1a4e84 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -391,8 +391,13 @@ impl<'d, T: Instance> Qspi<'d, T> { /// /// The difference with `read` is that this does not do bounds checks /// against the flash capacity. It is intended for use when QSPI is used as - /// a raw bus, not with flash memory. + /// a raw bus, not with flash memory. pub async fn read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> { + // Avoid blocking_wait_ready() blocking forever on zero-length buffers. + if data.len() == 0 { + return Ok(()); + } + let ondrop = OnDrop::new(Self::blocking_wait_ready); self.start_read(address, data)?; @@ -409,6 +414,11 @@ impl<'d, T: Instance> Qspi<'d, T> { /// against the flash capacity. It is intended for use when QSPI is used as /// a raw bus, not with flash memory. pub async fn write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> { + // Avoid blocking_wait_ready() blocking forever on zero-length buffers. + if data.len() == 0 { + return Ok(()); + } + let ondrop = OnDrop::new(Self::blocking_wait_ready); self.start_write(address, data)?; @@ -425,6 +435,11 @@ impl<'d, T: Instance> Qspi<'d, T> { /// against the flash capacity. It is intended for use when QSPI is used as /// a raw bus, not with flash memory. pub fn blocking_read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> { + // Avoid blocking_wait_ready() blocking forever on zero-length buffers. + if data.len() == 0 { + return Ok(()); + } + self.start_read(address, data)?; Self::blocking_wait_ready(); Ok(()) @@ -436,6 +451,11 @@ impl<'d, T: Instance> Qspi<'d, T> { /// against the flash capacity. It is intended for use when QSPI is used as /// a raw bus, not with flash memory. pub fn blocking_write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> { + // Avoid blocking_wait_ready() blocking forever on zero-length buffers. + if data.len() == 0 { + return Ok(()); + } + self.start_write(address, data)?; Self::blocking_wait_ready(); Ok(())