Skip to content

Commit 2954e70

Browse files
committed
Panic if the transfer length exceeds the hardware capability
1 parent 25ee0f3 commit 2954e70

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/dma/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ where
335335
/// `DmaConfig` while initializing a memory to memory transfer.
336336
/// * When double buffering is enabled but the `double_buf` argument is
337337
/// `None`.
338+
/// * When the transfer length is greater than (2^16 - 1)
338339
pub fn init(
339340
mut stream: STREAM,
340341
peripheral: PERIPHERAL,
@@ -408,10 +409,15 @@ where
408409
};
409410

410411
let n_transfers = if let Some(db) = db_len {
411-
buf_len.min(db) as u16
412+
buf_len.min(db)
412413
} else {
413-
buf_len as u16
414+
buf_len
414415
};
416+
assert!(
417+
n_transfers <= 65535,
418+
"Hardware does not support more than 65535 transfers"
419+
);
420+
let n_transfers = n_transfers as u16;
415421
stream.set_number_of_transfers(n_transfers);
416422

417423
// Set the DMAMUX request line if needed

0 commit comments

Comments
 (0)