aboutsummaryrefslogtreecommitdiff
path: root/tests/nrf/src/bin/uart_halves.rs
blob: a462f80ce20104ff8d7101e6870c14d1f1b8c9a1 (plain)
1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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(
        peri!(p, UART0).reborrow(),
        irqs!(UART0),
        peri!(p, PIN_A).reborrow(),
        config.clone(),
    );
    let mut rx = UarteRx::new(
        peri!(p, UART1).reborrow(),
        irqs!(UART1),
        peri!(p, PIN_B).reborrow(),
        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();
}