From 871700f05dbd30aac71d6a3b5446e7743a18b90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Gr=C3=B6nlund?= Date: Sat, 31 Dec 2022 16:25:37 +0100 Subject: [PATCH] Fixed length for wlan_read. The length provided in command word for FUNC_WLAN READ, should describe the actual bytes requested, not the size of the buffer which is sized in u32. --- src/bus.rs | 7 ++++--- src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index f220cffc..f64c0abb 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -48,11 +48,12 @@ where assert_eq!(val, TEST_PATTERN); } - pub async fn wlan_read(&mut self, buf: &mut [u32]) { - let cmd = cmd_word(READ, INC_ADDR, FUNC_WLAN, 0, buf.len() as u32 * 4); + pub async fn wlan_read(&mut self, buf: &mut [u32], len_in_u8: u32) { + let cmd = cmd_word(READ, INC_ADDR, FUNC_WLAN, 0, len_in_u8); + let len_in_u32 = (len_in_u8 as usize + 3) / 4; transaction!(&mut self.spi, |bus| async { bus.write(&[cmd]).await?; - bus.read(buf).await?; + bus.read(&mut buf[..len_in_u32]).await?; Ok(()) }) .await diff --git a/src/lib.rs b/src/lib.rs index fa73b32e..a606d6be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -687,7 +687,7 @@ where if status & STATUS_F2_PKT_AVAILABLE != 0 { let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; - self.bus.wlan_read(&mut buf[..(len as usize + 3) / 4]).await; + self.bus.wlan_read(&mut buf, len).await; trace!("rx {:02x}", &slice8_mut(&mut buf)[..(len as usize).min(48)]); self.rx(&slice8_mut(&mut buf)[..len as usize]); }