Skip to content

Commit 5dae5e1

Browse files
committed
ehci fix dcache clean when control endpoint failed
1 parent f26a939 commit 5dae5e1

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

hw/bsp/imxrt/family.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ if (NOT TARGET ${BOARD_TARGET})
5757
)
5858
update_board(${BOARD_TARGET})
5959

60+
if (NOT DEFINED LD_FILE_${TOOLCHAIN})
61+
set(LD_FILE_gcc ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_VARIANT}xxxxx_flexspi_nor.ld)
62+
endif ()
63+
6064
if (TOOLCHAIN STREQUAL "gcc")
6165
target_sources(${BOARD_TARGET} PUBLIC
6266
${SDK_DIR}/devices/${MCU_VARIANT}/gcc/startup_${MCU_VARIANT}.S
6367
)
6468
target_link_options(${BOARD_TARGET} PUBLIC
65-
"LINKER:--script=${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_VARIANT}xxxxx_flexspi_nor.ld"
69+
"LINKER:--script=${LD_FILE_gcc}"
6670
"LINKER:-Map=$<IF:$<BOOL:$<TARGET_PROPERTY:OUTPUT_NAME>>,$<TARGET_PROPERTY:OUTPUT_NAME>,$<TARGET_PROPERTY:NAME>>${CMAKE_EXECUTABLE_SUFFIX}.map"
6771
# nanolib
6872
--specs=nosys.specs

src/host/usbh.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
440440
uint8_t const epnum = tu_edpt_number(ep_addr);
441441
uint8_t const ep_dir = tu_edpt_dir(ep_addr);
442442

443-
TU_LOG_USBH("on EP %02X with %u bytes %s\r\n", ep_addr, (unsigned int) event.xfer_complete.len,
443+
TU_LOG_USBH("on EP %02X with %u bytes: %s\r\n", ep_addr, (unsigned int) event.xfer_complete.len,
444444
tu_str_xfer_result[event.xfer_complete.result]);
445445

446446
if (event.dev_addr == 0)
@@ -1255,6 +1255,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
12551255
{
12561256
failed_count++;
12571257
osal_task_delay(ATTEMPT_DELAY_MS); // delay a bit
1258+
TU_LOG1("Enumeration attempt %u\r\n", failed_count);
12581259
TU_ASSERT(tuh_control_xfer(xfer), );
12591260
}else
12601261
{

src/portable/ehci/ehci.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/tusb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ char const* const tu_str_std_request[] =
440440
};
441441

442442
char const* const tu_str_xfer_result[] = {
443-
"OK", "Failed", "Stalled", "Timeout"
443+
"OK", "FAILED", "STALLED", "TIMEOUT"
444444
};
445445

446446
#endif

0 commit comments

Comments
 (0)