aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-12-03 23:21:32 +0100
committerGitHub <[email protected]>2023-12-03 23:21:32 +0100
commit521cdef8a1c134dfe8cadd84914ec5e1ce227673 (patch)
tree2136d97762f4589244102eb3a01ee669f1d9e066
parent1dc31c4627d934e7aae2175601ff6d1328c11890 (diff)
parent9fb2eb7470d56d94bd8687b7566d60c3837df3a2 (diff)
Merge pull request #2245 from peter9477/nrf52-qspi-zerolen-fix
nrf52/qspi: avoid infinite busy-wait read/write with zero-len buf
-rwxr-xr-x[-rw-r--r--]embassy-nrf/src/qspi.rs22
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(())