Skip to content

Commit dac270e

Browse files
committed
Check EPDATASTATUS inside write()
This helps in a situation when `poll()` is not called periodically, for example, when main loop is busy writing data to an endpoint. This situation happens in the usb_serial example.
1 parent d82d242 commit dac270e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,17 @@ impl UsbBus for Usbd<'_> {
368368
let busy_in_endpoints = self.busy_in_endpoints.borrow(cs);
369369

370370
if busy_in_endpoints.get() & (1 << i) != 0 {
371-
return Err(UsbError::WouldBlock);
371+
// Maybe this endpoint is not busy?
372+
let epdatastatus = regs.epdatastatus.read().bits();
373+
if epdatastatus & (1 << i) != 0 {
374+
// Clear the event flag
375+
regs.epdatastatus.write(|w| unsafe { w.bits(1 << i) });
376+
377+
// Clear the busy status and continue
378+
busy_in_endpoints.set(busy_in_endpoints.get() & !(1 << i));
379+
} else {
380+
return Err(UsbError::WouldBlock);
381+
}
372382
}
373383
if regs.epstatus.read().bits() & (1 << i) != 0 {
374384
return Err(UsbError::WouldBlock);

0 commit comments

Comments
 (0)