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 {
225225
226226typedef enum
227227{
228- XFER_RESULT_SUCCESS ,
228+ XFER_RESULT_SUCCESS = 0 ,
229229 XFER_RESULT_FAILED ,
230230 XFER_RESULT_STALLED ,
231231 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)
620620 .user_data = _ctrl_xfer .user_data
621621 };
622622
623- usbh_lock ();
624- _ctrl_xfer .stage = CONTROL_STAGE_IDLE ;
625- usbh_unlock ();
623+ _set_control_xfer_stage (CONTROL_STAGE_IDLE );
626624
627625 if (xfer_temp .complete_cb )
628626 {
@@ -1182,12 +1180,28 @@ static void enum_full_complete(void);
11821180// process device enumeration
11831181static void process_enumeration (tuh_xfer_t * xfer )
11841182{
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+
11851190 if (XFER_RESULT_SUCCESS != xfer -> result )
11861191 {
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+ }
11891202 return ;
11901203 }
1204+ failed_count = 0 ;
11911205
11921206 uint8_t const daddr = xfer -> daddr ;
11931207 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
5151{
5252 uint8_t daddr ;
5353 uint8_t ep_addr ;
54-
54+ uint8_t TU_RESERVED ; // reserved
5555 xfer_result_t result ;
56+
5657 uint32_t actual_len ; // excluding setup packet
5758
5859 union
5960 {
6061 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)
6263 };
6364
6465 uint8_t * buffer ; // not available in callback if not control transfer
8081
8182//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
8283
83- // Invoked when device is mounted (configured)
84+ // Invoked when a device is mounted (configured)
8485TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr );
8586
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)
8791TU_ATTR_WEAK void tuh_umount_cb (uint8_t daddr );
8892
8993//--------------------------------------------------------------------+
You can’t perform that action at this time.
0 commit comments