blob: c8666e64a20e1a1edfc918ff460a1df946c4e79e (
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
|
#![no_std]
#![no_main]
use embassy_executor::Spawner;
use embassy_mcxa_examples::init_uart2_pins;
use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
use crate::hal::lpuart::{Config, Lpuart};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = hal::init(hal::config::Config::default());
defmt::info!("boot");
// Board-level init for UART2 clocks and pins.
unsafe {
init_uart2_pins();
}
// Create UART configuration
let config = Config {
baudrate_bps: 115_200,
enable_tx: true,
enable_rx: true,
..Default::default()
};
// Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX
let lpuart = Lpuart::new_blocking(
p.LPUART2, // Peripheral
p.P2_2, // TX pin
p.P2_3, // RX pin
config,
)
.unwrap();
// Split into separate TX and RX parts
let (mut tx, mut rx) = lpuart.split();
// Write hello messages
tx.blocking_write(b"Hello world.\r\n").unwrap();
tx.blocking_write(b"Echoing. Type characters...\r\n").unwrap();
// Echo loop
loop {
let mut buf = [0u8; 1];
rx.blocking_read(&mut buf).unwrap();
tx.blocking_write(&buf).unwrap();
}
}
|