diff options
| author | Peter Hansen <[email protected]> | 2023-12-03 16:35:39 -0500 |
|---|---|---|
| committer | Peter Hansen <[email protected]> | 2023-12-03 16:35:39 -0500 |
| commit | 9fb2eb7470d56d94bd8687b7566d60c3837df3a2 (patch) | |
| tree | c7a8a68c5d25829869b1dc46a7ebffd5d683cba8 | |
| parent | 9ba3aeada40afd3cafd64e73fee91896c15d7c8d (diff) | |
nrf52/qspi: avoid infinite busy-wait on QSPI read/write with zero-len buffer, fixes #2115
| -rwxr-xr-x[-rw-r--r--] | embassy-nrf/src/qspi.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index add093b63..5e1a4e842 100644..100755 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -391,8 +391,13 @@ impl<'d, T: Instance> Qspi<'d, T> { | |||
| 391 | /// | 391 | /// |
| 392 | /// The difference with `read` is that this does not do bounds checks | 392 | /// The difference with `read` is that this does not do bounds checks |
| 393 | /// against the flash capacity. It is intended for use when QSPI is used as | 393 | /// against the flash capacity. It is intended for use when QSPI is used as |
| 394 | /// a raw bus, not with flash memory. | 394 | /// a raw bus, not with flash memory. |
| 395 | pub async fn read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> { | 395 | pub async fn read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> { |
| 396 | // Avoid blocking_wait_ready() blocking forever on zero-length buffers. | ||
| 397 | if data.len() == 0 { | ||
| 398 | return Ok(()); | ||
| 399 | } | ||
| 400 | |||
| 396 | let ondrop = OnDrop::new(Self::blocking_wait_ready); | 401 | let ondrop = OnDrop::new(Self::blocking_wait_ready); |
| 397 | 402 | ||
| 398 | self.start_read(address, data)?; | 403 | self.start_read(address, data)?; |
| @@ -409,6 +414,11 @@ impl<'d, T: Instance> Qspi<'d, T> { | |||
| 409 | /// against the flash capacity. It is intended for use when QSPI is used as | 414 | /// against the flash capacity. It is intended for use when QSPI is used as |
| 410 | /// a raw bus, not with flash memory. | 415 | /// a raw bus, not with flash memory. |
| 411 | pub async fn write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> { | 416 | pub async fn write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> { |
| 417 | // Avoid blocking_wait_ready() blocking forever on zero-length buffers. | ||
| 418 | if data.len() == 0 { | ||
| 419 | return Ok(()); | ||
| 420 | } | ||
| 421 | |||
| 412 | let ondrop = OnDrop::new(Self::blocking_wait_ready); | 422 | let ondrop = OnDrop::new(Self::blocking_wait_ready); |
| 413 | 423 | ||
| 414 | self.start_write(address, data)?; | 424 | self.start_write(address, data)?; |
| @@ -425,6 +435,11 @@ impl<'d, T: Instance> Qspi<'d, T> { | |||
| 425 | /// against the flash capacity. It is intended for use when QSPI is used as | 435 | /// against the flash capacity. It is intended for use when QSPI is used as |
| 426 | /// a raw bus, not with flash memory. | 436 | /// a raw bus, not with flash memory. |
| 427 | pub fn blocking_read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> { | 437 | pub fn blocking_read_raw(&mut self, address: u32, data: &mut [u8]) -> Result<(), Error> { |
| 438 | // Avoid blocking_wait_ready() blocking forever on zero-length buffers. | ||
| 439 | if data.len() == 0 { | ||
| 440 | return Ok(()); | ||
| 441 | } | ||
| 442 | |||
| 428 | self.start_read(address, data)?; | 443 | self.start_read(address, data)?; |
| 429 | Self::blocking_wait_ready(); | 444 | Self::blocking_wait_ready(); |
| 430 | Ok(()) | 445 | Ok(()) |
| @@ -436,6 +451,11 @@ impl<'d, T: Instance> Qspi<'d, T> { | |||
| 436 | /// against the flash capacity. It is intended for use when QSPI is used as | 451 | /// against the flash capacity. It is intended for use when QSPI is used as |
| 437 | /// a raw bus, not with flash memory. | 452 | /// a raw bus, not with flash memory. |
| 438 | pub fn blocking_write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> { | 453 | pub fn blocking_write_raw(&mut self, address: u32, data: &[u8]) -> Result<(), Error> { |
| 454 | // Avoid blocking_wait_ready() blocking forever on zero-length buffers. | ||
| 455 | if data.len() == 0 { | ||
| 456 | return Ok(()); | ||
| 457 | } | ||
| 458 | |||
| 439 | self.start_write(address, data)?; | 459 | self.start_write(address, data)?; |
| 440 | Self::blocking_wait_ready(); | 460 | Self::blocking_wait_ready(); |
| 441 | Ok(()) | 461 | Ok(()) |
