From 3fd4ea8587a3e14977a84580bf4d9140917e379f Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Tue, 7 Feb 2023 14:14:38 +0100 Subject: [PATCH] nxscope/nxscope_iser.c: wait for device if CONFIG_SERIAL_REMOVALBE=y --- logging/nxscope/nxscope_iser.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/logging/nxscope/nxscope_iser.c b/logging/nxscope/nxscope_iser.c index 35004dd95..61860abe8 100644 --- a/logging/nxscope/nxscope_iser.c +++ b/logging/nxscope/nxscope_iser.c @@ -177,10 +177,35 @@ int nxscope_ser_init(FAR struct nxscope_intf_s *intf, flags |= O_NONBLOCK; } +#ifdef CONFIG_SERIAL_REMOVABLE + do + { + /* Try to open the console */ + + priv->fd = open(priv->cfg->path, flags); + if (priv->fd < 0) + { + /* ENOTCONN means that the USB device is not yet connected. + * Anything else is bad. + */ + + if (errno != ENOTCONN) + { + break; + } + + /* Sleep a bit and try again */ + + sleep(1); + } + } + while (priv->fd < 0); +#else priv->fd = open(priv->cfg->path, flags); +#endif if (priv->fd < 0) { - _err("ERROR: failed to open %s\n", priv->cfg->path); + _err("ERROR: failed to open %s %d\n", priv->cfg->path, errno); ret = -errno; goto errout; }