Merge pull request #1763 from hathach/host-retry-failed-enumeration-request
Retry a few times with transfers in enumeration since device can be unstable when starting up
This commit is contained in:
@@ -32,12 +32,8 @@ if(FAMILY STREQUAL "rp2040")
|
|||||||
|
|
||||||
# due to warnings from Pico-PIO-USB
|
# due to warnings from Pico-PIO-USB
|
||||||
target_compile_options(${PROJECT} PUBLIC
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
-Wno-error=shadow
|
|
||||||
-Wno-error=cast-align
|
|
||||||
-Wno-error=cast-qual
|
-Wno-error=cast-qual
|
||||||
-Wno-error=redundant-decls
|
|
||||||
-Wno-error=sign-conversion
|
-Wno-error=sign-conversion
|
||||||
-Wno-error=conversion
|
-Wno-error=conversion
|
||||||
-Wno-error=unused-function
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
@@ -34,12 +34,8 @@ if(FAMILY STREQUAL "rp2040")
|
|||||||
|
|
||||||
# due to warnings from Pico-PIO-USB
|
# due to warnings from Pico-PIO-USB
|
||||||
target_compile_options(${PROJECT} PUBLIC
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
-Wno-error=shadow
|
|
||||||
-Wno-error=cast-align
|
|
||||||
-Wno-error=cast-qual
|
-Wno-error=cast-qual
|
||||||
-Wno-error=redundant-decls
|
|
||||||
-Wno-error=sign-conversion
|
-Wno-error=sign-conversion
|
||||||
-Wno-error=conversion
|
-Wno-error=conversion
|
||||||
-Wno-error=unused-function
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
@@ -33,12 +33,8 @@ if(FAMILY STREQUAL "rp2040")
|
|||||||
|
|
||||||
# due to warnings from Pico-PIO-USB
|
# due to warnings from Pico-PIO-USB
|
||||||
target_compile_options(${PROJECT} PUBLIC
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
-Wno-error=shadow
|
|
||||||
-Wno-error=cast-align
|
|
||||||
-Wno-error=cast-qual
|
-Wno-error=cast-qual
|
||||||
-Wno-error=redundant-decls
|
|
||||||
-Wno-error=sign-conversion
|
-Wno-error=sign-conversion
|
||||||
-Wno-error=conversion
|
-Wno-error=conversion
|
||||||
-Wno-error=unused-function
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
@@ -38,12 +38,8 @@ if(FAMILY STREQUAL "rp2040")
|
|||||||
|
|
||||||
# due to warnings from Pico-PIO-USB
|
# due to warnings from Pico-PIO-USB
|
||||||
target_compile_options(${PROJECT} PUBLIC
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
-Wno-error=shadow
|
|
||||||
-Wno-error=cast-align
|
|
||||||
-Wno-error=cast-qual
|
-Wno-error=cast-qual
|
||||||
-Wno-error=redundant-decls
|
|
||||||
-Wno-error=sign-conversion
|
-Wno-error=sign-conversion
|
||||||
-Wno-error=conversion
|
-Wno-error=conversion
|
||||||
-Wno-error=unused-function
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
Submodule hw/mcu/raspberry_pi/Pico-PIO-USB updated: f78dc9b2c7...52805e6d92
@@ -225,7 +225,7 @@ enum {
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
XFER_RESULT_SUCCESS,
|
XFER_RESULT_SUCCESS = 0,
|
||||||
XFER_RESULT_FAILED,
|
XFER_RESULT_FAILED,
|
||||||
XFER_RESULT_STALLED,
|
XFER_RESULT_STALLED,
|
||||||
XFER_RESULT_TIMEOUT,
|
XFER_RESULT_TIMEOUT,
|
||||||
|
@@ -620,9 +620,7 @@ static void _xfer_complete(uint8_t daddr, xfer_result_t result)
|
|||||||
.user_data = _ctrl_xfer.user_data
|
.user_data = _ctrl_xfer.user_data
|
||||||
};
|
};
|
||||||
|
|
||||||
usbh_lock();
|
_set_control_xfer_stage(CONTROL_STAGE_IDLE);
|
||||||
_ctrl_xfer.stage = CONTROL_STAGE_IDLE;
|
|
||||||
usbh_unlock();
|
|
||||||
|
|
||||||
if (xfer_temp.complete_cb)
|
if (xfer_temp.complete_cb)
|
||||||
{
|
{
|
||||||
@@ -1182,12 +1180,28 @@ static void enum_full_complete(void);
|
|||||||
// process device enumeration
|
// process device enumeration
|
||||||
static void process_enumeration(tuh_xfer_t* xfer)
|
static void process_enumeration(tuh_xfer_t* xfer)
|
||||||
{
|
{
|
||||||
|
// Retry a few times with transfers in enumeration since device can be unstable when starting up
|
||||||
|
enum {
|
||||||
|
ATTEMPT_COUNT_MAX = 3,
|
||||||
|
ATTEMPT_DELAY_MS = 100
|
||||||
|
};
|
||||||
|
static uint8_t failed_count = 0;
|
||||||
|
|
||||||
if (XFER_RESULT_SUCCESS != xfer->result)
|
if (XFER_RESULT_SUCCESS != xfer->result)
|
||||||
{
|
{
|
||||||
// stop enumeration, maybe we could retry this
|
// retry if not reaching max attempt
|
||||||
enum_full_complete();
|
if ( failed_count < ATTEMPT_COUNT_MAX )
|
||||||
|
{
|
||||||
|
failed_count++;
|
||||||
|
osal_task_delay(ATTEMPT_DELAY_MS); // delay a bit
|
||||||
|
TU_ASSERT(tuh_control_xfer(xfer), );
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
enum_full_complete();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
failed_count = 0;
|
||||||
|
|
||||||
uint8_t const daddr = xfer->daddr;
|
uint8_t const daddr = xfer->daddr;
|
||||||
uintptr_t const state = xfer->user_data;
|
uintptr_t const state = xfer->user_data;
|
||||||
|
@@ -51,14 +51,15 @@ struct tuh_xfer_s
|
|||||||
{
|
{
|
||||||
uint8_t daddr;
|
uint8_t daddr;
|
||||||
uint8_t ep_addr;
|
uint8_t ep_addr;
|
||||||
|
uint8_t TU_RESERVED; // reserved
|
||||||
xfer_result_t result;
|
xfer_result_t result;
|
||||||
|
|
||||||
uint32_t actual_len; // excluding setup packet
|
uint32_t actual_len; // excluding setup packet
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
tusb_control_request_t const* setup; // setup packet pointer if control transfer
|
tusb_control_request_t const* setup; // setup packet pointer if control transfer
|
||||||
uint32_t buflen; // expected length if not control transfer (not available in callback)
|
uint32_t buflen; // expected length if not control transfer (not available in callback)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t* buffer; // not available in callback if not control transfer
|
uint8_t* buffer; // not available in callback if not control transfer
|
||||||
@@ -80,10 +81,13 @@ enum
|
|||||||
|
|
||||||
//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
|
//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
|
||||||
|
|
||||||
// Invoked when device is mounted (configured)
|
// Invoked when a device is mounted (configured)
|
||||||
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr);
|
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr);
|
||||||
|
|
||||||
/// Invoked when device is unmounted (bus reset/unplugged)
|
// Invoked when a device failed to mount during enumeration process
|
||||||
|
// TU_ATTR_WEAK void tuh_mount_failed_cb (uint8_t daddr);
|
||||||
|
|
||||||
|
/// Invoked when a device is unmounted (detached)
|
||||||
TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr);
|
TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
Reference in New Issue
Block a user