From 24ea504e62d5da9da37747b76a95523310643524 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 6 May 2023 15:26:32 +0000 Subject: [PATCH 1/2] Remove on-target-tests/tests/dma_drop.rs This test didn't work, and it was unclear what it should test. --- on-target-tests/Cargo.toml | 4 - on-target-tests/tests/dma_drop.rs | 121 ------------------------------ 2 files changed, 125 deletions(-) delete mode 100644 on-target-tests/tests/dma_drop.rs diff --git a/on-target-tests/Cargo.toml b/on-target-tests/Cargo.toml index c3e3dc17c..b857ac147 100644 --- a/on-target-tests/Cargo.toml +++ b/on-target-tests/Cargo.toml @@ -24,10 +24,6 @@ harness = false name = "dma_spi_loopback_u16" harness = false -[[test]] -name = "dma_drop" -harness = false - [[test]] name = "dma_dyn" harness = false diff --git a/on-target-tests/tests/dma_drop.rs b/on-target-tests/tests/dma_drop.rs deleted file mode 100644 index ab13192f2..000000000 --- a/on-target-tests/tests/dma_drop.rs +++ /dev/null @@ -1,121 +0,0 @@ -#![no_std] -#![no_main] -#![cfg(test)] - -use crate::hal::dma::Channels; -use defmt_rtt as _; // defmt transport -use defmt_test as _; -use panic_probe as _; -use rp2040_hal as hal; // memory layout // panic handler - -/// The linker will place this boot block at the start of our program image. We -/// need this to help the ROM bootloader get our code up and running. -/// Note: This boot block is not necessary when using a rp-hal based BSP -/// as the BSPs already perform this step. -#[link_section = ".boot2"] -#[used] -pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H; - -/// External high-speed crystal on the Raspberry Pi Pico board is 12 MHz. Adjust -/// if your board has a different frequency -const XTAL_FREQ_HZ: u32 = 12_000_000u32; - -struct State { - channels: Option, -} - -mod testdata { - #[allow(dead_code)] - pub const ARRAY_U8: [u8; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - #[allow(dead_code)] - pub const ARRAY_U16: [u16; 10] = [270, 271, 272, 273, 274, 275, 276, 277, 278, 279]; - #[allow(dead_code)] - pub const ARRAY_U32: [u32; 10] = [ - 65571, 65572, 65573, 65574, 65575, 65576, 65577, 65578, 65579, 65580, - ]; - #[allow(dead_code)] - pub const ARRAY_U64: [u64; 10] = [ - 65571, 65572, 65573, 65574, 65575, 65576, 65577, 65578, 65579, 65580, - ]; -} - -#[defmt_test::tests] -mod tests { - use crate::testdata; - use crate::State; - use crate::XTAL_FREQ_HZ; - use defmt::assert_eq; - use defmt_rtt as _; - use panic_probe as _; - use rp2040_hal as hal; - - use hal::{clocks::init_clocks_and_plls, pac, watchdog::Watchdog}; - - use rp2040_hal::dma::DMAExt; - - #[init] - fn setup() -> State { - unsafe { - hal::sio::spinlock_reset(); - } - let mut pac = pac::Peripherals::take().unwrap(); - let _core = pac::CorePeripherals::take().unwrap(); - let mut watchdog = Watchdog::new(pac.WATCHDOG); - - let _clocks = init_clocks_and_plls( - XTAL_FREQ_HZ, - pac.XOSC, - pac.CLOCKS, - pac.PLL_SYS, - pac.PLL_USB, - &mut pac.RESETS, - &mut watchdog, - ) - .ok() - .unwrap(); - - let dma = pac.DMA.split(&mut pac.RESETS); - - State { - channels: Some(dma), - } - } - - #[test] - fn droptest_runfirst(state: &mut State) { - let dma = state - .channels - .take() - .expect("Failed to take Channels, not dropped correctly"); - - let rx_buffer = cortex_m::singleton!(: [u8; 10] = [0; 10]).unwrap(); - let tx_buffer = cortex_m::singleton!(: [u8; 10] = testdata::ARRAY_U8).unwrap(); - let tx_transfer = hal::dma::single_buffer::Config::new(dma.ch0, tx_buffer, rx_buffer); - let tx_started = tx_transfer.start(); - let (_ch0, tx_buffer, rx_buffer) = tx_started.wait(); - let first = tx_buffer.iter(); - let second = rx_buffer.iter(); - for (x, y) in first.zip(second) { - assert_eq!(x, y); - } - } - - #[test] - fn droptest_runsecond(state: &mut State) { - let dma = state - .channels - .take() - .expect("Failed to take Channels, not dropped correctly"); - - let rx_buffer = cortex_m::singleton!(: [u8; 10] = [0; 10]).unwrap(); - let tx_buffer = cortex_m::singleton!(: [u8; 10] = testdata::ARRAY_U8).unwrap(); - let tx_transfer = hal::dma::single_buffer::Config::new(dma.ch0, tx_buffer, rx_buffer); - let tx_started = tx_transfer.start(); - let (_ch0, tx_buffer, rx_buffer) = tx_started.wait(); - let first = tx_buffer.iter(); - let second = rx_buffer.iter(); - for (x, y) in first.zip(second) { - assert_eq!(x, y); - } - } -} From 8ac9115db4d51ed1a5fda9ed6d5c1a6396f8280e Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 6 May 2023 15:29:24 +0000 Subject: [PATCH 2/2] Document on-target tests --- on-target-tests/README.md | 12 ++++++++++++ on-target-tests/tests/dma_spi_loopback_u16.rs | 2 ++ on-target-tests/tests/dma_spi_loopback_u8.rs | 2 ++ 3 files changed, 16 insertions(+) diff --git a/on-target-tests/README.md b/on-target-tests/README.md index 81b957cd0..ea217370e 100644 --- a/on-target-tests/README.md +++ b/on-target-tests/README.md @@ -21,3 +21,15 @@ To run a specific test (to make developing tests faster) ```system CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER=probe-run cargo test --test my_new_test -- --chip rp2040 ``` + +## Prerequisites + +Some of the tests need connections between specific pins. + +Currently, the following connections are required: + +- Connect GPIO 4 to GPIO 7 (pins 6 and 10 an a Pico) for the SPI loopback tests + +If you add tests that need some hardware setup, make sure that they are +compatible to the existing on-target tests, so all tests can be run with +a single configuration. diff --git a/on-target-tests/tests/dma_spi_loopback_u16.rs b/on-target-tests/tests/dma_spi_loopback_u16.rs index b6e4d094b..98bc2ea2b 100644 --- a/on-target-tests/tests/dma_spi_loopback_u16.rs +++ b/on-target-tests/tests/dma_spi_loopback_u16.rs @@ -1,3 +1,5 @@ +//! This test needs a connection between GPIO 4 and GPIO 7 (pins 6 and 10 an a Pico) + #![no_std] #![no_main] #![cfg(test)] diff --git a/on-target-tests/tests/dma_spi_loopback_u8.rs b/on-target-tests/tests/dma_spi_loopback_u8.rs index 12339bd6a..138b5d141 100644 --- a/on-target-tests/tests/dma_spi_loopback_u8.rs +++ b/on-target-tests/tests/dma_spi_loopback_u8.rs @@ -1,3 +1,5 @@ +//! This test needs a connection between GPIO 4 and GPIO 7 (pins 6 and 10 an a Pico) + #![no_std] #![no_main] #![cfg(test)]