Skip to content

Commit

Permalink
Add note where TARGET_BUFFER should be initialised (but is not)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardeoin committed Jan 31, 2024
1 parent 4586b6f commit 2bcf2af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ fn main() -> ! {
// Save a copy on the stack so we can check it later
let source_buffer_cloned = *source_buffer;

// NOTE(unsafe): TARGET_BUFFER must also be initialised to prevent undefined
// behaviour (taking a mutable reference to uninitialised memory)

// Setup DMA
//
// We need to specify the transfer size with a type annotation
Expand Down
5 changes: 4 additions & 1 deletion examples/mdma_bursts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() -> ! {
info!("");

// Initialise the source buffer without taking any references to
// uninitialisated memory
// uninitialised memory
let _source_buffer: &'static mut [u32; 200] = {
let buf: &mut [MaybeUninit<u32>; 200] = unsafe {
&mut *(core::ptr::addr_of_mut!(SOURCE_BUFFER)
Expand All @@ -76,6 +76,9 @@ fn main() -> ! {
unsafe { SOURCE_BUFFER.assume_init_mut() }
};

// NOTE(unsafe): TARGET_BUFFER must also be initialised to prevent undefined
// behaviour (taking a mutable reference to uninitialised memory)

// Setup DMA
let streams = StreamsTuple::new(dp.MDMA, ccdr.peripheral.MDMA);

Expand Down

0 comments on commit 2bcf2af

Please sign in to comment.