Embassy uart split

I'm trying to get uart.split() example but for an stm32c011x running.

#![no_std]
#![no_main]

use defmt::*;
use embassy_executor::Spawner;
use embassy_time::Timer;
use embassy_stm32::{bind_interrupts, usart, peripherals};
use embassy_stm32::peripherals::{PA8, EXTI8};
use embassy_stm32::usart::{Uart, UartRx, UartTx, Config};
use embassy_stm32::mode::Async;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use {defmt_rtt as _, panic_probe as _};

bind_interrupts!(struct Irqs {
    USART2 => usart::InterruptHandler<peripherals::USART2>;
});

#[embassy_executor::task]
async fn button(
    pa8: PA8,
    exti8: EXTI8
) {
    let button = Input::new(pa8, Pull::None);
    let mut button = ExtiInput::new(button, exti8);

    info!("button started");
    loop {
        button.wait_for_falling_edge().await;
        Timer::after_millis(50).await;
        info!("pressed");
        while button.is_low() {
            info!("still pressed");
            Timer::after_millis(50).await;
        }
        info!("released");
    }
}

#[embassy_executor::task]
async fn uart_comm_receive(mut rx: UartRx<'static, Async>) {

    info!("uart receive started");

    let mut msg: [u8; 1] = [0; 1];

    loop {
        rx.read(&mut msg).await.unwrap();
        Timer::after_millis(50).await;
    }
}

#[embassy_executor::task]
async fn uart_comm_send(mut tx: UartTx<'static, Async>) {

    info!("uart send started");

    let msg: [u8; 1] = [0; 1];

    loop {
        tx.write_all(&msg).await.unwrap();
        Timer::after_millis(50).await;
    }
}

#[embassy_executor::main]
async fn main(spawner: Spawner) {
    let p = embassy_stm32::init(Default::default());

    let mut conf = Config::default();
    conf.baudrate = 9600;

    let uart = Uart::new(
        p.USART2,
        p.PA3,
        p.PA2,
        Irqs,
        p.DMA1_CH1,
        p.DMA1_CH2,
        conf
    );

    let (mut tx, rx) = uart.unwrap().split();

    let _ = spawner.spawn(uart_comm_send(tx));
    let _ = spawner.spawn(uart_comm_receive(rx));
    let _ = spawner.spawn(button(p.PA8, p.EXTI8));
}

But I get the error
error[E0432]: unresolved import embassy_stm32::mode

At embassy_stm32::mode - Rust the module is listed for embassy_stm32 v0.1.0 and mcu stm32c011f6

How to get Mode Async?

I fixed it. Async isn't still not available, but uart.split() returns UartRx<USART2, DMA1_CH2> and UartTx<USART2, DMA1_CH1>. So, the correct paramter for receive / send functions are mut rx: UartRx<'static, USART2, DMA1_CH2> and mut tx: UartTx<'static, USART2, DMA1_CH1>.

Sometimes it could be so simple.

1 Like