Skip to content

Commit

Permalink
system/adb: Waiting for enumeration to complete before opening endpoint
Browse files Browse the repository at this point in the history
Env

  esp32s3-devkit:adb

Error

  adbd [3:100]

  NuttShell (NSH)
  nsh> adb_uv_usb_setup (154): failed to open usb device -1 2

Test

  adbd [3:100]

  NuttShell (NSH)
  nsh> adbd_main (161): Waiting for /dev/adb0/ep0 ..

  nsh> ps
    PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
      0     0   0 FIFO     Kthread   - Ready              0000000000000000 0003008 Idle_Task
      1     0 224 RR       Kthread   - Waiting  Semaphore 0000000000000000 0008080 hpwork 0x3fc8bc00 0x3fc8bc24
      2     2 100 RR       Task      - Running            0000000000000000 0003992 nsh_main
      3     3 100 RR       Task      - Waiting  Semaphore 0000000000000000 0008112 adbd
  nsh>

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
  • Loading branch information
JianyuWang0623 committed Nov 22, 2024
1 parent 365869b commit 991f28b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions system/adb/adb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#include "adb.h"

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
#include <nuttx/streams.h>

Expand All @@ -36,6 +39,17 @@
# include "netutils/netinit.h"
#endif

#define ADB_WAIT_EP_READY(ep) \
{ \
struct stat sb; \
\
while (stat(ep, &sb) != 0) \
{ \
adb_log("Waiting for %s ..", ep); \
usleep(500000); \
}; \
}

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -144,6 +158,10 @@ int main(int argc, FAR char **argv)
}
#endif /* ADBD_USB_BOARDCTL */

ADB_WAIT_EP_READY("/dev/adb0/ep0");
ADB_WAIT_EP_READY("/dev/adb0/ep1");
ADB_WAIT_EP_READY("/dev/adb0/ep2");

#ifdef CONFIG_ADBD_NET_INIT
/* Bring up the network */

Expand Down

0 comments on commit 991f28b

Please sign in to comment.