dma Rx working
This commit is contained in:
@@ -8,18 +8,20 @@ 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 dma_gpio::dma_timer::init_tim7_for_uart;
|
||||
use embassy_stm32::gpio::Input;
|
||||
use embassy_stm32::gpio::Pull;
|
||||
use dma_gpio::gpio_uart_rx::GpioUartRx;
|
||||
use dma_gpio::gpio_dma_uart_rx::GpioDmaRx;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
use embassy_stm32::{
|
||||
gpio::{Level, Output, Speed},
|
||||
peripherals::GPDMA1_CH0,
|
||||
peripherals::GPDMA1_CH1,
|
||||
};
|
||||
use embassy_stm32::Peri;
|
||||
|
||||
use dma_gpio::gpio_dma_uart::{
|
||||
use dma_gpio::gpio_dma_uart_tx::{
|
||||
write_uart_frames_to_pipe, GpioDmaBsrrTx, Parity, StopBits, UartConfig,
|
||||
};
|
||||
|
||||
@@ -29,13 +31,15 @@ static PIPE_RX: Pipe<CriticalSectionRawMutex, 256> = Pipe::new();
|
||||
// Baud rate: one TIM6 update equals one UART bit-time
|
||||
const BAUD: u32 = 115_200;
|
||||
const TX_PIN_BIT: u8 = 2; // PA2
|
||||
const OVERSAMPLE: u16 = 16;
|
||||
const TX_OVERSAMPLE: u16 = 1;
|
||||
const RX_OVERSAMPLE: u16 = 16;
|
||||
|
||||
const UART_CFG: UartConfig = UartConfig {
|
||||
data_bits: 8,
|
||||
parity: Parity::None,
|
||||
stop_bits: StopBits::One,
|
||||
};
|
||||
static mut RX_DMA_BUF: [u32; 512] = [0; 512];
|
||||
|
||||
fn dump_tim6_regs() {
|
||||
// PAC path for STM32U5: module `tim6`, type `Tim6` with ptr()
|
||||
@@ -80,41 +84,45 @@ 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");
|
||||
info!("Hehe");
|
||||
|
||||
// PA3 as Rx "wire"
|
||||
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);
|
||||
init_tim6_for_uart(p.TIM6, BAUD, OVERSAMPLE);
|
||||
init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE); // TX
|
||||
init_tim7_for_uart(p.TIM7, BAUD, RX_OVERSAMPLE); // RX
|
||||
dump_tim6_regs();
|
||||
|
||||
// Start DMA consumer task
|
||||
spawner.spawn(dma_tx_task(p.GPDMA1_CH0)).unwrap();
|
||||
spawner.spawn(rx_dma_task(p.GPDMA1_CH1)).unwrap();
|
||||
|
||||
// Example: transmit a string as UART frames via the Pipe
|
||||
loop {
|
||||
write_uart_frames_to_pipe(
|
||||
&PIPE_TX,
|
||||
TX_PIN_BIT,
|
||||
b"Hello, DMA UART (configurable)!\r\n",
|
||||
b"Hello marshmallow\r\n",
|
||||
&UART_CFG,
|
||||
).await;
|
||||
Timer::after(Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn rx_dma_task(ch: Peri<'static, GPDMA1_CH1>) {
|
||||
let buf_ptr = core::ptr::addr_of_mut!(RX_DMA_BUF);
|
||||
let buf = unsafe { &mut *buf_ptr };
|
||||
let mut rx = GpioDmaRx::new(ch, 3 /*PA3 bit*/, buf, &PIPE_RX);
|
||||
rx.run().await;
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn dma_tx_task(ch: Peri<'static, GPDMA1_CH0>) {
|
||||
let mut tx = GpioDmaBsrrTx::new(ch);
|
||||
|
||||
Reference in New Issue
Block a user