Skip to content

Commit c5df788

Browse files
Revert "4 byte align bulk/interrupt endpoint buffers"
This reverts commit 878e0f6.
1 parent 38ade73 commit c5df788

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

nrf-hal-common/src/usbd/mod.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,11 @@ impl Usbd {
9595
unsafe { &*USBD::ptr() }.usbaddr.read().addr().bits()
9696
}
9797

98-
fn alloc_ep_buf(
99-
&mut self,
100-
ep_type: EndpointType,
101-
mut size: u16,
102-
) -> usb_device::Result<&'static mut [u8]> {
98+
fn alloc_ep_buf(&mut self, size: u16) -> usb_device::Result<&'static mut [u8]> {
99+
assert!(size <= 64);
103100
if self.unalloc_buffers.len() < usize::from(size) {
104101
Err(UsbError::EndpointMemoryOverflow)
105102
} else {
106-
if ep_type == EndpointType::Bulk || ep_type == EndpointType::Interrupt {
107-
// datasheet: buffer must be 4-byte aligned and its size must be a multiple of 4
108-
let rem = self.unalloc_buffers.as_mut_ptr() as usize % 4;
109-
if rem != 0 {
110-
let (_padding, remaining) =
111-
mem::replace(&mut self.unalloc_buffers, &mut []).split_at_mut(4 - rem);
112-
self.unalloc_buffers = remaining;
113-
}
114-
115-
let rem = size % 4;
116-
if rem != 0 {
117-
size = size + 4 - rem;
118-
}
119-
}
120-
assert!(size <= 64);
121103
let (alloc, remaining) =
122104
mem::replace(&mut self.unalloc_buffers, &mut []).split_at_mut(size.into());
123105
self.unalloc_buffers = remaining;
@@ -201,7 +183,7 @@ impl UsbBus for Usbd {
201183

202184
// Endpoint directions are allocated individually.
203185

204-
let buf = self.alloc_ep_buf(ep_type, max_packet_size)?;
186+
let buf = self.alloc_ep_buf(max_packet_size)?;
205187

206188
if false {
207189
unimplemented!(

0 commit comments

Comments
 (0)