From 363881b76610a992e2b2ece7aab2993369f6a9fe Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 28 Aug 2024 20:47:06 +1000 Subject: [PATCH] chips: apollo3: iom: Support non 4-byte alligned SPI writes Signed-off-by: Alistair Francis --- chips/apollo3/src/iom.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/chips/apollo3/src/iom.rs b/chips/apollo3/src/iom.rs index 722cb6cbfa..7c195a7be7 100644 --- a/chips/apollo3/src/iom.rs +++ b/chips/apollo3/src/iom.rs @@ -667,9 +667,15 @@ impl<'a> Iom<'_> { && transfered_bytes < 24 { let idx = self.write_index.get(); - let data = u32::from_le_bytes( - write_buffer[idx..(idx + 4)].try_into().unwrap_or([0; 4]), - ); + + let chunk = write_buffer[idx..].chunks(4).next().unwrap_or(&[]); + + let data = u32::from_le_bytes([ + chunk.get(0).copied().unwrap_or(0), + chunk.get(1).copied().unwrap_or(0), + chunk.get(2).copied().unwrap_or(0), + chunk.get(3).copied().unwrap_or(0), + ]); self.registers.fifopush.set(data); self.write_index.set(idx + 4);