diff options
| author | Ian McIntyre <me@mciantyre.dev> | 2026-10-26 17:53:21 -0400 |
|---|---|---|
| committer | Ian McIntyre <me@mciantyre.dev> | 2026-10-27 11:35:22 -0400 |
| commit | f0ef2b86cee6b44e801eb80ba301888a608fdd76 (patch) | |
| tree | 23251fe48a1d14c53fd002abd3d49060ddd0258e | |
| parent | efe328a7bd17df1962a1db2a517c79f1e76a7b05 (diff) | |
Add ECC stress test for 1170EVK testing
A little firmware that you can run on your 11xx with ECC RAM active.
If I'm doing the preloading correctly and considering speculative reads
into unused memory, this test should pass. Right now, it definitely does
not pass, since the __pre_init only (maybe) zeros the program sections.
| -rw-r--r-- | Cargo.toml | 5 | ||||
| -rw-r--r-- | board/src/imxrt1170evk_cm7.rs | 6 | ||||
| -rw-r--r-- | board/src/lib.rs | 2 | ||||
| -rw-r--r-- | examples/rip_through_ram.rs | 211 |
4 files changed, 223 insertions, 1 deletions
@@ -23,6 +23,7 @@ cortex-m-rt = { version = "0.7.3", features = ["set-vtor", "set-sp"] } [target.'cfg(all(target_arch = "arm", target_os = "none"))'.dev-dependencies] board = { path = "board" } cortex-m-rtic = { version = "1.0" } +rtt-target = { version = "0.3", features = ["cortex-m"] } [target.'cfg(not(all(target_arch = "arm", target_os = "none")))'.dev-dependencies] goblin = "0.5" @@ -31,6 +32,10 @@ goblin = "0.5" name = "blink-rtic" required-features = ["board/rtic"] +[[example]] +name = "rip_through_ram" +required-features = ["board/imxrt1170evk-cm7"] + [workspace] members = [ "board", diff --git a/board/src/imxrt1170evk_cm7.rs b/board/src/imxrt1170evk_cm7.rs index f1a72d7..089c9e8 100644 --- a/board/src/imxrt1170evk_cm7.rs +++ b/board/src/imxrt1170evk_cm7.rs @@ -14,6 +14,12 @@ pub mod rtic_support { #[allow(non_snake_case)] // For RTIC trickery... pub mod Interrupt { pub const PIT: crate::ral::Interrupt = crate::ral::Interrupt::PIT1; + pub const FLEXRAM: crate::ral::Interrupt = crate::ral::Interrupt::FLEXRAM; + pub const FLEXRAM_ECC: crate::ral::Interrupt = crate::ral::Interrupt::FLEXRAM_ECC; + pub const MECC1_INT: crate::ral::Interrupt = crate::ral::Interrupt::MECC1_INT; + pub const MECC1_FATAL_INT: crate::ral::Interrupt = crate::ral::Interrupt::MECC1_FATAL_INT; + pub const MECC2_INT: crate::ral::Interrupt = crate::ral::Interrupt::MECC2_INT; + pub const MECC2_FATAL_INT: crate::ral::Interrupt = crate::ral::Interrupt::MECC2_FATAL_INT; } pub use Interrupt as interrupt; } diff --git a/board/src/lib.rs b/board/src/lib.rs index ebc76ad..fa2afcd 100644 --- a/board/src/lib.rs +++ b/board/src/lib.rs @@ -1,7 +1,7 @@ //! A very simple, multi-board BSP for imxrt-rt-support examples. #![no_std] -use imxrt_ral as ral; +pub use imxrt_ral as ral; cfg_if::cfg_if! { if #[cfg(feature = "teensy4")] { diff --git a/examples/rip_through_ram.rs b/examples/rip_through_ram.rs new file mode 100644 index 0000000..9eee493 --- /dev/null +++ b/examples/rip_through_ram.rs @@ -0,0 +1,211 @@ +//! Read through all of ITCM, DTCM, and OCRAM. +//! +//! Useful for stress testing ECC RAM. This program should complete +//! without activating any ECC RAM faults, provided the runtime has +//! preloaded all of RAM. +//! +//! This program assumes the layout specified in board/build.rs for +//! the 1170EVK. + +#![no_std] +#![no_main] + +const ITCM: (usize, usize) = (0x0000_0000, 0x0000_0000 + 256 * 1024); +const DTCM: (usize, usize) = (0x2000_0000, 0x2000_0000 + 256 * 1024); +const OCRAM: (usize, usize) = (0x2024_0000, 0x2024_0000 + 1024 * 1024); + +// Single- and multi-bit errors in all three regions. +const FLEXRAM_STATUS_MASK: u32 = 0x3FC0; +// Single- and multi-bit errors in all banks. +const OCRAM_STATUS_MASK: u32 = 0xFFFF; + +#[rtic::app(device = board::rtic_support, peripherals = false)] +mod app { + use board::ral; + + #[local] + struct Local { + led: board::Led, + flexram: ral::flexram::FLEXRAM, + mecc1: ral::mecc::MECC1, + mecc2: ral::mecc::MECC2, + } + + #[shared] + struct Shared {} + + #[init] + fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + let board::Resources { led, .. } = board::prepare(1_000_000).unwrap(); + let flexram = unsafe { ral::flexram::FLEXRAM::instance() }; + let mecc1 = unsafe { ral::mecc::MECC1::instance() }; + let mecc2 = unsafe { ral::mecc::MECC2::instance() }; + + ral::write_reg!( + ral::flexram, + flexram, + INT_STAT_EN, + crate::FLEXRAM_STATUS_MASK + ); + ral::write_reg!( + ral::flexram, + flexram, + INT_SIG_EN, + crate::FLEXRAM_STATUS_MASK + ); + + ral::write_reg!(ral::mecc, mecc1, ERR_STAT_EN, crate::OCRAM_STATUS_MASK); + ral::write_reg!(ral::mecc, mecc2, ERR_STAT_EN, crate::OCRAM_STATUS_MASK); + ral::write_reg!(ral::mecc, mecc1, ERR_SIG_EN, crate::OCRAM_STATUS_MASK); + ral::write_reg!(ral::mecc, mecc2, ERR_SIG_EN, crate::OCRAM_STATUS_MASK); + + ( + Shared {}, + Local { + led, + flexram, + mecc1, + mecc2, + }, + init::Monotonics(), + ) + } + + #[idle(local = [led, flexram, mecc1, mecc2])] + fn idle(cx: idle::Context) -> ! { + rtt_target::rprintln!("Starting to read all of RAM..."); + for (start, end) in [crate::ITCM, crate::DTCM, crate::OCRAM] { + unsafe { crate::read_ram_range(start as *const u32, end as *const u32) }; + rtt_target::rprintln!("Completed range {:#010X} through {:#010X}", start, end); + } + + let int_status = ral::read_reg!(ral::flexram, cx.local.flexram, INT_STATUS); + assert_eq!(int_status, 0, "FlexRAM INT_STATUS: {int_status:#010X}"); + + let err_status_1 = ral::read_reg!(ral::mecc, cx.local.mecc1, ERR_STATUS); + let err_status_2 = ral::read_reg!(ral::mecc, cx.local.mecc2, ERR_STATUS); + + assert_eq!(err_status_1, 0, "MECC1 ERR_STATUS: {err_status_1:#010X}"); + assert_eq!(err_status_2, 0, "MECC2 ERR_STATUS: {err_status_2:#010X}"); + + rtt_target::rprintln!("OK"); + loop { + cx.local.led.set(); + } + } + + // Expected to be linked by today's board... + #[task(binds = PIT)] + fn pit(_: pit::Context) { + panic!("Unexpected PIT interrupt"); + } + + #[task(binds = FLEXRAM)] + fn flexram(_: flexram::Context) { + crate::flexram_report(&unsafe { ral::flexram::FLEXRAM::instance() }); + panic!("FLEXRAM"); + } + + #[task(binds = FLEXRAM_ECC)] + fn flexram_ecc(_: flexram_ecc::Context) { + crate::flexram_report(&unsafe { ral::flexram::FLEXRAM::instance() }); + panic!("FLEXRAM_ECC"); + } + + #[task(binds = MECC1_INT)] + fn mecc1(_: mecc1::Context) { + crate::mecc64_report(&unsafe { ral::mecc::MECC1::instance() }); + panic!("MECC1"); + } + + #[task(binds = MECC1_FATAL_INT)] + fn mecc1_fatal(_: mecc1_fatal::Context) { + crate::mecc64_report(&unsafe { ral::mecc::MECC1::instance() }); + panic!("MECC1_FATAL"); + } + + #[task(binds = MECC2_INT)] + fn mecc2(_: mecc2::Context) { + crate::mecc64_report(&unsafe { ral::mecc::MECC2::instance() }); + panic!("MECC2"); + } + + #[task(binds = MECC2_FATAL_INT)] + fn mecc2_fatal(_: mecc2_fatal::Context) { + crate::mecc64_report(&unsafe { ral::mecc::MECC2::instance() }); + panic!("MECC2_FATAL"); + } +} + +use board::ral; + +fn flexram_report(flexram: &ral::flexram::FLEXRAM) { + macro_rules! print_regs { + ($($reg:ident),* $(,)?) => { + $( + let value = ral::read_reg!(ral::flexram, flexram, $reg); + rtt_target::rprintln!("FlexRAM {}: {:#010X}", stringify!($reg), value); + )* + }; + } + + print_regs!( + INT_STATUS, + ITCM_ECC_SINGLE_ERROR_INFO, + ITCM_ECC_SINGLE_ERROR_ADDR, + ITCM_ECC_MULTI_ERROR_INFO, + ITCM_ECC_MULTI_ERROR_ADDR, + D0TCM_ECC_SINGLE_ERROR_INFO, + D0TCM_ECC_SINGLE_ERROR_ADDR, + D0TCM_ECC_MULTI_ERROR_INFO, + D0TCM_ECC_MULTI_ERROR_ADDR, + D1TCM_ECC_SINGLE_ERROR_INFO, + D1TCM_ECC_SINGLE_ERROR_ADDR, + D1TCM_ECC_MULTI_ERROR_INFO, + D1TCM_ECC_MULTI_ERROR_ADDR, + ); +} + +fn mecc64_report<const N: u8>(mecc: &ral::mecc::Instance<N>) { + macro_rules! print_regs { + ($($reg:ident),* $(,)?) => { + $( + let value = ral::read_reg!(ral::mecc, mecc, $reg); + rtt_target::rprintln!("MECC{} {}: {:#010X}", N, stringify!($reg), value); + )* + }; + } + + print_regs!( + ERR_STATUS, + SINGLE_ERR_ADDR_ECC0, + SINGLE_ERR_ADDR_ECC1, + SINGLE_ERR_ADDR_ECC2, + SINGLE_ERR_ADDR_ECC3, + MULTI_ERR_ADDR_ECC0, + MULTI_ERR_ADDR_ECC1, + MULTI_ERR_ADDR_ECC2, + MULTI_ERR_ADDR_ECC3, + ); +} + +#[unsafe(naked)] +unsafe extern "C" fn read_ram_range(start: *const u32, end: *const u32) { + core::arch::naked_asm!( + "1:", + "cmp r0, r1", + "beq 2f", + "ldrd r2, r3, [r0], #8", + "b 1b", + "2:", + "bx lr", + ) +} + +use imxrt_rt::exception; + +#[exception] +unsafe fn DefaultHandler(i: i16) { + crate::flexram_report(&unsafe { ral::flexram::FLEXRAM::instance() }); + panic!("DefaultHandler {i}"); +} |
