mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
tests/nrf: add non-buffered uart tests.
This commit is contained in:
parent
b870e7f257
commit
9a21f70c9f
@ -91,6 +91,16 @@ name = "timer"
|
|||||||
path = "src/bin/timer.rs"
|
path = "src/bin/timer.rs"
|
||||||
required-features = []
|
required-features = []
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "uart_halves"
|
||||||
|
path = "src/bin/uart_halves.rs"
|
||||||
|
required-features = [ "two-uarts",]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "uart_split"
|
||||||
|
path = "src/bin/uart_split.rs"
|
||||||
|
required-features = [ "easydma",]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "wifi_esp_hosted_perf"
|
name = "wifi_esp_hosted_perf"
|
||||||
path = "src/bin/wifi_esp_hosted_perf.rs"
|
path = "src/bin/wifi_esp_hosted_perf.rs"
|
||||||
|
41
tests/nrf/src/bin/uart_halves.rs
Normal file
41
tests/nrf/src/bin/uart_halves.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// required-features: two-uarts
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
#[path = "../common.rs"]
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
use defmt::{assert_eq, *};
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_futures::join::join;
|
||||||
|
use embassy_nrf::uarte::{UarteRx, UarteTx};
|
||||||
|
use embassy_nrf::{peripherals, uarte};
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) {
|
||||||
|
let mut p = embassy_nrf::init(Default::default());
|
||||||
|
let mut config = uarte::Config::default();
|
||||||
|
config.parity = uarte::Parity::EXCLUDED;
|
||||||
|
config.baudrate = uarte::Baudrate::BAUD1M;
|
||||||
|
|
||||||
|
let mut tx = UarteTx::new(&mut peri!(p, UART0), irqs!(UART0), &mut peri!(p, PIN_A), config.clone());
|
||||||
|
let mut rx = UarteRx::new(&mut peri!(p, UART1), irqs!(UART1), &mut peri!(p, PIN_B), config.clone());
|
||||||
|
|
||||||
|
let data = [
|
||||||
|
0x42, 0x43, 0x44, 0x45, 0x66, 0x12, 0x23, 0x34, 0x45, 0x19, 0x91, 0xaa, 0xff, 0xa5, 0x5a, 0x77,
|
||||||
|
];
|
||||||
|
|
||||||
|
let tx_fut = async {
|
||||||
|
tx.write(&data).await.unwrap();
|
||||||
|
};
|
||||||
|
let rx_fut = async {
|
||||||
|
let mut buf = [0u8; 16];
|
||||||
|
rx.read(&mut buf).await.unwrap();
|
||||||
|
assert_eq!(data, buf);
|
||||||
|
};
|
||||||
|
join(rx_fut, tx_fut).await;
|
||||||
|
|
||||||
|
info!("Test OK");
|
||||||
|
cortex_m::asm::bkpt();
|
||||||
|
}
|
49
tests/nrf/src/bin/uart_split.rs
Normal file
49
tests/nrf/src/bin/uart_split.rs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// required-features: easydma
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
#[path = "../common.rs"]
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
use defmt::{assert_eq, *};
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_futures::join::join;
|
||||||
|
use embassy_nrf::uarte::Uarte;
|
||||||
|
use embassy_nrf::{peripherals, uarte};
|
||||||
|
use embassy_time::Timer;
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) {
|
||||||
|
let mut p = embassy_nrf::init(Default::default());
|
||||||
|
let mut config = uarte::Config::default();
|
||||||
|
config.parity = uarte::Parity::EXCLUDED;
|
||||||
|
config.baudrate = uarte::Baudrate::BAUD9600;
|
||||||
|
|
||||||
|
let uarte = Uarte::new(
|
||||||
|
&mut peri!(p, UART0),
|
||||||
|
irqs!(UART0),
|
||||||
|
&mut peri!(p, PIN_A),
|
||||||
|
&mut peri!(p, PIN_B),
|
||||||
|
config.clone(),
|
||||||
|
);
|
||||||
|
let (mut tx, mut rx) = uarte.split();
|
||||||
|
|
||||||
|
let data = [
|
||||||
|
0x42, 0x43, 0x44, 0x45, 0x66, 0x12, 0x23, 0x34, 0x45, 0x19, 0x91, 0xaa, 0xff, 0xa5, 0x5a, 0x77,
|
||||||
|
];
|
||||||
|
|
||||||
|
let tx_fut = async {
|
||||||
|
Timer::after_millis(10).await;
|
||||||
|
tx.write(&data).await.unwrap();
|
||||||
|
};
|
||||||
|
let rx_fut = async {
|
||||||
|
let mut buf = [0u8; 16];
|
||||||
|
rx.read(&mut buf).await.unwrap();
|
||||||
|
assert_eq!(data, buf);
|
||||||
|
};
|
||||||
|
join(rx_fut, tx_fut).await;
|
||||||
|
|
||||||
|
info!("Test OK");
|
||||||
|
cortex_m::asm::bkpt();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user