Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: BufferedUart + half duplex #3278

Open
BKSalman opened this issue Aug 23, 2024 · 2 comments
Open

Question: BufferedUart + half duplex #3278

BKSalman opened this issue Aug 23, 2024 · 2 comments

Comments

@BKSalman
Copy link

BKSalman commented Aug 23, 2024

Hello,

I'm using stm32f446re, and I wanted to have uart with embedded_io_async::Write & embedded_io_async::Read implemented, but also be half duplex

so I'm wondering if that is possible, and just hasn't been implemented yet, or not

thank you for the great project :)

@BKSalman BKSalman changed the title BufferedUart + half duplex Question: BufferedUart + half duplex Aug 23, 2024
@badrbouslikhin
Copy link
Contributor

badrbouslikhin commented Aug 27, 2024

Hi @BKSalman,
It's already possible. Take a look at UartRx in embassy_stm32::usart - Rust and into_ring_buffered - UartRx in embassy_stm32::usart - Rust.

Here's a snippet of how to achieve this:

    const DMA_BUF_SIZE: usize = 256;

    let mut usart = Uart::new_half_duplex(
        p.UART4,
        p.PA0,
        Irqs,
        p.DMA1_CH0,
        p.DMA1_CH1,
        config,
        HalfDuplexConfig::PushPull,
    )
    .unwrap();

    let (mut tx, rx) = usart.split();
    static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
    let dma_buf = unsafe { DMA_BUF.as_mut() };
    let rx = rx.into_ring_buffered(dma_buf);

In this case, tx implements embedded_io_async::Write and rx implements embedded_io_async::Read.

@BKSalman
Copy link
Author

thank you for the help :), this might work for the time being

however I feel like this should be part of the BufferedUart API that it just handles the half duplex configuration the same way Uart does (using BufferedUart::new_half_duplex()), and the user doesn't have to split tx and rx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants