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

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

commit 5938f58fd8be1d0527c37d715937119ac3e3dba9
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Sun Sep 13 12:21:26 2026 -0300

    arch/arm/stm32: Convert RX hardware timestamp before pkt_input().
    
    stm32_receive() called pkt_input() before
    stm32_eth_ptp_convert_rxtime(), so every packet handed to a packet
    socket carried the previous frame's RX timestamp instead of its own
    in dev->d_rxtime. Reorder so the timestamp is converted first.
    
    Assisted-by: Claude:claude-sonnet-5
    Signed-off-by: Daniel P. Carvalho <[email protected]>
    (cherry picked from commit 9bfa20da28da79a567e3b38cb127767cf9e03042)
---
 arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c 
b/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c
index b151bf6e9ce..6614bdc1073 100644
--- a/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c
+++ b/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c
@@ -1714,12 +1714,6 @@ static void stm32_receive(struct stm32_ethmac_s *priv)
 
   while (stm32_recvframe(priv) == OK)
     {
-#ifdef CONFIG_NET_PKT
-      /* When packet sockets are enabled, feed the frame into the tap */
-
-      pkt_input(&priv->dev);
-#endif
-
       /* Check if the packet is a valid size for the network buffer
        * configuration (this should not happen)
        */
@@ -1741,9 +1735,24 @@ static void stm32_receive(struct stm32_ethmac_s *priv)
         }
 
 #ifdef CONFIG_STM32_ETH_TIMESTAMP_RX
+      /* Convert this frame's hardware RX timestamp before handing the
+       * frame to pkt_input() below. pkt_input() copies dev->d_rxtime
+       * into the packet socket's queued metadata immediately, so if
+       * the conversion ran after it, every packet would be tagged
+       * with the *previous* frame's timestamp instead of its own,
+       * introducing effectively random error on the order of the
+       * inter-frame interval into every RX timestamp.
+       */
+
       stm32_eth_ptp_convert_rxtime(priv);
 #endif
 
+#ifdef CONFIG_NET_PKT
+      /* When packet sockets are enabled, feed the frame into the tap */
+
+      pkt_input(&priv->dev);
+#endif
+
       /* We only accept IP packets of the configured type and ARP packets */
 
 #ifdef CONFIG_NET_IPv4

Reply via email to