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

Add some comments to the UART DMA example #814

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rp2040-hal/examples/uart_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ fn main() -> ! {
// Initialize DMA.
let dma = pac.DMA.split(&mut pac.RESETS);

// The `write_full_blocking` calls in this example are only used to provide some structure to the
// output. They are not required for using the UART with DMA.
uart.write_full_blocking(b"\r\n\r\nUART DMA echo example\r\n\r\n");

// In order to use DMA we need to split the UART into a RX (receive) and TX (transmit) pair
Expand All @@ -110,6 +112,13 @@ fn main() -> ! {
let teststring = b"DMA UART write\r\n";
let tx_transfer = hal::dma::single_buffer::Config::new(dma.ch0, teststring, tx).start();

// The actual transfer happens in the background, asynchronously. So the CPU could do something
// else here:
//
// while !tx_transfer.is_done() {
// // do something else
// }

// Wait for the DMA transfer to finish so we can reuse the tx and the dma channel
let (ch0, _teststring, tx) = tx_transfer.wait();

Expand All @@ -129,7 +138,7 @@ fn main() -> ! {
let _tx_transfer = hal::dma::single_buffer::Config::new(ch0, rx, tx).start();

loop {
// everything should be handled by DMA, nothing else to do
// Everything should be handled by DMA, nothing else to do. The CPU is free to do other tasks. Here, we just wait.
delay.delay_ms(1000);
}
}
Expand Down
Loading