adding hardware uart
This commit is contained in:
@@ -17,38 +17,62 @@ use dma_gpio::config::{TX_RING_BYTES, RX_RING_BYTES, PIPE_RX_SIZE};
|
||||
use dma_gpio::software_uart::gpio_dma_uart_tx::tx_dma_task;
|
||||
use static_cell::StaticCell;
|
||||
use embassy_futures::yield_now;
|
||||
use hw_uart_pc::usart1;
|
||||
use embassy_stm32::usart::{BufferedUart, Config, BufferedInterruptHandler};
|
||||
use embassy_stm32::peripherals;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
pub const TIM6_UP_REQ: Request = 4;
|
||||
bind_interrupts!(struct Irqs {
|
||||
USART1 => BufferedInterruptHandler<peripherals::USART1>;
|
||||
});
|
||||
|
||||
// Software uart
|
||||
pub const TIM6_UP_REQ: Request = 4;
|
||||
static PIPE_RX: Pipe<CriticalSectionRawMutex, PIPE_RX_SIZE> = Pipe::new();
|
||||
static TX_RING: StaticCell<[u32; TX_RING_BYTES]> = StaticCell::new();
|
||||
static RX_RING: StaticCell<[u8; RX_RING_BYTES]> = StaticCell::new();
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
info!("boot");
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hehe");
|
||||
info!("init m8");
|
||||
|
||||
// HARDWARE UART to the PC
|
||||
|
||||
let mut cfg = Config::default();
|
||||
cfg.baudrate = 230_400;
|
||||
static TX_BUF: StaticCell<[u8; 256]> = StaticCell::new();
|
||||
static RX_BUF: StaticCell<[u8; 256]> = StaticCell::new();
|
||||
let uart = BufferedUart::new(
|
||||
p.USART1,
|
||||
p.PA10, // RX pin
|
||||
p.PA9, // TX pin
|
||||
TX_BUF.init([0; 256]),
|
||||
RX_BUF.init([0; 256]),
|
||||
Irqs,
|
||||
cfg,
|
||||
).unwrap();
|
||||
let handle = usart1::setup_and_spawn(&spawner, uart, cfg.baudrate);
|
||||
// END OF HARDWARE UART to the PC
|
||||
|
||||
// SOFTWARE UART
|
||||
let _rx = Input::new(p.PA3, Pull::Up);
|
||||
let _tx = Output::new(p.PA2, Level::High, Speed::VeryHigh);
|
||||
|
||||
init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE);
|
||||
init_tim7_for_uart(p.TIM7, BAUD, RX_OVERSAMPLE);
|
||||
|
||||
dump_tim6_regs();
|
||||
|
||||
// Safe one-time init from StaticCell
|
||||
let rx_ring: &mut [u8; RX_RING_BYTES] = RX_RING.init([0; RX_RING_BYTES]);
|
||||
let tx_ring_mem: &mut [u32; TX_RING_BYTES] = TX_RING.init([0; TX_RING_BYTES]);
|
||||
|
||||
// Spawn tasks
|
||||
spawner.spawn(rx_dma_task(p.GPDMA1_CH1, rx_ring, &PIPE_RX).unwrap());
|
||||
|
||||
// Create and start the TX DMA ring in main.
|
||||
// let bsrr_ptr = embassy_stm32::pac::GPIOA.bsrr().as_ptr() as *mut u32;
|
||||
let odr_ptr = embassy_stm32::pac::GPIOA.odr().as_ptr() as *mut u32;
|
||||
spawner.spawn(tx_dma_task(p.GPDMA1_CH0, odr_ptr, tx_ring_mem, &PIPE_RX).unwrap());
|
||||
// EDN OF SOFTWARE UART
|
||||
|
||||
loop {
|
||||
info!("tick start");
|
||||
|
||||
Reference in New Issue
Block a user