Skip to content

Commit

Permalink
Add some comments to the UART DMA example
Browse files Browse the repository at this point in the history
Closes #538
  • Loading branch information
jannic committed Jul 5, 2024
1 parent 2d593e4 commit df4d971
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit df4d971

Please sign in to comment.