Skip to content

Commit

Permalink
Merge pull request #2221 from hathach/ehci-halted-error
Browse files Browse the repository at this point in the history
EHCI more fixes
  • Loading branch information
hathach authored Aug 16, 2023
2 parents 7537985 + f4845e4 commit 1fdf290
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,19 +738,27 @@ bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr) {
usbh_device_t* dev = get_device(daddr);
TU_VERIFY(dev);

TU_LOG_USBH("[%u] Aborted transfer on EP %02X\r\n", daddr, ep_addr);

uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);

// skip if not busy
TU_VERIFY(dev->ep_status[epnum][dir].busy);

bool const ret = hcd_edpt_abort_xfer(dev->rhport, daddr, ep_addr);
if (ret) {
// mark as ready if transfer is aborted
if ( epnum == 0 ) {
// control transfer: only 1 control at a time, check if we are aborting the current one
TU_VERIFY(daddr == _ctrl_xfer.daddr && _ctrl_xfer.stage != CONTROL_STAGE_IDLE);
TU_VERIFY(hcd_edpt_abort_xfer(dev->rhport, daddr, ep_addr));
// reset control transfer state to idle
_set_control_xfer_stage(CONTROL_STAGE_IDLE);
} else {
// non-control skip if not busy
TU_VERIFY(dev->ep_status[epnum][dir].busy);
TU_VERIFY(hcd_edpt_abort_xfer(dev->rhport, daddr, ep_addr));
// mark as ready and release endpoint if transfer is aborted
dev->ep_status[epnum][dir].busy = false;
usbh_edpt_release(daddr, ep_addr);
}

return ret;
return true;
}

//--------------------------------------------------------------------+
Expand Down
2 changes: 2 additions & 0 deletions src/portable/ehci/ehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ void qhd_xfer_complete_isr(ehci_qhd_t * qhd) {
if ( qtd_overlay->halted ) {
if (qtd_overlay->xact_err || qtd_overlay->err_count == 0 || qtd_overlay->buffer_err || qtd_overlay->babble_err) {
// Error count = 0 often occurs when device disconnected, or other bus-related error
// clear halted bit if not caused by STALL to allow more transfer
xfer_result = XFER_RESULT_FAILED;
qtd_overlay->halted = false;
TU_LOG3(" QHD xfer err count: %d\n", qtd_overlay->err_count);
// TU_BREAKPOINT(); // TODO skip unplugged device
}else {
Expand Down

0 comments on commit 1fdf290

Please sign in to comment.