From 52d0be45b9b3ced0a6e8b44624e0630035b687f8 Mon Sep 17 00:00:00 2001 From: "Daniel P. Carvalho" Date: Mon, 21 Sep 2026 18:48:27 -0300 Subject: [PATCH] arch/arm/stm32h7: fix the period of the PPS output. The interval and the width of the pulse train of the PPS output were programmed as the number of increments of the system time minus one, but the MAC takes them as they are. Each period was one increment (10 ns with HCLK at 200 MHz) shorter than a second, so the pulses came 10 ns early each second, about 36 us in an hour, and the output drifted away from the system time. Program the interval and the width without subtracting one. On a run of 8.2 hours against a grandmaster clock the pulse moved 0.29 ms ahead of the system time, which is 10 ns per second, while the system time stayed within 1 us of the grandmaster. With the change, a run of 11 hours showed no drift of the pulse against the system time, within 3 us per hour on samples of 1 ms of resolution. Signed-off-by: Daniel P. Carvalho Assisted-by: Claude:claude-sonnet-5 --- arch/arm/src/stm32h7/stm32_ethernet.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/arm/src/stm32h7/stm32_ethernet.c b/arch/arm/src/stm32h7/stm32_ethernet.c index aa919d6d237b5..bda84f897a3ba 100644 --- a/arch/arm/src/stm32h7/stm32_ethernet.c +++ b/arch/arm/src/stm32h7/stm32_ethernet.c @@ -296,13 +296,12 @@ * second and a width of half of it, that starts at a whole second of the * system time. The first pulse is at least STM32_PTP_PPS_MARGIN_NS ahead, * so the target time is loaded before it. The interval and the width are - * in increments of the system time, minus one. + * in increments of the system time. */ # define STM32_PTP_PPS_MARGIN_NS (100000000) -# define STM32_PTP_PPS_INTERVAL (NSEC_PER_SEC / STM32_PTP_SSINC - 1) -# define STM32_PTP_PPS_WIDTH ((NSEC_PER_SEC / 2) / \ - STM32_PTP_SSINC - 1) +# define STM32_PTP_PPS_INTERVAL (NSEC_PER_SEC / STM32_PTP_SSINC) +# define STM32_PTP_PPS_WIDTH ((NSEC_PER_SEC / 2) / STM32_PTP_SSINC) # endif #endif