From 13702f2df05dbbff5f2ecb0c33213e53ba8bb06e Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 22 Nov 2024 15:23:38 +0800 Subject: [PATCH 1/7] fix unit test to match actual testbench tooling --- libs/xous-bio-bdma/src/bio_tests/units.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/xous-bio-bdma/src/bio_tests/units.rs b/libs/xous-bio-bdma/src/bio_tests/units.rs index 1d6c4c7fb..840dad168 100644 --- a/libs/xous-bio-bdma/src/bio_tests/units.rs +++ b/libs/xous-bio-bdma/src/bio_tests/units.rs @@ -318,10 +318,11 @@ pub fn host_fifo_tests() -> usize { // // finally, we're pegged at 15, because, backpressure caused us to miss the rest of // the entries, and we are stuck at the final written value of the output test + print!("rbk: {:x}\r", rbk); if i <= 9 { - assert!(rbk == !(0xF1F0_0000 + i)); + assert!(rbk == (0xF1F0_0000 + i)); } else { - assert!(rbk == !(0xF1F0_0000 + 15)); + assert!(rbk == (0xF1F0_0000 + 15)); } print!("backpressure {:x}\r", rbk); } From 3738db9f5cae40c1add8149088d0df2f01581b9f Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 28 Nov 2024 01:28:39 +0800 Subject: [PATCH 2/7] fix io-direction issue in testbench --- libs/xous-bio-bdma/src/bio_tests/units.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/xous-bio-bdma/src/bio_tests/units.rs b/libs/xous-bio-bdma/src/bio_tests/units.rs index 840dad168..31673011d 100644 --- a/libs/xous-bio-bdma/src/bio_tests/units.rs +++ b/libs/xous-bio-bdma/src/bio_tests/units.rs @@ -403,7 +403,7 @@ pub fn host_fifo_tests() -> usize { bio_code!(fifo_host0_bitbang, FIFO_HOST0_BITBANG_START, FIFO_HOST0_BITBANG_END, "li t0, 0xFFFFFFFF", "mv x26, t0", // ensure mask is disabled - "mv x25, t0", // set all pins to inputs + "mv x24, t0", // set all pins to outputs "90:", "mv x21, x16", "mv x20, zero", From 6e8bff749c1b6c0bef243e77d44bad998fd2947b Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 28 Nov 2024 15:07:43 +0800 Subject: [PATCH 3/7] eliminate invalid PLL transition this transition was in the reference C code, but in verilog simulation it turns out it activates the PLL in an invalid mode which can lead to glitching. Removing this makes both the simulation happy and presumably the PLL happier as well. --- loader/src/platform/cramium/cramium.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/loader/src/platform/cramium/cramium.rs b/loader/src/platform/cramium/cramium.rs index c1e915202..5b8f51a61 100644 --- a/loader/src/platform/cramium/cramium.rs +++ b/loader/src/platform/cramium/cramium.rs @@ -1415,14 +1415,6 @@ unsafe fn init_clock_asic(freq_hz: u32) -> u32 { crate::println!("pllq: 0x{:x}, pllmn: 0x{:x}, n_frac: 0x{:x}", pllq, pllmn, n_frac); - daric_cgu.add(sysctrl::SFR_CGUSEL1.offset()).write_volatile(1); // 0: RC, 1: XTAL - daric_cgu.add(sysctrl::SFR_CGUFSCR.offset()).write_volatile(48); // external crystal is 48MHz - daric_cgu.add(sysctrl::SFR_CGUSET.offset()).write_volatile(0x32); - - if freq_hz < 1_000_000 { - daric_cgu.add(sysctrl::SFR_IPCOSC.offset()).write_volatile(freq_hz); - daric_cgu.add(sysctrl::SFR_IPCARIPFLOW.offset()).write_volatile(0x32); // commit, must write 32 - } // switch to OSC daric_cgu.add(sysctrl::SFR_CGUSEL0.offset()).write_volatile(0); // clktop sel, 0:clksys, 1:clkpll0 daric_cgu.add(sysctrl::SFR_CGUSET.offset()).write_volatile(0x32); // commit From 861b7ae3ff3932e5685b422457f743abc20b27a9 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 28 Nov 2024 15:32:19 +0800 Subject: [PATCH 4/7] compromise on oscillator setting I felt uncomfortable leaving the oscillator setting entirely outside the PLL routine, so as a compromise I defer the oscillator switch-over until after the initial PLL settings are loaded. This makes both the simulation model and the actual hardware happy. I think probably what the simulation model *should* have done is consider the "powerdown" pin when checking the validity of the signals going into the PLL model - but this is impossible to modify/check because the PLL is provided as an encrypted blob :( --- loader/src/platform/cramium/cramium.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/loader/src/platform/cramium/cramium.rs b/loader/src/platform/cramium/cramium.rs index 5b8f51a61..e63e051a9 100644 --- a/loader/src/platform/cramium/cramium.rs +++ b/loader/src/platform/cramium/cramium.rs @@ -1422,7 +1422,7 @@ unsafe fn init_clock_asic(freq_hz: u32) -> u32 { if 0 == freq_hz { // do nothing } else { - // PD PLL + // powerdown PLL daric_cgu .add(sysctrl::SFR_IPCLPEN.offset()) .write_volatile(daric_cgu.add(sysctrl::SFR_IPCLPEN.offset()).read_volatile() | 0x02); @@ -1445,6 +1445,17 @@ unsafe fn init_clock_asic(freq_hz: u32) -> u32 { // daric_cgu.add(sysctrl::SFR_IPCCR.offset()).write_volatile((3 << 6) | (5 << 3) | (5)); daric_cgu.add(sysctrl::SFR_IPCARIPFLOW.offset()).write_volatile(0x32); // commit, must write 32 + // ensure the correct oscillator is selected here. It's put after the PLL is configured + // to ensure the PLL doesn't get edges while in an invalid configuration. + daric_cgu.add(sysctrl::SFR_CGUSEL1.offset()).write_volatile(1); // 0: RC, 1: XTAL + daric_cgu.add(sysctrl::SFR_CGUFSCR.offset()).write_volatile(48); // external crystal is 48MHz + daric_cgu.add(sysctrl::SFR_CGUSET.offset()).write_volatile(0x32); + + if freq_hz < 1_000_000 { + daric_cgu.add(sysctrl::SFR_IPCOSC.offset()).write_volatile(freq_hz); + daric_cgu.add(sysctrl::SFR_IPCARIPFLOW.offset()).write_volatile(0x32); // commit, must write 32 + } + daric_cgu .add(sysctrl::SFR_IPCLPEN.offset()) .write_volatile(daric_cgu.add(sysctrl::SFR_IPCLPEN.offset()).read_volatile() & !0x02); From a3619618d02507055b46afc03a253a3729a9e0d5 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 28 Nov 2024 15:53:12 +0800 Subject: [PATCH 5/7] slow down toggle rate on i2c so it is compatible with slow pullups the strict verilog model has weak pull-ups which model the "slowness" of the rise with an extended Z-condition that takes 3us to pull up to a solid 1. --- libs/xous-bio-bdma/src/bio_tests/i2c.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/xous-bio-bdma/src/bio_tests/i2c.rs b/libs/xous-bio-bdma/src/bio_tests/i2c.rs index 635bf63e3..d4fe67cdd 100644 --- a/libs/xous-bio-bdma/src/bio_tests/i2c.rs +++ b/libs/xous-bio-bdma/src/bio_tests/i2c.rs @@ -22,7 +22,7 @@ pub fn i2c_test() -> usize { // configure & run the 0th machine // 400kHz clock -> 100kHz toggle rate = 0x7D0_0000 @ 800MHz rate FCLK // 1600kHz clock -> 400kHz toggle rate = 0x1F4_0000 @ 800MHz rate FCLK - bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x1F4_0000); + bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x7D0_0000); // clear all events bio_ss.bio.wfo(utra::bio_bdma::SFR_EVENT_CLR_SFR_EVENT_CLR, 0xFFFF_FF); From ffb00cf6ad36f4d13dd85833950e50b355a95288 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 28 Nov 2024 16:14:14 +0800 Subject: [PATCH 6/7] turns out it helps if you put explicit pull-ups on the I/Os reverting this change --- libs/xous-bio-bdma/src/bio_tests/i2c.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/xous-bio-bdma/src/bio_tests/i2c.rs b/libs/xous-bio-bdma/src/bio_tests/i2c.rs index d4fe67cdd..635bf63e3 100644 --- a/libs/xous-bio-bdma/src/bio_tests/i2c.rs +++ b/libs/xous-bio-bdma/src/bio_tests/i2c.rs @@ -22,7 +22,7 @@ pub fn i2c_test() -> usize { // configure & run the 0th machine // 400kHz clock -> 100kHz toggle rate = 0x7D0_0000 @ 800MHz rate FCLK // 1600kHz clock -> 400kHz toggle rate = 0x1F4_0000 @ 800MHz rate FCLK - bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x7D0_0000); + bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x1F4_0000); // clear all events bio_ss.bio.wfo(utra::bio_bdma::SFR_EVENT_CLR_SFR_EVENT_CLR, 0xFFFF_FF); From 2dddae34fc6b4fd63a5a3c2bb3257d56920311a2 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 28 Nov 2024 18:27:52 +0800 Subject: [PATCH 7/7] add udma stresstest feature --- libs/cramium-hal/Cargo.toml | 3 +++ libs/cramium-hal/src/udma/mod.rs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/libs/cramium-hal/Cargo.toml b/libs/cramium-hal/Cargo.toml index e6586e606..170a0f199 100644 --- a/libs/cramium-hal/Cargo.toml +++ b/libs/cramium-hal/Cargo.toml @@ -32,6 +32,9 @@ board-baosec = [] # USB form factor token board-baosor = [] # Precursor form factor board-dabao = [] # Dev board form factor +udma-stress-test = [ +] # For RTL simulation testing - aggravates a key corner case + compress-entropy = [] magic-manual = [] std = ["log", "xous-api-names", "usb-device", "xous-api-ticktimer"] diff --git a/libs/cramium-hal/src/udma/mod.rs b/libs/cramium-hal/src/udma/mod.rs index d0013e68c..19da2b93b 100644 --- a/libs/cramium-hal/src/udma/mod.rs +++ b/libs/cramium-hal/src/udma/mod.rs @@ -426,6 +426,15 @@ pub trait Udma { } } fn udma_busy(&self, bank: Bank) -> bool { + // create dummy traffic on IFRAM that causes stall conditions on the bus + // the write is totally bogus and + #[cfg(feature = "udma-stress-test")] + for i in 0..12 { + unsafe { + let ifram_tickle = 0x5000_0000 as *mut u32; + ifram_tickle.add(i).write_volatile(i as u32); + } + } // Safety: only safe when used in the context of UDMA registers. unsafe { let saddr = self.csr().base().add(bank as usize).add(DmaReg::Saddr.into()).read_volatile();