Open
Description
Right now I have a couple tasks in the ptp.yml
tasks file that I still need to write:
Time Pi - Grandmaster
- Discipline the NIC's PHY clock (could take 2-4 minutes to get into the sub-100 ns range):
- If using Chrony to sync the system clock from NTP/GPS:
sudo phc2sys -s CLOCK_REALTIME -c eth1 -m -O 0
- If using GPS directly:
sudo ts2phc -c /dev/ptp0 -s generic --ts2phc.pin_index 2 --ts2phc.extts_polarity both --ts2phc.pulsewidth 100000000 -m -l 7
- see Get PPS working with GPS #13 — and note the
extts_polarity
andpulsewidth
would not be needed with the patch referenced in that issue) - Also note, there will be no PPS events until GPS position is locked
- see Get PPS working with GPS #13 — and note the
- If using Chrony to sync the system clock from NTP/GPS:
- Set up the Pi as a PTP grandmaster on
eth1
:sudo ptp4l -i eth1 -m --masterOnly 1
(could be--serverOnly
on newer versions of linuxPTP)- Maybe set up configuration inside
/etc/linuxptp/ptp4l.conf
?
- Maybe set up configuration inside
- Discipline the system clock from the NIC's PHY:
sudo phc2sys -s /dev/ptp0 -c CLOCK_REALTIME --step_threshold=1 --transportSpecific=1 -O 37 -m
(NOTE: This offset is the current offset between TAI and UTC—it can change depending on leap seconds!)
Note: To wrap up the PTP configuration in automation, see this austinsnerdythings.com blog post, specificially the ptp4l config files).
Testing Sync on the Grandmaster:
Use testptp
to set PPS out on the proper pin:
- Install with these instructions: Get PPS working with GPS #13 (comment)
sudo testptp -d /dev/ptp0 -L0,2
(for the SMA closest to the 40-pin GPIO header)sudo testptp -d /dev/ptp0 -p 1000000000
Slave/Client Pi
This example assumes a Pi running Pi OS:
- Install linuxptp:
sudo apt install -y linuxptp
- Stop timesyncd or any other preconfigured time sync service:
sudo systemctl stop systemd-timesyncd
- Run
sudo ptp4l -i eth0 --step_threshold=1 -m --slaveOnly 1
to begin time sync over PTP- You should quickly see a message like
port 1: new foreign master 00a0c9.fffe.000002-1
, and then theoffset
values should settle in < 100ns. Ideally...
- You should quickly see a message like
- Discipline the Pi's internal clock from the PHY (could take 2-4 minutes to get into the sub-100 ns range):
sudo phc2sys -s eth0 -c CLOCK_REALTIME -q -m -w
To check if clocks are configured correctly and PTP is happy:
wget https://tsn.readthedocs.io/_downloads/f329e8dec804247b1dbb5835bd949e6f/check_clocks.c
gcc -o check_clocks check_clocks.c
sudo ./check_clocks -d eth1 # ethX depends on device setup
[see output here]
For reference:
$ phc2sys -h
usage: phc2sys [options]
automatic configuration:
-a turn on autoconfiguration
-r synchronize system (realtime) clock
repeat -r to consider it also as a time source
$ testptp -h
usage: testptp [options]
-c query the ptp clock's capabilities
-d name device to open
-l list the current pin configuration
-L pin,val configure pin index 'pin' with function 'val'
the channel index is taken from the '-i' option
'val' specifies the auxiliary function:
0 - none
1 - external time stamp
2 - periodic output
-p val enable output with a period of 'val' nanoseconds