From 991f28b70ebf531d25bbb6b7e6a47b9a0914c940 Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Fri, 22 Nov 2024 20:27:30 +0800 Subject: [PATCH] system/adb: Waiting for enumeration to complete before opening endpoint 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 --- system/adb/adb_main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/system/adb/adb_main.c b/system/adb/adb_main.c index bc2cd36bc29..f07a5103851 100644 --- a/system/adb/adb_main.c +++ b/system/adb/adb_main.c @@ -24,6 +24,9 @@ #include "adb.h" +#include +#include +#include #include #include @@ -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 ****************************************************************************/ @@ -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 */