@@ -577,7 +577,7 @@ void qhd_xfer_complete_isr(ehci_qhd_t * qhd) {
577577 uint32_t const xferred_bytes = qtd -> expected_bytes - qtd -> total_bytes ;
578578
579579 // invalidate dcache if IN transfer
580- if (dir == 1 && qhd -> attached_buffer != 0 ) {
580+ if (dir == 1 && qhd -> attached_buffer != 0 && xferred_bytes > 0 ) {
581581 hcd_dcache_invalidate ((void * ) qhd -> attached_buffer , xferred_bytes );
582582 }
583583
@@ -660,7 +660,7 @@ void qhd_xfer_error_isr(ehci_qhd_t * qhd)
660660 if (qtd_overlay -> halted ) {
661661 xfer_result_t xfer_result ;
662662
663- if (qtd_overlay -> err_count == 0 || qtd_overlay -> buffer_err || qtd_overlay -> babble_err || qtd_overlay -> xact_err ) {
663+ if (qtd_overlay -> xact_err || qtd_overlay -> err_count == 0 || qtd_overlay -> buffer_err || qtd_overlay -> babble_err ) {
664664 // Error count = 0 often occurs when device disconnected, or other bus-related error
665665 xfer_result = XFER_RESULT_FAILED ;
666666 }else {
@@ -671,7 +671,6 @@ void qhd_xfer_error_isr(ehci_qhd_t * qhd)
671671// if (XFER_RESULT_FAILED == xfer_result ) {
672672// TU_LOG1(" QHD xfer err count: %d\n", qtd_overlay->err_count);
673673// TU_BREAKPOINT(); // TODO skip unplugged device
674- // while(1){}
675674// }
676675
677676 ehci_qtd_t * volatile qtd = (ehci_qtd_t * volatile ) qhd -> attached_qtd ;
@@ -683,7 +682,7 @@ void qhd_xfer_error_isr(ehci_qhd_t * qhd)
683682 uint32_t const xferred_bytes = qtd -> expected_bytes - qtd -> total_bytes ;
684683
685684 // invalidate dcache if IN transfer
686- if (dir == 1 && qhd -> attached_buffer != 0 ) {
685+ if (dir == 1 && qhd -> attached_buffer != 0 && xferred_bytes > 0 ) {
687686 hcd_dcache_invalidate ((void * ) qhd -> attached_buffer , xferred_bytes );
688687 }
689688
@@ -698,8 +697,7 @@ void qhd_xfer_error_isr(ehci_qhd_t * qhd)
698697 qhd -> qtd_overlay .alternate .terminate = 1 ;
699698 qhd -> qtd_overlay .halted = 0 ;
700699
701- ehci_qtd_t * p_setup = qtd_control (qhd -> dev_addr );
702- p_setup -> used = 0 ;
700+ hcd_dcache_clean (qhd , sizeof (ehci_qhd_t ));
703701 }
704702
705703 // notify usbh
0 commit comments