Skip to content

Commit ce7d135

Browse files
dgoodladCryowatt
authored andcommitted
Fix Tx FIFO memory calculation
This used to allocate 9 * 16 words minimum, no matter how many tx endpoints where active. Now we only account for memory allocated to enabled Tx endpoints when determining how much has already been used.
1 parent 83c044c commit ce7d135

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/endpoint_memory.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ impl<USB: UsbPeripheral> EndpointMemoryAllocator<USB> {
152152
return Err(UsbError::InvalidEndpoint)
153153
}
154154

155-
let used = 30
156-
+ self.total_rx_buffer_size_words() as usize
157-
+ self.tx_fifo_size_words.iter().sum::<u16>() as usize;
155+
let mut used = self.total_rx_buffer_size_words() as usize + 30;
156+
for sz in &self.tx_fifo_size_words[0..ep_number] {
157+
used += core::cmp::max(*sz as usize, 16);
158+
}
159+
used -= 16;
158160

159161
let size_words = core::cmp::max((size + 3) / 4, 16);
160162
if (used + size_words) > USB::FIFO_DEPTH_WORDS {

0 commit comments

Comments
 (0)