牛卧堂MCU技术交流

标题: [NUC980] Precision Time Protocol (PTP): Synchronizing Time on NUC980 [打印本页]

作者: admin    时间: 4 天前
标题: [NUC980] Precision Time Protocol (PTP): Synchronizing Time on NUC980
1. Introduction

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.


2. Buildroot and Kernel Configuration

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 Settings

Navigate to your kernel configuration: $ make linux-menuconfig

Enable the following paths to ensure the driver generates the /dev/ptp0 interface:

Step B: Buildroot Tool Selection

Navigate to your Buildroot configuration: $ make menuconfig

Select the necessary networking utilities:

Run make to build the images.


3. Hardware Setup

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.


4. Step-by-Step SynchronizationBoard A: The Grand Master

Board A will act as the reference time source for the network. We will run ptp4l using the Layer-2 Ethernet transport (-2).


# ptp4l -i eth0 -2 -m



Board B: The Client (Slave)

Board B will synchronize its Hardware Clock to Board A.


# ptp4l -i eth0 -2 -s -m



Step 5: Synchronizing the System Clock

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:


# ptp4l -i eth0 -2 -s &# phc2sys -s /dev/ptp0 -c CLOCK_REALTIME -w -m -R 0.2




Conclusion

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