Rx is not using dma now

This commit is contained in:
Priec
2025-10-31 14:31:25 +01:00
parent 0ecf821e40
commit 28b468902a
3 changed files with 65 additions and 3 deletions

View File

@@ -8,6 +8,9 @@ use embassy_executor::Spawner;
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, pipe::Pipe};
use embassy_time::{Duration, Timer};
use dma_gpio::dma_timer::init_tim6_for_uart;
use embassy_stm32::gpio::Input;
use embassy_stm32::gpio::Pull;
use dma_gpio::gpio_uart_rx::GpioUartRx;
use {defmt_rtt as _, panic_probe as _};
use embassy_stm32::{
@@ -20,7 +23,8 @@ use dma_gpio::gpio_dma_uart::{
write_uart_frames_to_pipe, GpioDmaBsrrTx, Parity, StopBits, UartConfig,
};
static PIPE: Pipe<CriticalSectionRawMutex, 256> = Pipe::new();
static PIPE_TX: Pipe<CriticalSectionRawMutex, 256> = Pipe::new();
static PIPE_RX: Pipe<CriticalSectionRawMutex, 256> = Pipe::new();
// Baud rate: one TIM6 update equals one UART bit-time
const BAUD: u32 = 115_200;
@@ -76,11 +80,20 @@ fn dump_dma_ch0_regs() {
);
}
#[embassy_executor::task]
async fn rx_task(pin: Input<'static>) {
let mut rx = GpioUartRx::new(pin, BAUD, UART_CFG, &PIPE_RX);
rx.run().await;
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("DMA Pipe -> GPIO UART-like TX");
let pa3_rx = Input::new(p.PA3, Pull::Up);
spawner.spawn(rx_task(pa3_rx)).unwrap();
// PA2 is the TX "wire"
let _pa2 = Output::new(p.PA2, Level::High, Speed::VeryHigh);
// drop(_pa2);
@@ -93,7 +106,7 @@ async fn main(spawner: Spawner) {
// Example: transmit a string as UART frames via the Pipe
loop {
write_uart_frames_to_pipe(
&PIPE,
&PIPE_TX,
TX_PIN_BIT,
b"Hello, DMA UART (configurable)!\r\n",
&UART_CFG,
@@ -110,7 +123,7 @@ async fn dma_tx_task(ch: Peri<'static, GPDMA1_CH0>) {
loop {
// Read one 32-bit BSRR word (4 bytes) from the Pipe
let mut b = [0u8; 4];
let n = PIPE.read(&mut b).await;
let n = PIPE_TX.read(&mut b).await;
if n != 4 {
continue;
}