jclark / rpi-cm4-ptp-guide

Guide to using the hardware PTP support in the Raspberry Pi CM4
MIT License
80 stars 10 forks source link
ptp raspberry-pi

Guide to using the hardware PTP support in the Raspberry Pi CM4

This is still a work-in-progress. Suggestions for improvements are very welcome and can be made by creating issues.

The Raspberry Pi Compute Module 4 (CM4) has hardware support for the Precision Time Protocol (PTP). This repository is a guide to how to use this to provide an accurate source of time within your local network.

Although the CM4 does not have an Ethernet jack, it does have an Ethernet PHY, the Broadcom BCM54210PE, which has support for PTP. Linux kernel support for this was added recently (2022), as discussed in https://github.com/raspberrypi/linux/issues/4151. This support has now been merged into the mainline Linux kernel.

The PTP support involves the Ethernet PHY having its own clock, called the PTP hardware clock (PHC), and being able to use this clock to timestamp incoming and outgoing network packets. This enables the CM4 to make use of PTP, but it is not by itself particularly exciting: similar functionality is available on many NICs. The exciting part is that the CM4 provides a pin that allows the PHC to be synchronized with an external pulse per second (PPS) signal. When this pin is connected to the PPS output of a GPS receiver, the CM4 can providech a highly accurate source of time for PTP within a local area network. (As far as I know, the only other inexpensive, easy way to to get this functionality is using an Intel i210-T1 PCIe card.) The CM4 can also generate a PPS signal from the PHC on this pin: this makes it possible to measure the accuracy of the PHC.

There's a useful introductory blog from Jeff Geerling and also a video.

This goal of this repository is to be a guide to taking advantage of this. The guide is split into the following sections:

Results

This shows the results from using a TAPR TICC in interval mode with two CM4 PTP slaves

tdev-20221129 mtie-20221129

References

Fedora has great docs for PTP, although some details are different for Raspberry Pi OS, which is Debian-based.