aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-09-27 06:00:33 +0000
committerGitHub <[email protected]>2022-09-27 06:00:33 +0000
commit82d436075633e179f96d49b6afb9045451a591d4 (patch)
tree0e5e66638d2896357070671ff26f8d1cd65269a5 /tests
parent86fd4806724a003421897f2e465f0c79e38e849b (diff)
parente129a97d48a00d7923886ab3faa82357b2369f13 (diff)
Merge #934
934: (embassy-rp): Add Buffered UART implementation r=MathiasKoch a=MathiasKoch ### Questions & concerns: - ~~Would it make sense to add `RxBufferedUart` and `TxBufferedUart`, for cases where you would want to only buffer one way?~~ - ~~Do I need to be monitoring more interrupt flags than `Receive` & `Receive timeout`?~~ This PR adds working `BufferedUart` implementation, along with `RxBufferedUart` and `TxBufferedUart`. The implementation leaves room for improvement with respect to performance, as it still does not utilize DMA nor the internal UART buffers. Co-authored-by: Mathias <[email protected]> Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/rp/.cargo/config.toml2
-rw-r--r--tests/rp/Cargo.toml1
-rw-r--r--tests/rp/src/bin/uart_buffered.rs44
3 files changed, 46 insertions, 1 deletions
diff --git a/tests/rp/.cargo/config.toml b/tests/rp/.cargo/config.toml
index 0330025e4..9611db3a0 100644
--- a/tests/rp/.cargo/config.toml
+++ b/tests/rp/.cargo/config.toml
@@ -3,7 +3,7 @@ build-std = ["core"]
3build-std-features = ["panic_immediate_abort"] 3build-std-features = ["panic_immediate_abort"]
4 4
5[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 5[target.'cfg(all(target_arch = "arm", target_os = "none"))']
6#runner = "teleprobe client run --target bluepill-stm32f103c8 --elf" 6#runner = "teleprobe client run --target rpi-pico --elf"
7runner = "teleprobe local run --chip RP2040 --elf" 7runner = "teleprobe local run --chip RP2040 --elf"
8 8
9rustflags = [ 9rustflags = [
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml
index 7e2717ddf..503373759 100644
--- a/tests/rp/Cargo.toml
+++ b/tests/rp/Cargo.toml
@@ -20,6 +20,7 @@ embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
20embedded-hal-async = { version = "0.1.0-alpha.1" } 20embedded-hal-async = { version = "0.1.0-alpha.1" }
21panic-probe = { version = "0.3.0", features = ["print-defmt"] } 21panic-probe = { version = "0.3.0", features = ["print-defmt"] }
22futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 22futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
23embedded-io = { version = "0.3.0", features = ["async"] }
23 24
24[profile.dev] 25[profile.dev]
25debug = 2 26debug = 2
diff --git a/tests/rp/src/bin/uart_buffered.rs b/tests/rp/src/bin/uart_buffered.rs
new file mode 100644
index 000000000..9cc20bb98
--- /dev/null
+++ b/tests/rp/src/bin/uart_buffered.rs
@@ -0,0 +1,44 @@
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::{BufferedUart, Config, State, 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 uart = Uart::new_blocking(uart, tx, rx, config);
21
22 let irq = interrupt::take!(UART0_IRQ);
23 let tx_buf = &mut [0u8; 16];
24 let rx_buf = &mut [0u8; 16];
25 let mut state = State::new();
26 let mut uart = BufferedUart::new(&mut state, uart, irq, tx_buf, rx_buf);
27
28 // Make sure we send more bytes than fits in the FIFO, to test the actual
29 // bufferedUart.
30
31 let data = [
32 1_u8, 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,
33 30, 31, 32,
34 ];
35 uart.write_all(&data).await.unwrap();
36 info!("Done writing");
37
38 let mut buf = [0; 32];
39 uart.read_exact(&mut buf).await.unwrap();
40 assert_eq!(buf, data);
41
42 info!("Test OK");
43 cortex_m::asm::bkpt();
44}