Skip to content

uart-dma example with changing data length #112

Open
@usbalbin

Description

@usbalbin
Member

The uart-dma example does not show how to send data with different length using dma.

Is this not supported by this crate or is it even a hardware limitation?

example:

[...]

let data_to_send = [
    &b"Hello"[..], // These are to be sent one at a time to simulate sending messages of different sizes
    &b"I"[..],
    &b"am Bob the Bot"[..],
];


// Setup DMA for USART2 TX with dma channel 1.
let mut transfer =
    streams
        .0
        .into_memory_to_peripheral_transfer(tx.enable_dma(), &mut tx_buffer[..], config);

transfer.start(|_tx| {});
loop {
    while !transfer.get_transfer_complete_flag() {}

    delay_syst.delay(1000.millis());
    led.toggle().unwrap();
    transfer.restart(|_tx| {}); // <---------- Do something here to either change buffer to data_to_send[i],
                                // , or copy to tx_buffer (assuming it is large enough) and tell `transfer` the new data length
}

Activity

usbalbin

usbalbin commented on Feb 14, 2024

@usbalbin
MemberAuthor

To me I think it would have made more sense if the uart and dma stream were combined into a "uart-with-dma" rather than a "dma-stream-thing that happens to wrap an uart".

So instead of

let mut transfer =
    streams
        .0
        .into_memory_to_peripheral_transfer(tx.enable_dma(), &mut tx_buffer[..], config);

I would want

let mut tx: Tx<UART2, PIN, DMA> = tx.enable_dma(streams.0, &mut tx_buffer[..]);

since Tx<UART2, PIN, DMA> can then impl core::fmt::Write(or some more appropriate alternative), set senseful dma configs automatically etc since it has more knowledge of how the dma channel will be used.

Any thoughts? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @usbalbin

        Issue actions

          uart-dma example with changing data length · Issue #112 · stm32-rs/stm32g4xx-hal