@@ -59,7 +59,9 @@ impl<B, C: Channel, T: Target> Transfer<B, C, T> {
59
59
let ( ptr, len) = unsafe { buffer. write_buffer ( ) } ;
60
60
let len = u16 ( len) . expect ( "buffer is too large" ) ;
61
61
62
- channel. set_memory_address ( ptr as u32 , Increment :: Enable ) ;
62
+ // NOTE(unsafe) We are using the address of a 'static WriteBuffer here,
63
+ // which is guaranteed to be safe for DMA.
64
+ unsafe { channel. set_memory_address ( ptr as u32 , Increment :: Enable ) } ;
63
65
channel. set_transfer_length ( len) ;
64
66
channel. set_word_size :: < B :: Word > ( ) ;
65
67
channel. set_direction ( Direction :: FromPeripheral ) ;
@@ -84,7 +86,9 @@ impl<B, C: Channel, T: Target> Transfer<B, C, T> {
84
86
let ( ptr, len) = unsafe { buffer. read_buffer ( ) } ;
85
87
let len = u16 ( len) . expect ( "buffer is too large" ) ;
86
88
87
- channel. set_memory_address ( ptr as u32 , Increment :: Enable ) ;
89
+ // NOTE(unsafe) We are using the address of a 'static ReadBuffer here,
90
+ // which is guaranteed to be safe for DMA.
91
+ unsafe { channel. set_memory_address ( ptr as u32 , Increment :: Enable ) } ;
88
92
channel. set_transfer_length ( len) ;
89
93
channel. set_word_size :: < B :: Word > ( ) ;
90
94
channel. set_direction ( Direction :: FromMemory ) ;
@@ -266,7 +270,12 @@ pub trait Channel: private::Channel {
266
270
/// # Panics
267
271
///
268
272
/// Panics if this channel is enabled.
269
- fn set_peripheral_address ( & mut self , address : u32 , inc : Increment ) {
273
+ ///
274
+ /// # Safety
275
+ ///
276
+ /// Callers must ensure the given address is the address of a peripheral
277
+ /// register that supports DMA.
278
+ unsafe fn set_peripheral_address ( & mut self , address : u32 , inc : Increment ) {
270
279
assert ! ( !self . is_enabled( ) ) ;
271
280
272
281
self . ch ( ) . par . write ( |w| w. pa ( ) . bits ( address) ) ;
@@ -281,7 +290,12 @@ pub trait Channel: private::Channel {
281
290
/// # Panics
282
291
///
283
292
/// Panics if this channel is enabled.
284
- fn set_memory_address ( & mut self , address : u32 , inc : Increment ) {
293
+ ///
294
+ /// # Safety
295
+ ///
296
+ /// Callers must ensure the given address is a valid memory address
297
+ /// that will remain valid as long as at is used by DMA.
298
+ unsafe fn set_memory_address ( & mut self , address : u32 , inc : Increment ) {
285
299
assert ! ( !self . is_enabled( ) ) ;
286
300
287
301
self . ch ( ) . mar . write ( |w| w. ma ( ) . bits ( address) ) ;
0 commit comments