2022-05-26 11:02:55 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::*;
|
|
|
|
use embassy::executor::Spawner;
|
|
|
|
use embassy_stm32::dma::NoDma;
|
|
|
|
use embassy_stm32::usart::{BufferedUart, Config, State, Uart};
|
|
|
|
use embassy_stm32::{interrupt, Peripherals};
|
|
|
|
use embedded_io::asynch::BufRead;
|
2022-06-12 20:15:44 +00:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-05-26 11:02:55 +00:00
|
|
|
|
|
|
|
#[embassy::main]
|
|
|
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let config = Config::default();
|
|
|
|
let usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config);
|
|
|
|
|
|
|
|
let mut state = State::new();
|
|
|
|
let irq = interrupt::take!(USART3);
|
|
|
|
let mut tx_buf = [0u8; 32];
|
|
|
|
let mut rx_buf = [0u8; 32];
|
2022-06-09 19:28:13 +00:00
|
|
|
let mut buf_usart = BufferedUart::new(&mut state, usart, irq, &mut tx_buf, &mut rx_buf);
|
2022-05-26 11:02:55 +00:00
|
|
|
|
|
|
|
loop {
|
2022-05-26 11:11:15 +00:00
|
|
|
let buf = buf_usart.fill_buf().await.unwrap();
|
|
|
|
info!("Received: {}", buf);
|
2022-05-26 11:02:55 +00:00
|
|
|
|
|
|
|
// Read bytes have to be explicitly consumed, otherwise fill_buf() will return them again
|
2022-05-26 11:11:15 +00:00
|
|
|
let n = buf.len();
|
2022-05-26 11:02:55 +00:00
|
|
|
buf_usart.consume(n);
|
|
|
|
}
|
|
|
|
}
|