Skip to content

arch/arm/stm32h7: timestamp the transmitted frames in hardware - #20213

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
daniel-p-carvalho:feat/stm32h7-ptp-tx-hw
Sep 21, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
daniel-p-carvalho:feat/stm32h7-ptp-tx-hw

Conversation

@daniel-p-carvalho

@daniel-p-carvalho daniel-p-carvalho commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

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_Req from the hardware.

This PR adds STM32_ETH_TIMESTAMP_TX for the STM32H7, the option that #20148 defines for the legacy STM32 driver, delivered through the generic SO_TIMESTAMPING mechanism 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 the AF_PACKET socket, where recvmsg(..., 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

Testing

Built for a custom board with an STM32H753 and a DP83848 PHY, with STM32_ETH_TIMESTAMP_TX and STM32_ETH_TIMESTAMP_RX, on the current master, without errors or warnings. ./tools/checkpatch.sh -g upstream/master..HEAD passes.

On hardware, against a GNSS-referenced ptp4l Grandmaster using the IEC/IEEE 61850-9-3 profile, over AF_PACKET, with ptpd -2 -s -H -p /dev/ptp0 -B -P -i eth0 from apache/nuttx-apps#3782 and the transmit timestamps of apache/nuttx-apps#3791:

  • The peer delay was 9.0 to 9.4 us in every measurement, the same as the STM32F4 driver of arch/arm/stm32: hardware TX timestamping via SO_TIMESTAMPING #20148 against the same Grandmaster (9.27 us).
  • A run of 8.2 hours: 2824 samples of the daemon, none failed, with the clock source valid all the time. The phase difference measured by the daemon averaged 0.94 us (standard deviation 0.32 us, between -1.9 and +4.1 us), with no trend along the run. The drift was 17.3 ppm and stable, and the peer delay averaged 9.5 us.
  • The PPS outputs of the STM32H7 and of the STM32F4 board, measured on an oscilloscope against the same Grandmaster, differed by about 20 us at first and by about 1 us in a later measurement.

The end-to-end mechanism, master mode and a longer run were not tested.

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: arm Issues related to ARM (32-bit) architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Sep 20, 2026
@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@xiaoxiang781216

Copy link
Copy Markdown
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
@github-actions github-actions Bot added Size: M The size of the change in this PR is medium and removed Area: Documentation Improvements or additions to documentation Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Sep 21, 2026
@daniel-p-carvalho
daniel-p-carvalho marked this pull request as ready for review September 21, 2026 09:42
@xiaoxiang781216
xiaoxiang781216 merged commit 2674088 into apache:master Sep 21, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants