Skip to content

Commit

Permalink
Reset core1 at top of on-target tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jannic committed Feb 6, 2025
1 parent 47e2abf commit c24c77a
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 14 deletions.
4 changes: 3 additions & 1 deletion on-target-tests/tests/dma_dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ mod testdata {
];
}

mod init;

#[defmt_test::tests]
mod tests {
use crate::testdata;
Expand All @@ -73,7 +75,7 @@ mod tests {
#[init]
fn setup() -> State {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down
4 changes: 3 additions & 1 deletion on-target-tests/tests/dma_m2m_u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ mod testdata {
];
}

mod init;

#[defmt_test::tests]
mod tests {
use crate::testdata;
Expand All @@ -69,7 +71,7 @@ mod tests {
#[init]
fn setup() -> State {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down
4 changes: 3 additions & 1 deletion on-target-tests/tests/dma_m2m_u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ mod testdata {
];
}

mod init;

#[defmt_test::tests]
mod tests {
use crate::testdata;
Expand All @@ -69,7 +71,7 @@ mod tests {
#[init]
fn setup() -> State {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down
4 changes: 3 additions & 1 deletion on-target-tests/tests/dma_m2m_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ mod testdata {
];
}

mod init;

#[defmt_test::tests]
mod tests {
use crate::testdata;
Expand All @@ -69,7 +71,7 @@ mod tests {
#[init]
fn setup() -> State {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down
4 changes: 3 additions & 1 deletion on-target-tests/tests/dma_spi_loopback_u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ mod testdata {
];
}

mod init;

#[defmt_test::tests]
mod tests {
use crate::testdata;
Expand All @@ -78,7 +80,7 @@ mod tests {
#[init]
fn setup() -> State {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down
4 changes: 3 additions & 1 deletion on-target-tests/tests/dma_spi_loopback_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct State {
spi: Option<spi::Spi<spi::Enabled, SPI0, (MOSI, MISO, SCLK), 8>>,
}

mod init;

mod testdata {
#[allow(dead_code)]
pub const ARRAY_U8: [u8; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
Expand Down Expand Up @@ -79,7 +81,7 @@ mod tests {
#[init]
fn setup() -> State {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down
4 changes: 3 additions & 1 deletion on-target-tests/tests/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
/// if your board has a different frequency
const XTAL_FREQ_HZ: u32 = 12_000_000u32;

mod init;

#[defmt_test::tests]
mod tests {
use crate::hal;
Expand All @@ -41,7 +43,7 @@ mod tests {
#[init]
fn setup() -> () {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down
2 changes: 2 additions & 0 deletions on-target-tests/tests/i2c_loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
const XTAL_FREQ_HZ: u32 = 12_000_000u32;

pub mod i2c_tests;
mod init;

#[interrupt]
unsafe fn I2C1_IRQ() {
Expand All @@ -51,6 +52,7 @@ mod tests {

#[init]
fn setup() -> State {
unsafe { crate::init::reset_cleanup() };
i2c_tests::blocking::setup(super::XTAL_FREQ_HZ, ADDR_7BIT)
}

Expand Down
2 changes: 2 additions & 0 deletions on-target-tests/tests/i2c_loopback_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
const XTAL_FREQ_HZ: u32 = 12_000_000u32;

pub mod i2c_tests;
mod init;

#[interrupt]
unsafe fn I2C0_IRQ() {
Expand All @@ -59,6 +60,7 @@ mod tests {

#[init]
fn setup() -> State {
unsafe { crate::init::reset_cleanup() };
non_blocking::setup(super::XTAL_FREQ_HZ, ADDR_7BIT)
}

Expand Down
3 changes: 0 additions & 3 deletions on-target-tests/tests/i2c_tests/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ macro_rules! assert_restart_count {
}

pub fn setup<T: ValidAddress>(xtal_freq_hz: u32, addr: T) -> State {
unsafe {
hal::sio::spinlock_reset();
}
let mut pac = pac::Peripherals::take().unwrap();
let mut watchdog = Watchdog::new(pac.WATCHDOG);

Expand Down
3 changes: 0 additions & 3 deletions on-target-tests/tests/i2c_tests/non_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ async fn wait_with(payload: &RefCell<TargetState>, mut f: impl FnMut(&TargetStat
}

pub fn setup<T: ValidAddress>(xtal_freq_hz: u32, addr: T) -> State {
unsafe {
hal::sio::spinlock_reset();
}
let mut pac = pac::Peripherals::take().unwrap();
let mut watchdog = Watchdog::new(pac.WATCHDOG);

Expand Down
24 changes: 24 additions & 0 deletions on-target-tests/tests/init/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[cfg(feature = "rp2040")]
use rp2040_hal as hal;
#[cfg(feature = "rp235x")]
use rp235x_hal as hal;

use hal::pac;

/// When test cases are run from a debugger, there may not be a complete
/// system reset between test cases. To get clean initial conditions, reset
/// core1 and spinlocks.
///
/// This must only be called immediatly after booting core0, ie. at the start
/// of the `#[init]` function.
pub unsafe fn reset_cleanup() {
unsafe {
(*pac::PSM::PTR).frce_off().modify(|_, w| w.proc1().set_bit());
while !(*pac::PSM::PTR).frce_off().read().proc1().bit_is_set() {
cortex_m::asm::nop();
}
(*pac::PSM::PTR).frce_off().modify(|_, w| w.proc1().clear_bit());
hal::sio::spinlock_reset();
}
}

4 changes: 3 additions & 1 deletion on-target-tests/tests/multicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static STATE: AtomicU8 = AtomicU8::new(0);
static COUNTER: AtomicU32 = AtomicU32::new(0);
const STEPS: u32 = 100000;

mod init;

#[defmt_test::tests]
mod tests {
use crate::hal;
Expand All @@ -53,7 +55,7 @@ mod tests {
#[init]
fn setup() -> () {
unsafe {
hal::sio::spinlock_reset();
crate::init::reset_cleanup();
}
let mut pac = pac::Peripherals::take().unwrap();
#[cfg(feature = "rp2040")]
Expand Down

0 comments on commit c24c77a

Please sign in to comment.