aboutsummaryrefslogtreecommitdiff
path: root/embassy-imxrt
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-12-16 11:28:31 -0800
committerFelipe Balbi <[email protected]>2025-12-16 15:04:15 -0800
commit772c9f951b5ee292089670d9b489314d75f8a92a (patch)
tree5760dacb87bebdc64a82e3afaf539b1454c541d3 /embassy-imxrt
parent2102dba83b3254b77c12a23fd17853cbf985233f (diff)
[iMXRT] dma: fix transfer count computation
count should be defined as the integer div_round_up of buffer length and word size, otherwise transferring small buffers will cause a panic due to underflow: if we let from = [0u32; 1]; then calling dma::write() will result in: let count = ((1 / 4 as usize) - 1) = 0 - 1 // underflow Rounding up results in 1 - 1 as expected.
Diffstat (limited to 'embassy-imxrt')
-rw-r--r--embassy-imxrt/src/dma.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/embassy-imxrt/src/dma.rs b/embassy-imxrt/src/dma.rs
index 76c9953c1..eaa09870d 100644
--- a/embassy-imxrt/src/dma.rs
+++ b/embassy-imxrt/src/dma.rs
@@ -71,7 +71,7 @@ pub(crate) unsafe fn init() {
71/// 71///
72/// SAFETY: Slice must point to a valid location reachable by DMA. 72/// SAFETY: Slice must point to a valid location reachable by DMA.
73pub unsafe fn read<'a, C: Channel, W: Word>(ch: Peri<'a, C>, from: *const W, to: *mut [W]) -> Transfer<'a, C> { 73pub unsafe fn read<'a, C: Channel, W: Word>(ch: Peri<'a, C>, from: *const W, to: *mut [W]) -> Transfer<'a, C> {
74 let count = ((to.len() / W::size() as usize) - 1) as isize; 74 let count = (to.len().div_ceil(W::size() as usize) - 1) as isize;
75 75
76 copy_inner( 76 copy_inner(
77 ch, 77 ch,
@@ -89,7 +89,7 @@ pub unsafe fn read<'a, C: Channel, W: Word>(ch: Peri<'a, C>, from: *const W, to:
89/// 89///
90/// SAFETY: Slice must point to a valid location reachable by DMA. 90/// SAFETY: Slice must point to a valid location reachable by DMA.
91pub unsafe fn write<'a, C: Channel, W: Word>(ch: Peri<'a, C>, from: *const [W], to: *mut W) -> Transfer<'a, C> { 91pub unsafe fn write<'a, C: Channel, W: Word>(ch: Peri<'a, C>, from: *const [W], to: *mut W) -> Transfer<'a, C> {
92 let count = ((from.len() / W::size() as usize) - 1) as isize; 92 let count = (from.len().div_ceil(W::size() as usize) - 1) as isize;
93 93
94 copy_inner( 94 copy_inner(
95 ch, 95 ch,
@@ -111,7 +111,7 @@ pub unsafe fn copy<'a, C: Channel, W: Word>(ch: Peri<'a, C>, from: &[W], to: &mu
111 let to_len = to.len(); 111 let to_len = to.len();
112 assert_eq!(from_len, to_len); 112 assert_eq!(from_len, to_len);
113 113
114 let count = ((from_len / W::size() as usize) - 1) as isize; 114 let count = (from_len.div_ceil(W::size() as usize) - 1) as isize;
115 115
116 copy_inner( 116 copy_inner(
117 ch, 117 ch,