In many industrial automation, power grid, and telecommunications applications, standard NTP (Network Time Protocol) is insufficient because it only offers millisecond-level accuracy. IEEE 1588, also known as the Precision Time Protocol (PTP), provides a solution by using hardware timestamping to achieve microsecond or even nanosecond-level synchronization across a local area network.
While IEEE 1588V1 was the original standard, IEEE 1588V2 (PTPv2) improved precision and reduced network overhead. The Nuvoton NUC980 series features built-in hardware support for PTP, making it an excellent choice for time-sensitive networking tasks.
To enable PTP support, you must configure both the Linux kernel (to interface with the hardware clock) and the Buildroot target packages (to provide the user-space tools).
Step A: Linux Kernel SettingsNavigate to your kernel configuration: $ make linux-menuconfig
Enable the following paths to ensure the driver generates the /dev/ptp0 interface:
Networking support → Networking options →
Device Drivers →
Navigate to your Buildroot configuration: $ make menuconfig
Select the necessary networking utilities:
Target packages → Networking applications →
Target packages → Networking applications →
Run make to build the images.
Connect two NUC980 boards directly using an Ethernet cable.
Important: Ensure that both boards have unique MAC addresses. You can set this in your bootloader (U-Boot) or via the ifconfig command before starting the PTP service to avoid network conflicts.
Board A will act as the reference time source for the network. We will run ptp4l using the Layer-2 Ethernet transport (-2).
Behavior: The board will initially search for a master. Once it timeouts, it will assume the Grand Master role.
Board B will synchronize its Hardware Clock to Board A.
-s: Forces the node into Slave mode.
-m: Prints logs to the console so you can see the offset calculations.
By default, ptp4l only synchronizes the PTP Hardware Clock (PHC) on the Ethernet chip. To update the actual Linux system time (the clock you see when typing date), you must use phc2sys to bridge the two.
Run ptp4l in the background, then execute:
-s /dev/ptp0: Defines the source (the hardware clock).
-c CLOCK_REALTIME: Defines the destination (the Linux system clock).
-w: Waits for ptp4l to be synchronized before starting.
-R 0.2: (Optional) Sets the update rate to 0.2 Hz, meaning the system clock will update once every 5 seconds. Default is 1 Hz.
-m: (Optional) Remove this to disable console output once you verify it is working.
By leveraging the NUC980’s hardware timestamping and the linuxptp stack, you can achieve highly accurate synchronization with very little CPU overhead. This setup ensures that your distributed logs, sensor data, and control signals remain perfectly aligned across your network.
| 欢迎光临 牛卧堂MCU技术交流 (http://nuvoton-mcu.com/) | Powered by Discuz! X3.2 |