2022-03-14 22:03:35 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt::*;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2022-03-14 22:03:35 +01:00
|
|
|
use embassy_stm32::dma::NoDma;
|
2022-10-26 18:58:22 +02:00
|
|
|
use embassy_stm32::interrupt;
|
2022-06-12 22:15:44 +02:00
|
|
|
use embassy_stm32::peripherals::{DMA1_CH1, UART7};
|
|
|
|
use embassy_stm32::usart::{Config, Uart, UartRx};
|
2022-08-22 21:46:09 +02:00
|
|
|
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
2022-08-22 22:00:06 +02:00
|
|
|
use embassy_sync::channel::Channel;
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-03-14 22:03:35 +01:00
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::task]
|
2022-03-14 22:03:35 +01:00
|
|
|
async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) {
|
|
|
|
unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
|
|
|
|
info!("wrote Hello, starting echo");
|
|
|
|
|
|
|
|
let mut buf = [0u8; 1];
|
|
|
|
loop {
|
|
|
|
unwrap!(usart.blocking_read(&mut buf));
|
|
|
|
unwrap!(usart.blocking_write(&buf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 00:00:29 +02:00
|
|
|
static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
|
2022-03-14 22:03:35 +01:00
|
|
|
|
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-03-14 22:03:35 +01:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let config = Config::default();
|
2022-10-26 18:58:22 +02:00
|
|
|
let irq = interrupt::take!(UART7);
|
|
|
|
let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, irq, p.DMA1_CH0, p.DMA1_CH1, config);
|
2022-03-14 22:03:35 +01:00
|
|
|
unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n"));
|
|
|
|
|
|
|
|
let (mut tx, rx) = usart.split();
|
|
|
|
|
2022-04-06 00:00:29 +02:00
|
|
|
unwrap!(spawner.spawn(reader(rx)));
|
2022-03-14 22:03:35 +01:00
|
|
|
|
|
|
|
loop {
|
2022-04-06 00:00:29 +02:00
|
|
|
let buf = CHANNEL.recv().await;
|
|
|
|
info!("writing...");
|
|
|
|
unwrap!(tx.write(&buf).await);
|
2022-03-14 22:03:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::task]
|
2022-04-06 00:00:29 +02:00
|
|
|
async fn reader(mut rx: UartRx<'static, UART7, DMA1_CH1>) {
|
2022-03-14 22:03:35 +01:00
|
|
|
let mut buf = [0; 8];
|
|
|
|
loop {
|
|
|
|
info!("reading...");
|
|
|
|
unwrap!(rx.read(&mut buf).await);
|
2022-04-06 00:00:29 +02:00
|
|
|
CHANNEL.send(buf).await;
|
2022-03-14 22:03:35 +01:00
|
|
|
}
|
|
|
|
}
|