2022-09-26 05:32:45 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::{assert_eq, *};
|
|
|
|
use embassy_executor::Spawner;
|
|
|
|
use embassy_rp::interrupt;
|
2022-11-07 00:27:21 +01:00
|
|
|
use embassy_rp::uart::{BufferedUart, Config};
|
2022-09-26 05:32:45 +02:00
|
|
|
use embedded_io::asynch::{Read, Write};
|
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0);
|
|
|
|
|
|
|
|
let config = Config::default();
|
|
|
|
let irq = interrupt::take!(UART0_IRQ);
|
2022-09-27 07:45:10 +02:00
|
|
|
let tx_buf = &mut [0u8; 16];
|
|
|
|
let rx_buf = &mut [0u8; 16];
|
2022-11-07 00:27:21 +01:00
|
|
|
let mut uart = BufferedUart::new(uart, irq, tx, rx, tx_buf, rx_buf, config);
|
2022-09-26 05:32:45 +02:00
|
|
|
|
2022-09-27 05:51:38 +02:00
|
|
|
// Make sure we send more bytes than fits in the FIFO, to test the actual
|
|
|
|
// bufferedUart.
|
|
|
|
|
|
|
|
let data = [
|
2023-04-30 04:14:07 +02:00
|
|
|
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,
|
2022-09-27 05:51:38 +02:00
|
|
|
];
|
2022-09-27 07:45:10 +02:00
|
|
|
uart.write_all(&data).await.unwrap();
|
|
|
|
info!("Done writing");
|
2022-09-26 05:32:45 +02:00
|
|
|
|
2023-04-30 04:14:07 +02:00
|
|
|
let mut buf = [0; 48];
|
2022-09-27 07:45:10 +02:00
|
|
|
uart.read_exact(&mut buf).await.unwrap();
|
2022-09-26 05:32:45 +02:00
|
|
|
assert_eq!(buf, data);
|
|
|
|
|
|
|
|
info!("Test OK");
|
|
|
|
cortex_m::asm::bkpt();
|
|
|
|
}
|