aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-rp/src/uart/mod.rs3
-rw-r--r--tests/rp/src/bin/uart_upgrade.rs54
2 files changed, 55 insertions, 2 deletions
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs
index 97f4463e5..682243a27 100644
--- a/embassy-rp/src/uart/mod.rs
+++ b/embassy-rp/src/uart/mod.rs
@@ -1,12 +1,11 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use embassy_cortex_m::interrupt::InterruptExt;
4use embassy_hal_common::{into_ref, PeripheralRef}; 3use embassy_hal_common::{into_ref, PeripheralRef};
5 4
6use crate::dma::{AnyChannel, Channel}; 5use crate::dma::{AnyChannel, Channel};
7use crate::gpio::sealed::Pin; 6use crate::gpio::sealed::Pin;
8use crate::gpio::AnyPin; 7use crate::gpio::AnyPin;
9use crate::{pac, peripherals, Peripheral, RegExt}; 8use crate::{pac, peripherals, Peripheral};
10 9
11#[cfg(feature = "nightly")] 10#[cfg(feature = "nightly")]
12mod buffered; 11mod buffered;
diff --git a/tests/rp/src/bin/uart_upgrade.rs b/tests/rp/src/bin/uart_upgrade.rs
new file mode 100644
index 000000000..d8c9aecf6
--- /dev/null
+++ b/tests/rp/src/bin/uart_upgrade.rs
@@ -0,0 +1,54 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{assert_eq, *};
6use embassy_executor::Spawner;
7use embassy_rp::interrupt;
8use embassy_rp::uart::{Config, Uart};
9use embedded_io::asynch::{Read, Write};
10use {defmt_rtt as _, panic_probe as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let p = embassy_rp::init(Default::default());
15 info!("Hello World!");
16
17 let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0);
18
19 let config = Config::default();
20 let mut uart = Uart::new_blocking(uart, tx, rx, config);
21
22 // We can't send too many bytes, they have to fit in the FIFO.
23 // This is because we aren't sending+receiving at the same time.
24
25 let data = [0xC0, 0xDE];
26 uart.blocking_write(&data).unwrap();
27
28 let mut buf = [0; 2];
29 uart.blocking_read(&mut buf).unwrap();
30 assert_eq!(buf, data);
31
32 let irq = interrupt::take!(UART0_IRQ);
33 let tx_buf = &mut [0u8; 16];
34 let rx_buf = &mut [0u8; 16];
35
36 let mut uart = uart.into_buffered(irq, tx_buf, rx_buf);
37
38 // Make sure we send more bytes than fits in the FIFO, to test the actual
39 // bufferedUart.
40
41 let data = [
42 1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
43 30, 31,
44 ];
45 uart.write_all(&data).await.unwrap();
46 info!("Done writing");
47
48 let mut buf = [0; 31];
49 uart.read_exact(&mut buf).await.unwrap();
50 assert_eq!(buf, data);
51
52 info!("Test OK");
53 cortex_m::asm::bkpt();
54}