2022-05-26 13:02:55 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
use defmt::*;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2023-03-31 15:50:37 +02:00
|
|
|
use embassy_stm32::usart::{BufferedUart, Config};
|
2023-05-25 00:29:56 +02:00
|
|
|
use embassy_stm32::{bind_interrupts, peripherals, usart};
|
2023-08-07 13:43:09 +02:00
|
|
|
use embedded_io_async::BufRead;
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-05-26 13:02:55 +02:00
|
|
|
|
2023-05-25 00:29:56 +02:00
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
USART3 => usart::BufferedInterruptHandler<peripherals::USART3>;
|
|
|
|
});
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 18:49:55 +02:00
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_stm32::init(Default::default());
|
2022-05-26 13:02:55 +02:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let config = Config::default();
|
|
|
|
|
|
|
|
let mut tx_buf = [0u8; 32];
|
|
|
|
let mut rx_buf = [0u8; 32];
|
2023-09-26 00:14:52 +02:00
|
|
|
let mut buf_usart = BufferedUart::new(p.USART3, Irqs, p.PD9, p.PD8, &mut tx_buf, &mut rx_buf, config).unwrap();
|
2022-05-26 13:02:55 +02:00
|
|
|
|
|
|
|
loop {
|
2022-05-26 13:11:15 +02:00
|
|
|
let buf = buf_usart.fill_buf().await.unwrap();
|
|
|
|
info!("Received: {}", buf);
|
2022-05-26 13:02:55 +02:00
|
|
|
|
|
|
|
// Read bytes have to be explicitly consumed, otherwise fill_buf() will return them again
|
2022-05-26 13:11:15 +02:00
|
|
|
let n = buf.len();
|
2022-05-26 13:02:55 +02:00
|
|
|
buf_usart.consume(n);
|
|
|
|
}
|
|
|
|
}
|