PTP Time Synchronization - ashBabu/Utilities GitHub Wiki

Precision Time Protocol (PTP / IEEE 1588) synchronizes system clocks between an Intel NUC and a Raspberry Pi down to sub-microsecond precision. Because ROS 2 records bag messages using the local operating system clock (CLOCK_REALTIME), synchronizing CLOCK_REALTIME across both devices ensures recorded ROS 2 bag timestamps align.

  • Connect the NUC and Raspberry Pi using an ethernet cable

Check Network Interface Capabilities:

Hardware vs. Software Mode

Identify the network interface name on both systems (ifconfig, e.g., eth0 or enp2s0) and check for PTP hardware timestamping support:

ethtool -T eth0

Intel NUCs and Raspberry Pi 5/CM4 boards typically support hardware timestamping (hardware-transmit, hardware-receive, hardware-raw-clock). Older Raspberry Pi models (like the Pi 4) fall back to software timestamping (software-transmit, software-receive).

Verification: Confirm that ethtool -T eth0 displays PTP Hardware Clock: 0 (or similar) for hardware mode, or lists software-transmit capabilities for software mode.

Install LinuxPTP & Disable Conflicting Time Services:

Prerequisite.Install the LinuxPTP package on both machines.

On the slave machine (Raspberry Pi), disable systemd-timesyncd or NTP so it does not interfere with PTP clock adjustments.

sudo apt update && sudo apt install -y linuxptp
sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd

Verification: Run systemctl status systemd-timesyncd on the Pi and verify the service status is inactive (dead).

Synchronize Network Clocks via ptp4l

Designate the Intel NUC as the Grandmaster (Master) and the Raspberry Pi as the Follower (Slave).

Intel NUC (Master):

sudo ptp4l -i eth0 -m -H

Raspberry Pi (Slave): sudo ptp4l -i eth0 -m -s -H

(Note: Replace -H with -S on either device if ethtool indicated software timestamping only).

Verification: Observe the terminal logs on the Pi slave; the reported rms (root mean square) offset values should stabilize below 1,000 ns for hardware timestamping (or below 100,000 ns for software timestamping).

Synchronize System Clocks via phc2sys:

OS Clock Sync.ptp4l synchronizes the Physical Hardware Clock (PHC) on the network cards. To bridge the PHC to the OS system clock (CLOCK_REALTIME), run phc2sys on both devices (in separate terminal windows):

sudo phc2sys -s eth0 -c CLOCK_REALTIME -w -m

Verification: Monitor the phc2sys terminal output; confirm that the offset parameter trends downward and stabilizes near 0 ns.