2025-08-13 22:28:57 +02:00

6.3 KiB

flexPTP Linux demo

flexPTP CLI

What's this?

This is a flexPTP demo project showcasing the capabilities of the flexPTP IEEE 1588 Precision Time Protocol implementation on Linux systems.

Still not clear what is it useful for? No worries, it's a behind-the-scenes support technology that you use unaware every day if you have a smartphone or when you are connected to the internet. Modern telecommunication and measurement systems often rely on precise time synchronization down to the nanoseconds' scale. Methods got standardized by the IEEE and now it's known by the name of the Precision Time Protocol. This software project is an evaluation environment to showcase the capabilities of our IEEE 1588 PTP implementation named flexPTP on Linux systems.

Note

The primary goal of the flexPTP library is supporting microcontrollers. This project and the Linux port is an exceptional, experimental project for the time being. This project has been inspired by the linuxptp application. Want to learn more about the implementation? Head to Under the hood...!

Get the sources

Note

To acquire the full source tree after cloning the repo, please fetch the linked submodules as well:

git clone https://github.com/epagris/flexPTP-demo-linux/
cd flexPTP-demo-linux
git submodule init
git submodule update

Building

Prerequisites

The following two pieces of software are necessary for building:

  • gcc (v12+): the GCC C
  • cmake (v3.22+): KitWare's build management system

Compiling

The project is fully CMake managed. Configure and invoke the cross-compiler using the commands below:

cmake . -B build
cmake --build build --target flexptp_linux --

Once the building has concluded the output binary will be deposited in the build directory: flexptp_linux.

Running

Start the flexptp_linux application with superuser right so it can execute privileged socket- and PHC-related commands. Pass the targeted network interface using the -i parameter, e.g. sudo flexptp_linux -i eth0 Connect your device to any PTP-compliant equipment (e.g. another Linux-based machine or embedded system with flexPTP or linuxptp) to test the flexPTP library. The application has an all-around CLI implemented. Startup configuration can be passed using the -c parameter (e.g. sudo flexptp_linux -i eth0 -c flexptp_startup.cfg) which should contain one command per line (like typing commands on the CLI).

The flexPTP parameters are defined in the flexptp_options.h header.

CLI commands

The software offers you with the following multitude, most flexPTP-related of commands:

?                                                  Print this help
ptp reset                                          Reset PTP subsystem
ptp servo offset [offset_ns]                       Set or query clock offset
ptp log {def|corr|ts|info|locked|bmca} {on|off}    Turn on or off logging
time [ns]                                          Print time
ptp master [[un]prefer] [clockid]                  Master clock settings
ptp info                                           Print PTP info
ptp domain [domain]                                Print or get PTP domain
ptp addend [addend]                                Print or set addend
ptp transport [{ipv4|802.3}]                       Set or get PTP transport layer
ptp delmech [{e2e|p2p}]                            Set or get PTP delay mechanism
ptp transpec [{def|gPTP}]                          Set or get PTP transportSpecific field (majorSdoId)
ptp profile [preset [<name>]]                      Print or set PTP profile, or list available presets
ptp tlv [preset [name]|unload]                     Print or set TLV-chain, or list available TLV presets
ptp pflags [<flags>]                               Print or set profile flags
ptp period <delreq|sync|ann> [<lp>|matched]        Print or set log. periods
ptp coarse [threshold]                             Print or set coarse correction threshold
ptp priority [<p1> <p2>]                           Print or set clock priority fields

Tip

The above hint can be listed by typing '?'.

Tested systems

The flexPTP Linux port has been tested on x86-based (64-bit generic PCs, Ubuntu 24.04, Ubuntu 24.10) and ARM-based (32-bit BeagleBone Black Industrial SBC, Debian 12) Linux systems.

All network interfaces supported by the kernel's PHC infrastructure can be used with flexPTP as well. The operation has been confirmed with the following Intel NICs:

  • Intel 82576
  • Intel I210
  • Intel I219-V
  • Intel E810

Under the hood

The porting layer used in this project is very much different compared to a conventional port supporting a specific microcontroller. The Network Stack Driver and the Hardware Port got unified into the single nsd_linux.c source file. The port uses the Linux kernel's built-in PHC-adjustment functions and standard POSIX socket operations. Each major step is documented in the NSD source file.

Time Synchronization Extension for the IO-Link Industrial Communication Protocol

Distributed Measurement System for Performance Evaluation of Embedded Clock Synchronization Solutions

Portable, PTP-based Clock Synchronization Implementation for Microcontroller-based Systems and its Performance Evaluation

Synchronization of Sampling in a Distributed Audio Frequency Range Data Acquisition System Utilizing Microcontrollers

Methods of Peripheral Synchronization in Real-Time Cyber-Physical Systems

License

The project was created by András Wiesner (Epagris) in 2025 and published under the MIT license. Contributions are welcome! :)