This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch releases/13.1
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/releases/13.1 by this push:
new 3579834bc83 arch/arm/stm32h7: wait for the PHY link in milliseconds.
3579834bc83 is described below
commit 3579834bc83cf3e2b3d3722c11a8548b08ab616d
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Sun Sep 20 15:47:52 2026 -0300
arch/arm/stm32h7: wait for the PHY link in milliseconds.
The PHY was polled with nxsched_usleep(100) in a loop of 0x1998
iterations, so the time the link had to come up depended on the period
of the system tick. With the usual 10 ms tick that is about 65 s, but
with CONFIG_SCHED_TICKLESS and a 100 us tick it is about 0.65 s, shorter
than the auto-negotiation of the PHY (about 1.7 s on the board tested),
and the interface could not be brought up.
Poll every 10 ms and give the PHY up to 5 s, both for the link and for
the auto-negotiation to complete, whatever the tick.
Signed-off-by: Daniel P. Carvalho <[email protected]>
Assisted-by: Claude:claude-sonnet-5
---
arch/arm/src/stm32h7/stm32_ethernet.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/arm/src/stm32h7/stm32_ethernet.c
b/arch/arm/src/stm32h7/stm32_ethernet.c
index a0d12523050..137a11a4809 100644
--- a/arch/arm/src/stm32h7/stm32_ethernet.c
+++ b/arch/arm/src/stm32h7/stm32_ethernet.c
@@ -367,7 +367,15 @@
#define PHY_READ_TIMEOUT (0x0004ffff)
#define PHY_WRITE_TIMEOUT (0x0004ffff)
-#define PHY_RETRY_TIMEOUT (0x0001998)
+/* The PHY is polled every PHY_POLL_MS milliseconds and given up to
+ * PHY_LINK_TIMEOUT_MS milliseconds to bring the link up or to complete
+ * auto-negotiation. The time is in milliseconds so that it does not depend
+ * on the period of the system tick.
+ */
+
+#define PHY_POLL_MS (10)
+#define PHY_LINK_TIMEOUT_MS (5000)
+#define PHY_RETRY_TIMEOUT (PHY_LINK_TIMEOUT_MS / PHY_POLL_MS)
/* MAC reset ready delays in loop counts */
@@ -3425,7 +3433,7 @@ static int stm32_phyinit(struct stm32_ethmac_s *priv)
break;
}
- nxsched_usleep(100);
+ nxsched_msleep(PHY_POLL_MS);
}
if (timeout >= PHY_RETRY_TIMEOUT)
@@ -3476,7 +3484,7 @@ static int stm32_phyinit(struct stm32_ethmac_s *priv)
break;
}
- nxsched_usleep(100);
+ nxsched_msleep(PHY_POLL_MS);
}
if (timeout >= PHY_RETRY_TIMEOUT)