diff options
| author | Mathias <[email protected]> | 2022-08-26 12:50:12 +0200 |
|---|---|---|
| committer | Mathias <[email protected]> | 2022-08-26 12:55:15 +0200 |
| commit | bd27b9080fd9019e69e84fd30894a71db9fd61b5 (patch) | |
| tree | 9627c002b0b38278b296f315be73d8951d8fa0d1 /tests | |
| parent | b88ef032141e87411dabb5d90ef488f5d6af2285 (diff) | |
Add HIL tests of DMA & UART, and correctly set DREQ for uart DMA
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/src/bin/dma_copy_async.rs | 41 | ||||
| -rw-r--r-- | tests/rp/src/bin/uart.rs | 32 | ||||
| -rw-r--r-- | tests/rp/src/bin/uart_dma.rs | 32 |
3 files changed, 105 insertions, 0 deletions
diff --git a/tests/rp/src/bin/dma_copy_async.rs b/tests/rp/src/bin/dma_copy_async.rs new file mode 100644 index 000000000..c53f644bd --- /dev/null +++ b/tests/rp/src/bin/dma_copy_async.rs | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{assert_eq, *}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::dma::copy; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_rp::init(Default::default()); | ||
| 13 | info!("Hello World!"); | ||
| 14 | |||
| 15 | // Check `u8` copy | ||
| 16 | { | ||
| 17 | let data: [u8; 2] = [0xC0, 0xDE]; | ||
| 18 | let mut buf = [0; 2]; | ||
| 19 | unsafe { copy(p.DMA_CH0, &data, &mut buf).await }; | ||
| 20 | assert_eq!(buf, data); | ||
| 21 | } | ||
| 22 | |||
| 23 | // Check `u16` copy | ||
| 24 | { | ||
| 25 | let data: [u16; 2] = [0xC0BE, 0xDEAD]; | ||
| 26 | let mut buf = [0; 2]; | ||
| 27 | unsafe { copy(p.DMA_CH1, &data, &mut buf).await }; | ||
| 28 | assert_eq!(buf, data); | ||
| 29 | } | ||
| 30 | |||
| 31 | // Check `u32` copy | ||
| 32 | { | ||
| 33 | let data: [u32; 2] = [0xC0BEDEAD, 0xDEADAAFF]; | ||
| 34 | let mut buf = [0; 2]; | ||
| 35 | unsafe { copy(p.DMA_CH2, &data, &mut buf).await }; | ||
| 36 | assert_eq!(buf, data); | ||
| 37 | } | ||
| 38 | |||
| 39 | info!("Test OK"); | ||
| 40 | cortex_m::asm::bkpt(); | ||
| 41 | } | ||
diff --git a/tests/rp/src/bin/uart.rs b/tests/rp/src/bin/uart.rs new file mode 100644 index 000000000..92f61464e --- /dev/null +++ b/tests/rp/src/bin/uart.rs | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{assert_eq, *}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::uart::{Config, Uart}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_rp::init(Default::default()); | ||
| 13 | info!("Hello World!"); | ||
| 14 | |||
| 15 | let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0); | ||
| 16 | |||
| 17 | let config = Config::default(); | ||
| 18 | let mut uart = Uart::new_blocking(uart, tx, rx, config); | ||
| 19 | |||
| 20 | // We can't send too many bytes, they have to fit in the FIFO. | ||
| 21 | // This is because we aren't sending+receiving at the same time. | ||
| 22 | |||
| 23 | let data = [0xC0, 0xDE]; | ||
| 24 | uart.blocking_write(&data).unwrap(); | ||
| 25 | |||
| 26 | let mut buf = [0; 2]; | ||
| 27 | uart.blocking_read(&mut buf).unwrap(); | ||
| 28 | assert_eq!(buf, data); | ||
| 29 | |||
| 30 | info!("Test OK"); | ||
| 31 | cortex_m::asm::bkpt(); | ||
| 32 | } | ||
diff --git a/tests/rp/src/bin/uart_dma.rs b/tests/rp/src/bin/uart_dma.rs new file mode 100644 index 000000000..963c22707 --- /dev/null +++ b/tests/rp/src/bin/uart_dma.rs | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{assert_eq, *}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::uart::{Config, Uart}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_rp::init(Default::default()); | ||
| 13 | info!("Hello World!"); | ||
| 14 | |||
| 15 | let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0); | ||
| 16 | |||
| 17 | let config = Config::default(); | ||
| 18 | let mut uart = Uart::new(uart, tx, rx, p.DMA_CH0, p.DMA_CH1, config); | ||
| 19 | |||
| 20 | // We can't send too many bytes, they have to fit in the FIFO. | ||
| 21 | // This is because we aren't sending+receiving at the same time. | ||
| 22 | |||
| 23 | let data = [0xC0, 0xDE]; | ||
| 24 | uart.write(&data).await.unwrap(); | ||
| 25 | |||
| 26 | let mut buf = [0; 2]; | ||
| 27 | uart.read(&mut buf).await.unwrap(); | ||
| 28 | assert_eq!(buf, data); | ||
| 29 | |||
| 30 | info!("Test OK"); | ||
| 31 | cortex_m::asm::bkpt(); | ||
| 32 | } | ||
