summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMathias <mk@blackbird.online>2022-08-26 12:50:12 +0200
committerMathias <mk@blackbird.online>2022-08-26 12:55:15 +0200
commitbd27b9080fd9019e69e84fd30894a71db9fd61b5 (patch)
tree9627c002b0b38278b296f315be73d8951d8fa0d1 /tests
parentb88ef032141e87411dabb5d90ef488f5d6af2285 (diff)
downloadembassy-bd27b9080fd9019e69e84fd30894a71db9fd61b5.zip
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.rs41
-rw-r--r--tests/rp/src/bin/uart.rs32
-rw-r--r--tests/rp/src/bin/uart_dma.rs32
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 00000000..c53f644b
--- /dev/null
+++ b/tests/rp/src/bin/dma_copy_async.rs
@@ -0,0 +1,41 @@
+#![no_std]
+#![no_main]
+#![feature(type_alias_impl_trait)]
+
+use defmt::{assert_eq, *};
+use embassy_executor::Spawner;
+use embassy_rp::dma::copy;
+use {defmt_rtt as _, panic_probe as _};
+
+#[embassy_executor::main]
+async fn main(_spawner: Spawner) {
+ let p = embassy_rp::init(Default::default());
+ info!("Hello World!");
+
+ // Check `u8` copy
+ {
+ let data: [u8; 2] = [0xC0, 0xDE];
+ let mut buf = [0; 2];
+ unsafe { copy(p.DMA_CH0, &data, &mut buf).await };
+ assert_eq!(buf, data);
+ }
+
+ // Check `u16` copy
+ {
+ let data: [u16; 2] = [0xC0BE, 0xDEAD];
+ let mut buf = [0; 2];
+ unsafe { copy(p.DMA_CH1, &data, &mut buf).await };
+ assert_eq!(buf, data);
+ }
+
+ // Check `u32` copy
+ {
+ let data: [u32; 2] = [0xC0BEDEAD, 0xDEADAAFF];
+ let mut buf = [0; 2];
+ unsafe { copy(p.DMA_CH2, &data, &mut buf).await };
+ assert_eq!(buf, data);
+ }
+
+ info!("Test OK");
+ cortex_m::asm::bkpt();
+}
diff --git a/tests/rp/src/bin/uart.rs b/tests/rp/src/bin/uart.rs
new file mode 100644
index 00000000..92f61464
--- /dev/null
+++ b/tests/rp/src/bin/uart.rs
@@ -0,0 +1,32 @@
+#![no_std]
+#![no_main]
+#![feature(type_alias_impl_trait)]
+
+use defmt::{assert_eq, *};
+use embassy_executor::Spawner;
+use embassy_rp::uart::{Config, Uart};
+use {defmt_rtt as _, panic_probe as _};
+
+#[embassy_executor::main]
+async fn main(_spawner: Spawner) {
+ let p = embassy_rp::init(Default::default());
+ info!("Hello World!");
+
+ let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0);
+
+ let config = Config::default();
+ let mut uart = Uart::new_blocking(uart, tx, rx, config);
+
+ // We can't send too many bytes, they have to fit in the FIFO.
+ // This is because we aren't sending+receiving at the same time.
+
+ let data = [0xC0, 0xDE];
+ uart.blocking_write(&data).unwrap();
+
+ let mut buf = [0; 2];
+ uart.blocking_read(&mut buf).unwrap();
+ assert_eq!(buf, data);
+
+ info!("Test OK");
+ cortex_m::asm::bkpt();
+}
diff --git a/tests/rp/src/bin/uart_dma.rs b/tests/rp/src/bin/uart_dma.rs
new file mode 100644
index 00000000..963c2270
--- /dev/null
+++ b/tests/rp/src/bin/uart_dma.rs
@@ -0,0 +1,32 @@
+#![no_std]
+#![no_main]
+#![feature(type_alias_impl_trait)]
+
+use defmt::{assert_eq, *};
+use embassy_executor::Spawner;
+use embassy_rp::uart::{Config, Uart};
+use {defmt_rtt as _, panic_probe as _};
+
+#[embassy_executor::main]
+async fn main(_spawner: Spawner) {
+ let p = embassy_rp::init(Default::default());
+ info!("Hello World!");
+
+ let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0);
+
+ let config = Config::default();
+ let mut uart = Uart::new(uart, tx, rx, p.DMA_CH0, p.DMA_CH1, config);
+
+ // We can't send too many bytes, they have to fit in the FIFO.
+ // This is because we aren't sending+receiving at the same time.
+
+ let data = [0xC0, 0xDE];
+ uart.write(&data).await.unwrap();
+
+ let mut buf = [0; 2];
+ uart.read(&mut buf).await.unwrap();
+ assert_eq!(buf, data);
+
+ info!("Test OK");
+ cortex_m::asm::bkpt();
+}