Skip to content

Support gPTP sync with PI control and fix i.MXRT1060 support #89234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 2, 2025

Conversation

yangbolu1991
Copy link
Contributor

@yangbolu1991 yangbolu1991 commented Apr 29, 2025

I'm just starting to look at zephyr gPTP with a i.MXRT1060 EVK board on hand.
It looks like there are many problems in both drivers and gPTP stack.
So, I basically fixed key issues in ENET MAC/PTP drivers for RT1060. Also added a simple PI control algorithm to support continuous frequency adjustment in gPTP stack.

Finally the sync offset convergence on RT1060 was as below log. It's stable at about 100ns sync offset. (RT1060 PTP clock nominal frequency is 25M, 40ns period)

[00:00:02.822,000] <inf> phy_mc_ksz8081: PHY 0 is up
[00:00:02.822,000] <inf> phy_mc_ksz8081: PHY (0) Link speed 100 Mb, full duplex

[00:00:02.823,000] <inf> eth_nxp_enet_mac: Link is up
*** Booting Zephyr OS build v4.1.0-3062-g764340614802 ***
[00:00:02.826,000] <inf> net_config: Initializing network
[00:00:02.826,000] <inf> net_config: IPv4 address: 192.0.2.1
[00:00:02.928,000] <inf> net_config: IPv6 address: 2001:db8::1
[00:00:03.830,000] <wrn> net_gptp: Reset Pdelay requests
[00:00:05.268,000] <dbg> net_gptp_sample: gptp_phase_dis_cb: GM FA:FA:62:FF:FE:FE:A2:11 last phase 0.0
[00:00:06.893,000] <inf> net_gptp: sync offset   -117781 ns, freq offset -117781.000000 ppb
[00:00:07.894,000] <inf> net_gptp: sync offset    -73643 ns, freq offset -108977.300000 ppb
[00:00:08.894,000] <inf> net_gptp: sync offset    -37936 ns, freq offset -95363.200000 ppb
[00:00:09.894,000] <inf> net_gptp: sync offset    -15866 ns, freq offset -84674.000000 ppb
[00:00:10.895,000] <inf> net_gptp: sync offset     -4318 ns, freq offset -77885.800000 ppb
[00:00:11.895,000] <inf> net_gptp: sync offset       564 ns, freq offset -74299.200000 ppb
[00:00:12.895,000] <inf> net_gptp: sync offset      1731 ns, freq offset -72963.000000 ppb
[00:00:13.895,000] <inf> net_gptp: sync offset      1687 ns, freq offset -72487.700000 ppb
[00:00:14.896,000] <inf> net_gptp: sync offset      1098 ns, freq offset -72570.600000 ppb
[00:00:15.896,000] <inf> net_gptp: sync offset       540 ns, freq offset -72799.200000 ppb
[00:00:16.896,000] <inf> net_gptp: sync offset       181 ns, freq offset -72996.200000 ppb
[00:00:17.896,000] <inf> net_gptp: sync offset       127 ns, freq offset -72995.900000 ppb
[00:00:18.896,000] <inf> net_gptp: sync offset       -50 ns, freq offset -73134.800000 ppb
[00:00:19.897,000] <inf> net_gptp: sync offset        59 ns, freq offset -73040.800000 ppb
[00:00:20.897,000] <inf> net_gptp: sync offset       -39 ns, freq offset -73121.100000 ppb
[00:00:21.897,000] <inf> net_gptp: sync offset        41 ns, freq offset -73052.800000 ppb
[00:00:22.897,000] <inf> net_gptp: sync offset       -89 ns, freq offset -73170.500000 ppb
[00:00:23.897,000] <inf> net_gptp: sync offset        62 ns, freq offset -73046.200000 ppb
[00:00:24.897,000] <inf> net_gptp: sync offset       -64 ns, freq offset -73153.600000 ppb
[00:00:25.898,000] <inf> net_gptp: sync offset       -27 ns, freq offset -73135.800000 ppb
[00:00:26.898,000] <inf> net_gptp: sync offset        50 ns, freq offset -73066.900000 ppb
[00:00:27.898,000] <inf> net_gptp: sync offset        -3 ns, freq offset -73104.900000 ppb
[00:00:28.899,000] <inf> net_gptp: sync offset        66 ns, freq offset -73036.800000 ppb
[00:00:29.899,000] <inf> net_gptp: sync offset       -63 ns, freq offset -73146.000000 ppb
[00:00:30.899,000] <inf> net_gptp: sync offset       -28 ns, freq offset -73129.900000 ppb
[00:00:31.900,000] <inf> net_gptp: sync offset       132 ns, freq offset -72978.300000 ppb
[00:00:32.900,000] <inf> net_gptp: sync offset        -7 ns, freq offset -73077.700000 ppb
[00:00:33.900,000] <inf> net_gptp: sync offset      -139 ns, freq offset -73211.800000 ppb
[00:00:34.901,000] <inf> net_gptp: sync offset       -58 ns, freq offset -73172.500000 ppb
[00:00:35.901,000] <inf> net_gptp: sync offset         1 ns, freq offset -73130.900000 ppb
[00:00:36.901,000] <inf> net_gptp: sync offset        82 ns, freq offset -73049.600000 ppb
[00:00:37.901,000] <inf> net_gptp: sync offset        -4 ns, freq offset -73111.000000 ppb
[00:00:38.902,000] <inf> net_gptp: sync offset       109 ns, freq offset -72999.200000 ppb

Thanks.

The RT10XX uses fixed 25M for PTP clock per RM. Verified on
RT1060.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
The enet handle in mac driver was not shared with ptp driver
properly. This was causing wrong TX timestamp.
This patch is to fix it.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
The rate adjustment should be based on nomianl frequency, but not
current frequency. Then any PTP stack with PID control could adjust
frequency well.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Converted ENET_Ptp1588Configure to ENET_Ptp1588StartTimer during reset.
This is to avoid configuring IRQ handlers again in hal driver with
ENET_Ptp1588Configure.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
@yangbolu1991
Copy link
Contributor Author

@jukkar
Regarding to PTP, I just added ptp clock shell commands support. You may help to review if you are interested in it:)
#89243

Thanks.

@yangbolu1991
Copy link
Contributor Author

Updated to v2. Changes include,

  • Added CONFIG_NET_GPTP_MONITOR_SYNC_STATUS to monitor real-time sync status, and print messages. Not only time offset and frequency offset now, there will be more users care about, like path delay, best clock changes and so on.

Thanks.

Current clock synchronization was always stepping clock. This was
causing large offset, and discontiguous ptp hardware clock time.
For TSN hardware, discontiguous ptp hardware clock time was not
able to be used for other TSN protocols.

This patch is to convert to frequency adjustment with a basic
PI control algorithm.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
@dleach02 dleach02 closed this May 1, 2025
@dleach02 dleach02 reopened this May 1, 2025
@kartben kartben merged commit f8b450d into zephyrproject-rtos:main May 2, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants