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

uart-dma example with changing data length #112

Open
usbalbin opened this issue Jan 4, 2024 · 1 comment
Open

uart-dma example with changing data length #112

usbalbin opened this issue Jan 4, 2024 · 1 comment

Comments

@usbalbin
Copy link
Contributor

usbalbin commented Jan 4, 2024

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
}
@usbalbin
Copy link
Contributor Author

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, 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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant