2021-08-16 15:16:49 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-04-02 02:35:06 +00:00
|
|
|
use defmt::*;
|
2022-08-17 21:40:16 +00:00
|
|
|
use embassy_executor::Spawner;
|
2023-03-31 13:50:37 +00:00
|
|
|
use embassy_stm32::usart::{BufferedUart, Config};
|
2023-05-24 22:29:56 +00:00
|
|
|
use embassy_stm32::{bind_interrupts, peripherals, usart};
|
2023-08-07 11:43:09 +00:00
|
|
|
use embedded_io_async::{Read, Write};
|
2022-06-12 20:15:44 +00:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2021-08-16 15:16:49 +00:00
|
|
|
|
2023-05-24 22:29:56 +00:00
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
USART2 => usart::BufferedInterruptHandler<peripherals::USART2>;
|
|
|
|
});
|
|
|
|
|
2022-07-29 19:58:35 +00:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 16:49:55 +00:00
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_stm32::init(Default::default());
|
2022-05-04 18:48:37 +00:00
|
|
|
info!("Hi!");
|
|
|
|
|
2021-08-16 15:16:49 +00:00
|
|
|
let mut config = Config::default();
|
|
|
|
config.baudrate = 9600;
|
2023-09-25 22:14:52 +00:00
|
|
|
let mut tx_buf = [0u8; 256];
|
|
|
|
let mut rx_buf = [0u8; 256];
|
|
|
|
let mut usart = BufferedUart::new(p.USART2, Irqs, p.PA3, p.PA2, &mut tx_buf, &mut rx_buf, config).unwrap();
|
2021-08-16 15:16:49 +00:00
|
|
|
|
|
|
|
usart.write_all(b"Hello Embassy World!\r\n").await.unwrap();
|
|
|
|
info!("wrote Hello, starting echo");
|
|
|
|
|
|
|
|
let mut buf = [0; 4];
|
|
|
|
loop {
|
|
|
|
usart.read_exact(&mut buf[..]).await.unwrap();
|
|
|
|
usart.write_all(&buf[..]).await.unwrap();
|
|
|
|
}
|
|
|
|
}
|