This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 649f10389327d6285669af7917654788be96ef29
Author: Bowen Wang <[email protected]>
AuthorDate: Mon Jul 13 20:39:55 2026 +0800

    drivers/rpmsg/rpmsg_port_spi: log when rx recovers after errors
    
    The rx error paths were fire-and-forget: once frames started being
    dropped as malformed or failing CRC, the log flooded with errors but
    never marked the point where the link recovered, making it hard to tell
    from a capture when communication actually came back.
    
    Latch a consecutive-error counter in the SPI master/slave rx paths and,
    on the first frame that passes all checks again, emit a single
    "rx recovered after N errors" line and clear it. Do the same at the
    retx layer: rpmsg_port_retx_rx_valid() now counts seqno-mismatch fails
    and prints "rx_validate recovered after N fails" on the first match,
    which is the most direct recovery marker for the rx_validate flooding
    seen in the field. Counters saturate at UINT16_MAX to avoid wrap.
    
    The two counters track distinct protocol layers and do not overlap:
    rxerr_count is bumped on the malformed/CRC-fail paths in the SPI
    handler, where the frame is dropped with goto out and never reaches the
    retx state machine, so it measures physical-layer damage (framing/CRC).
    rx_valid_fail is bumped only for a structurally intact DATA frame whose
    seqno does not match rx_next, so it measures sequence-state divergence.
    A malformed/CRC-bad frame can therefore never be seen by rx_valid, and
    the two-phase field failure (framing errors first, then rx_validate
    flooding) is only distinguishable by watching both counters separately.
    
    Diagnostics only; no behavioral change to the data path.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_port.c           | 12 ++++++++++++
 drivers/rpmsg/rpmsg_port.h           |  1 +
 drivers/rpmsg/rpmsg_port_spi.c       | 21 +++++++++++++++++++++
 drivers/rpmsg/rpmsg_port_spi_slave.c | 21 +++++++++++++++++++++
 4 files changed, 55 insertions(+)

diff --git a/drivers/rpmsg/rpmsg_port.c b/drivers/rpmsg/rpmsg_port.c
index f05f3f48414..2d143d21ff5 100644
--- a/drivers/rpmsg/rpmsg_port.c
+++ b/drivers/rpmsg/rpmsg_port.c
@@ -844,11 +844,23 @@ bool rpmsg_port_retx_rx_valid(FAR struct rpmsg_port_s 
*port,
   flags = spin_lock_irqsave(&port->retx.lock);
   if (hdr->seqno == port->retx.rx_next)
     {
+      if (port->retx.rx_valid_fail != 0)
+        {
+          rpmsgerr("rx_validate recovered after %u fails, seq:%u\n",
+                   port->retx.rx_valid_fail, hdr->seqno);
+          port->retx.rx_valid_fail = 0;
+        }
+
       port->retx.rx_next++;
       valid = true;
     }
   else
     {
+      if (port->retx.rx_valid_fail != UINT16_MAX)
+        {
+          port->retx.rx_valid_fail++;
+        }
+
       rpmsgerr("rx_validate FAIL got seq:%u expect:%u cmd:%u\n",
                hdr->seqno, port->retx.rx_next, hdr->cmd);
     }
diff --git a/drivers/rpmsg/rpmsg_port.h b/drivers/rpmsg/rpmsg_port.h
index b854f59d0da..630e46f39e6 100644
--- a/drivers/rpmsg/rpmsg_port.h
+++ b/drivers/rpmsg/rpmsg_port.h
@@ -165,6 +165,7 @@ struct rpmsg_port_retx_s
   uint16_t                          rx_next;
   uint16_t                          last_ackno;
   uint16_t                          retx_max_retry;
+  uint16_t                          rx_valid_fail;
 };
 #endif
 
diff --git a/drivers/rpmsg/rpmsg_port_spi.c b/drivers/rpmsg/rpmsg_port_spi.c
index 4cafe79a8aa..fc8e2b00aa6 100644
--- a/drivers/rpmsg/rpmsg_port_spi.c
+++ b/drivers/rpmsg/rpmsg_port_spi.c
@@ -114,6 +114,10 @@ struct rpmsg_port_spi_s
   uint16_t                       rxavail;
   uint16_t                       rxthres;
 
+  /* Count of consecutive rx errors, latched for recovery logging */
+
+  uint16_t                       rxerr_count;
+
   atomic_t                       transferring;
 };
 
@@ -434,6 +438,11 @@ static void rpmsg_port_spi_complete_handler(FAR void *arg)
                rpspi->rxhdr->seqno, rpspi->rxhdr->ackno,
                rpspi->rxhdr->min_seq, rpspi->port.retx.rx_next);
 #endif
+      if (rpspi->rxerr_count != UINT16_MAX)
+        {
+          rpspi->rxerr_count++;
+        }
+
       goto out;
     }
 
@@ -451,10 +460,22 @@ static void rpmsg_port_spi_complete_handler(FAR void *arg)
           rpmsgerr("retx crc check fail received: seq=%u\n",
                    rpspi->rxhdr->seqno);
 #endif
+          if (rpspi->rxerr_count != UINT16_MAX)
+            {
+              rpspi->rxerr_count++;
+            }
+
           goto out;
         }
     }
 
+  if (rpspi->rxerr_count != 0)
+    {
+      rpmsgerr("rx recovered after %u errors, cmd=%u\n",
+               rpspi->rxerr_count, rpspi->rxhdr->cmd);
+      rpspi->rxerr_count = 0;
+    }
+
   rpmsg_port_update_timestamp(&rpspi->port.rxq, rpspi->rxhdr, false);
 
   /* Skip any data received when connection is not established until a
diff --git a/drivers/rpmsg/rpmsg_port_spi_slave.c 
b/drivers/rpmsg/rpmsg_port_spi_slave.c
index d61d7420695..74569041530 100644
--- a/drivers/rpmsg/rpmsg_port_spi_slave.c
+++ b/drivers/rpmsg/rpmsg_port_spi_slave.c
@@ -118,6 +118,10 @@ struct rpmsg_port_spi_s
   uint16_t                       rxavail;
   uint16_t                       rxthres;
 
+  /* Count of consecutive rx errors, latched for recovery logging */
+
+  uint16_t                       rxerr_count;
+
   atomic_t                       transferring;
 };
 
@@ -512,6 +516,11 @@ static void rpmsg_port_spi_slave_notify(FAR struct 
spi_slave_dev_s *dev,
                rpspi->rxhdr->seqno, rpspi->rxhdr->ackno,
                rpspi->rxhdr->min_seq, rpspi->port.retx.rx_next);
 #endif
+      if (rpspi->rxerr_count != UINT16_MAX)
+        {
+          rpspi->rxerr_count++;
+        }
+
       goto out;
     }
 
@@ -529,10 +538,22 @@ static void rpmsg_port_spi_slave_notify(FAR struct 
spi_slave_dev_s *dev,
           rpmsgerr("retx crc check fail received: seq=%u\n",
                    rpspi->rxhdr->seqno);
 #endif
+          if (rpspi->rxerr_count != UINT16_MAX)
+            {
+              rpspi->rxerr_count++;
+            }
+
           goto out;
         }
     }
 
+  if (rpspi->rxerr_count != 0)
+    {
+      rpmsgerr("rx recovered after %u errors, cmd=%u\n",
+               rpspi->rxerr_count, rpspi->rxhdr->cmd);
+      rpspi->rxerr_count = 0;
+    }
+
   rpmsg_port_update_timestamp(&rpspi->port.rxq, rpspi->rxhdr, false);
 
   /* Skip any data received when connection is not established until a

Reply via email to