File tree Expand file tree Collapse file tree 3 files changed +28
-10
lines changed Expand file tree Collapse file tree 3 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -225,7 +225,7 @@ enum {
225
225
226
226
typedef enum
227
227
{
228
- XFER_RESULT_SUCCESS ,
228
+ XFER_RESULT_SUCCESS = 0 ,
229
229
XFER_RESULT_FAILED ,
230
230
XFER_RESULT_STALLED ,
231
231
XFER_RESULT_TIMEOUT ,
Original file line number Diff line number Diff line change @@ -620,9 +620,7 @@ static void _xfer_complete(uint8_t daddr, xfer_result_t result)
620
620
.user_data = _ctrl_xfer .user_data
621
621
};
622
622
623
- usbh_lock ();
624
- _ctrl_xfer .stage = CONTROL_STAGE_IDLE ;
625
- usbh_unlock ();
623
+ _set_control_xfer_stage (CONTROL_STAGE_IDLE );
626
624
627
625
if (xfer_temp .complete_cb )
628
626
{
@@ -1182,12 +1180,28 @@ static void enum_full_complete(void);
1182
1180
// process device enumeration
1183
1181
static void process_enumeration (tuh_xfer_t * xfer )
1184
1182
{
1183
+ // Retry a few times with transfers in enumeration since device can be unstable when starting up
1184
+ enum {
1185
+ ATTEMPT_COUNT_MAX = 3 ,
1186
+ ATTEMPT_DELAY_MS = 10
1187
+ };
1188
+ static uint8_t failed_count = 0 ;
1189
+
1185
1190
if (XFER_RESULT_SUCCESS != xfer -> result )
1186
1191
{
1187
- // stop enumeration, maybe we could retry this
1188
- enum_full_complete ();
1192
+ // retry if not reaching max attempt
1193
+ if ( failed_count < ATTEMPT_COUNT_MAX )
1194
+ {
1195
+ failed_count ++ ;
1196
+ osal_task_delay (ATTEMPT_DELAY_MS ); // delay a bit
1197
+ TU_ASSERT (tuh_control_xfer (xfer ), );
1198
+ }else
1199
+ {
1200
+ enum_full_complete ();
1201
+ }
1189
1202
return ;
1190
1203
}
1204
+ failed_count = 0 ;
1191
1205
1192
1206
uint8_t const daddr = xfer -> daddr ;
1193
1207
uintptr_t const state = xfer -> user_data ;
Original file line number Diff line number Diff line change @@ -51,14 +51,15 @@ struct tuh_xfer_s
51
51
{
52
52
uint8_t daddr ;
53
53
uint8_t ep_addr ;
54
-
54
+ uint8_t TU_RESERVED ; // reserved
55
55
xfer_result_t result ;
56
+
56
57
uint32_t actual_len ; // excluding setup packet
57
58
58
59
union
59
60
{
60
61
tusb_control_request_t const * setup ; // setup packet pointer if control transfer
61
- uint32_t buflen ; // expected length if not control transfer (not available in callback)
62
+ uint32_t buflen ; // expected length if not control transfer (not available in callback)
62
63
};
63
64
64
65
uint8_t * buffer ; // not available in callback if not control transfer
80
81
81
82
//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
82
83
83
- // Invoked when device is mounted (configured)
84
+ // Invoked when a device is mounted (configured)
84
85
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr );
85
86
86
- /// Invoked when device is unmounted (bus reset/unplugged)
87
+ // Invoked when a device failed to mount during enumeration process
88
+ // TU_ATTR_WEAK void tuh_mount_failed_cb (uint8_t daddr);
89
+
90
+ /// Invoked when a device is unmounted (detached)
87
91
TU_ATTR_WEAK void tuh_umount_cb (uint8_t daddr );
88
92
89
93
//--------------------------------------------------------------------+
You can’t perform that action at this time.
0 commit comments