From 829cff872f616f1a3cd8987689886916becbe419 Mon Sep 17 00:00:00 2001 From: Priec Date: Wed, 12 Nov 2025 14:15:33 +0100 Subject: [PATCH] using correct pipes now --- semestralka_1/src/bin/main.rs | 23 ++++++++++++++++------- semestralka_1/src/hw_uart_pc/driver.rs | 8 -------- semestralka_1/src/hw_uart_pc/usart1.rs | 12 ++---------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/semestralka_1/src/bin/main.rs b/semestralka_1/src/bin/main.rs index 47dfe72..0368d76 100644 --- a/semestralka_1/src/bin/main.rs +++ b/semestralka_1/src/bin/main.rs @@ -20,7 +20,6 @@ use static_cell::StaticCell; use embassy_futures::yield_now; use dma_gpio::hw_uart_pc::usart1; use dma_gpio::hw_uart_pc::driver::uart_task; -use dma_gpio::hw_uart_pc::driver::UartHandle; use embassy_stm32::usart::{BufferedUart, Config, BufferedInterruptHandler}; use embassy_stm32::peripherals; use embassy_stm32::bind_interrupts; @@ -57,8 +56,8 @@ async fn main(spawner: Spawner) { Irqs, cfg, ).unwrap(); - let (handle, yield_period) = usart1::setup_and_spawn(BAUD); - spawner.spawn(uart_task(uart, handle.tx, handle.rx).unwrap()); + let yield_period = usart1::setup_and_spawn(BAUD); + spawner.spawn(uart_task(uart, &PIPE_HW_TX, &PIPE_HW_RX).unwrap()); // END OF HARDWARE UART to the PC // SOFTWARE UART @@ -92,12 +91,22 @@ async fn main(spawner: Spawner) { info!("tick start"); // Timer::after(Duration::from_millis(100)).await; // info!("tick end"); - let n = handle.rx.read(&mut buf).await; - if n > 0 { - info!("PC received: {:a}", &buf[..n]); + + let n1 = PIPE_HW_RX.read(&mut buf).await; + if n1 > 0 { + info!("PC received: {:a}", &buf[..n1]); + } + if n1 > 0 { + let _ = PIPE_SW_TX.write(&buf[..n1]).await; + info!("SW UART TX sent echo: {:a}", &buf[..n1]); } - if Instant::now().duration_since(last_yield) >= handle.yield_period { + let n2 = PIPE_SW_RX.read(&mut buf).await; + if n2 > 0 { + info!("SW UART RX received: {:a}", &buf[..n2]); + } + + if Instant::now().duration_since(last_yield) >= yield_period { yield_now().await; last_yield = Instant::now(); } diff --git a/semestralka_1/src/hw_uart_pc/driver.rs b/semestralka_1/src/hw_uart_pc/driver.rs index fa09e24..7e4bdbc 100644 --- a/semestralka_1/src/hw_uart_pc/driver.rs +++ b/semestralka_1/src/hw_uart_pc/driver.rs @@ -4,17 +4,9 @@ use embassy_futures::select::{select, Either}; use embassy_stm32::usart::BufferedUart; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::pipe::Pipe; -use embassy_time::Duration; use embedded_io_async::{Read, Write}; - use crate::hw_uart_pc::safety::{RX_PIPE_CAP, TX_PIPE_CAP}; -pub struct UartHandle { - pub tx: &'static Pipe, - pub rx: &'static Pipe, - pub yield_period: Duration, -} - #[embassy_executor::task] pub async fn uart_task( mut uart: BufferedUart<'static>, diff --git a/semestralka_1/src/hw_uart_pc/usart1.rs b/semestralka_1/src/hw_uart_pc/usart1.rs index 8db68de..92cf78d 100644 --- a/semestralka_1/src/hw_uart_pc/usart1.rs +++ b/semestralka_1/src/hw_uart_pc/usart1.rs @@ -3,18 +3,10 @@ use defmt::info; use embassy_time::Duration; use crate::hw_uart_pc::safety::preflight_and_suggest_yield_period; -use crate::hw_uart_pc::driver::UartHandle; -use crate::config::{PIPE_HW_TX, PIPE_HW_RX}; -pub fn setup_and_spawn(baudrate: u32,) -> (UartHandle, Duration) { +pub fn setup_and_spawn(baudrate: u32,) -> Duration { let yield_period: Duration = preflight_and_suggest_yield_period(baudrate); info!("HW USART1 safe"); - let handle = UartHandle { - tx: &PIPE_HW_TX, - rx: &PIPE_HW_RX, - yield_period, - }; - - (handle, yield_period) + yield_period }