Skip to content

Commit c3094cb

Browse files
committed
fix(support_rp2040): reset EP0 PID to DATA1 after receiving a setup packet, but do not reset other flags
1 parent 1df2de8 commit c3094cb

File tree

1 file changed

+8
-5
lines changed
  • src/r3_support_rp2040/src

1 file changed

+8
-5
lines changed

src/r3_support_rp2040/src/usb.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl usb_device::bus::UsbBus for UsbBus {
233233
x.set(*y);
234234
}
235235

236+
// Set `buf_ctrl`, toggle PID
236237
buf_ctrl.set(
237238
buf_ctrl.get() & !EP_BUF_CTRL_AVAIL & !EP_BUF_CTRL_LEN_MASK ^ EP_BUF_CTRL_PID_DATA1
238239
| buf.len() as u32
@@ -284,11 +285,13 @@ impl usb_device::bus::UsbBus for UsbBus {
284285
.sie_status
285286
.write(|b| b.setup_rec().set_bit());
286287

287-
// Reset EP0
288-
self.ep_buf_ctrl(EndpointAddress::from_parts(0, UsbDirection::In))
289-
.set(0);
290-
self.ep_buf_ctrl(EndpointAddress::from_parts(0, UsbDirection::Out))
291-
.set(EP_BUF_CTRL_PID_DATA1 | EP_BUF_CTRL_AVAIL);
288+
// the first OUT data packet must be DATA1
289+
let buf_ctrl = self.ep_buf_ctrl(EndpointAddress::from_parts(0, UsbDirection::Out));
290+
buf_ctrl.set(buf_ctrl.get() | EP_BUF_CTRL_PID_DATA1);
291+
292+
// should respond by DATA1
293+
let buf_ctrl = self.ep_buf_ctrl(EndpointAddress::from_parts(0, UsbDirection::In));
294+
buf_ctrl.set(buf_ctrl.get() & !EP_BUF_CTRL_PID_DATA1);
292295

293296
return Ok(8);
294297
}

0 commit comments

Comments
 (0)