arch/arm/stm32h7: timestamp the transmitted frames in hardware - #20213
Merged
xiaoxiang781216 merged 1 commit intoSep 21, 2026
Merged
Conversation
Contributor
|
@daniel-p-carvalho please fix the conflict |
Support STM32_ETH_TIMESTAMP_TX on the STM32H7, as the legacy STM32 do, with the timestamp returned through SO_TIMESTAMPING. When a packet socket asks for the transmit timestamp of a frame, keep a copy of the frame and ask the MAC to timestamp it in the descriptor. When the transmission is done, take the timestamp from the descriptor and give the copy back to the network stack with it, that delivers it to the error queue of the socket. The MAC writes the timestamp over the address of the buffer in the descriptor, so the driver keeps the buffer of these descriptors. The copies that still wait for their timestamp are released when the interface goes down. With a PTP daemon using the peer-to-peer delay mechanism against a grandmaster clock, the path delay measured was between 9.0 and 9.1 us. Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com> Assisted-by: Claude:claude-sonnet-5
daniel-p-carvalho
force-pushed
the
feat/stm32h7-ptp-tx-hw
branch
from
September 21, 2026 09:36
e157cfe to
563b50e
Compare
daniel-p-carvalho
marked this pull request as ready for review
September 21, 2026 09:42
daniel-p-carvalho
requested review from
davids5,
raiden00pl and
xiaoxiang781216
as code owners
September 21, 2026 09:42
acassis
approved these changes
Sep 21, 2026
jerpelea
approved these changes
Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The STM32H7 MAC can capture a timestamp for every transmitted frame, but the driver only timestamped received frames (#20212). A PTP daemon using the peer-to-peer delay mechanism needs the transmit time of its
Pdelay_Reqfrom the hardware.This PR adds
STM32_ETH_TIMESTAMP_TXfor the STM32H7, the option that #20148 defines for the legacy STM32 driver, delivered through the genericSO_TIMESTAMPINGmechanism of the network stack (#20161): when a frame is flagged for timestamping, the driver keeps a copy of it, sets the timestamp enable bit in its descriptor and, when the transmission is done, reads the timestamp from the descriptor and loops the copy back to theAF_PACKETsocket, whererecvmsg(..., MSG_ERRQUEUE)returns it. The MAC writes the timestamp over the address of the buffer in the descriptor, so the driver keeps the buffer of these descriptors.It builds on #20148 and #20212, which are merged, so it is a single commit now.
Impact
STM32_ETH_TIMESTAMP_TX(default n, needsSTM32_ETH_PTPandNET_TIMESTAMP), so boards that do not enable it are not affected. The dependency of the option is widened to include the STM32H7 and STM32H5./dev/ptp0as its clock.appsside,ptpdreading the transmit timestamp from the error queue, is netutils/ptpd: hardware TX timestamps via MSG_ERRQUEUE and egress latency compensation nuttx-apps#3791, which builds on netutils/ptpd: IEEE 1588 P2P delay mechanism, hardware clock phase-lock and outlier rejection nuttx-apps#3782.Testing
Built for a custom board with an STM32H753 and a DP83848 PHY, with
STM32_ETH_TIMESTAMP_TXandSTM32_ETH_TIMESTAMP_RX, on the currentmaster, without errors or warnings../tools/checkpatch.sh -g upstream/master..HEADpasses.On hardware, against a GNSS-referenced
ptp4lGrandmaster using the IEC/IEEE 61850-9-3 profile, overAF_PACKET, withptpd -2 -s -H -p /dev/ptp0 -B -P -i eth0from apache/nuttx-apps#3782 and the transmit timestamps of apache/nuttx-apps#3791:The end-to-end mechanism, master mode and a longer run were not tested.