From 21e59885e3b6e5c9a9271dd645b76c66095a4d86 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 8 Nov 2024 00:17:42 +0800 Subject: [PATCH] add some attempts to debug the SPIM lockup. for now, filing a bug agaisnt the IP block --- libs/cramium-hal/src/udma/spim.rs | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/libs/cramium-hal/src/udma/spim.rs b/libs/cramium-hal/src/udma/spim.rs index 69b9f2be4..5478b8e40 100644 --- a/libs/cramium-hal/src/udma/spim.rs +++ b/libs/cramium-hal/src/udma/spim.rs @@ -955,6 +955,33 @@ impl Spim { timeout += 1; if (self.mode == SpimMode::Quad) && (timeout > chunk.len() * 10_000) { success = false; + /* + // unsuccessful attempt to clear the pending transfer manually + // the root cause of this is when the UDMA RX FIFO fills up and + // RX packets get dropped. The Rx counter becomes "desynced" from the + // data stream, and thus it never hits 0 (it wraps around and goes negative). + // The code below does not recover the PHY into a usable state. + unsafe { + self.csr() + .base() + .add(Bank::Rx as usize) + .add(DmaReg::Cfg.into()) + .write_volatile(CFG_SIZE_8 | CFG_CLEAR); + self.csr().base().add(Bank::Rx as usize).add(DmaReg::Saddr.into()).write_volatile(0); + }; + // send an EOT + let cmd_list = [SpimCmd::EndXfer(SpimEventGen::Disabled)]; + self.send_cmd_list(&cmd_list); + crate::println!( + "udma timeout: cfg {:x}, saddr {:x}", + unsafe { + self.csr().base().add(Bank::Rx as usize).add(DmaReg::Cfg.into()).read_volatile() + }, + unsafe { + self.csr().base().add(Bank::Rx as usize).add(DmaReg::Saddr.into()).read_volatile() + } + ); + */ break; } #[cfg(feature = "std")] @@ -1018,3 +1045,24 @@ impl Spim { } } } + +// Stub retained because it is helpful for debugging some bus contention issues. +#[allow(dead_code)] +fn cache_flush() { + unsafe { + // let the write go through before continuing + #[rustfmt::skip] + core::arch::asm!( + ".word 0x500F", + "nop", + "nop", + "nop", + "nop", + "fence", + "nop", + "nop", + "nop", + "nop", + ); + } +}