compiled and working

This commit is contained in:
Priec
2025-11-01 23:47:15 +01:00
parent 4365c72688
commit 15b3b96b68
4 changed files with 38 additions and 20 deletions

View File

@@ -5,6 +5,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Input, Output, Level, Pull, Speed};
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, pipe::Pipe};
use embassy_time::{Duration, Timer};
use dma_gpio::software_uart::{
dma_timer::{init_tim6_for_uart, init_tim7_for_uart},
@@ -12,6 +13,7 @@ use dma_gpio::software_uart::{
runtime::{rx_dma_task, tx_dma_task},
debug::dump_tim6_regs,
};
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
/// SOFTWARE UART CONFIGURATION
@@ -25,36 +27,33 @@ const RX_RING_BYTES: usize = 4096;
static PIPE_TX: Pipe<CriticalSectionRawMutex, PIPE_TX_SIZE> = Pipe::new();
static PIPE_RX: Pipe<CriticalSectionRawMutex, PIPE_RX_SIZE> = Pipe::new();
// Large hardware RX DMA circular buffer, scales with oversampling rate
static mut RX_RING: [u8; RX_RING_BYTES] = [0; RX_RING_BYTES];
static RX_RING: StaticCell<[u8; RX_RING_BYTES]> = StaticCell::new();
#[embassy_executor::main]
async fn main(spawner: Spawner) {
// Initialize peripheral access
let mut p = embassy_stm32::init(Default::default());
info!("UART DMA demo starting...");
let p = embassy_stm32::init(Default::default());
info!("Hehe");
// GPIO setup
let rx = Input::new(p.PA3, Pull::Up);
let _rx = Input::new(p.PA3, Pull::Up);
let _tx = Output::new(p.PA2, Level::High, Speed::VeryHigh);
// Timer setup
init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE);
init_tim7_for_uart(p.TIM7, BAUD, RX_OVERSAMPLE);
dump_tim6_regs(); // debug
dump_tim6_regs();
// Spawn DMA tasks
spawner.spawn(tx_dma_task(p.GPDMA1_CH0)).unwrap();
spawner.spawn(rx_dma_task(p.GPDMA1_CH1)).unwrap();
// Safe one-time init from StaticCell
let ring: &mut [u8; RX_RING_BYTES] = RX_RING.init([0; RX_RING_BYTES]);
// Spawn tasks
spawner.spawn(tx_dma_task(p.GPDMA1_CH0, &PIPE_TX).unwrap());
spawner.spawn(rx_dma_task(p.GPDMA1_CH1, &PIPE_RX, ring).unwrap());
// UART config (8N1 default)
let uart_cfg = UartConfig {
data_bits: 8,
parity: Parity::None,
stop_bits: StopBits::One,
};
// Main loop: send data periodically
loop {
write_uart_frames_to_pipe(&PIPE_TX, TX_PIN_BIT, b"Hello marshmallow\r\n", &uart_cfg).await;
Timer::after(Duration::from_secs(2)).await;