VAR-SOM-MX6 Eth IEEE.1588: Difference between revisions

From Variscite Wiki
 
(58 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{PageHeader|IEE1588 Hardware Timestamp}} {{DocImage|category1=Yocto|category2=VAR-SOM-MX6}}[[Category: DART-6UL]][[Category: VAR-SOM-MX7]] __toc__
{{PageHeader|VAR-SOM-MX6 - IEEE 1588 Hardware Timestamp}} {{DocImage|category1=Yocto|category2=VAR-SOM-MX6}}__toc__


= Overview of IEE1588 Hardware Timestamping =
= Overview of IEEE 1588 Hardware Timestamping =
For a basic overview of IEEE 1588 and PTP, please refer to https://elinux.org/images/f/f9/Introduction_to_IEEE_1588_Precision_Time_Protocol_%28PTP%29_Using_Embedded_Linux_Systems.pdf<br>
 
At the very top level, it allows high precision time synchronization over a packet-based network, and can be described by the below image:<br>
[[File:IEEE_1588_Basic_Overview.png]]<br>
 
 
 
NXP Supports IEEE 1588 PTP implemented in the SOC Ethernet MAC layer:<br>
[[File:IMX_IEEE_1588_functions.png]]<br>
 
The NXP IEEE 1588 PTP and timer implementation have the following features:
* Allows reference clock to be chosen independently of network speed.
* Allows reference clock to be chosen independently of network speed.
* Software-programmable precise time-stamping of ingress and egress frames
* Software-programmable precise time-stamping of ingress and egress frames.
* Timer monitoring capabilities for system calibration and timing accuracy management
* Timer monitoring capabilities for system calibration and timing accuracy management.
* Precise time-stamping of external events with programmable interrupt generation
* Precise time-stamping of external events with programmable interrupt generation.
* Programmable event and interrupt generation for external system control
* Programmable event and interrupt generation for external system control.
* Supports hardware- and software-controllable timer synchronization.
* Supports hardware and software-controllable timer synchronization.
* Provides a 4-channel IEEE 1588 timer. Each channel supports input capture and output compare using the 1588 counter.
* Provides a 4-channel IEEE 1588 timer. Each channel supports input capture and output compare using the 1588 counter.
* Distribution of precise time information over the packetbased network
* Distribution of precise time information over the packet-based network.
* Offers high accuracy (sub micro sec) over the network
* Offers high accuracy (in the sub-microsecond range) over the network.


= Hardware Setup =
= Hardware Setup =
* For DART-MX6: physically remove U109 (RTC IC) and R137 (i2c3_sda pull-up) from the board.
* Network Setup: Connect the PC/Grand Master Clock Source and the target to the same Ethernet network (and use ping to verify the connection between the PC and the target).


= Software =
= Software =
ptp4l, pmc, phc2sys
In the current setup, we will have <br>
* PC - Grand Master which acts as the clock source which has the GPS clock synchronized<br>
Note: You may choose Device (i.MX6) as grandmaster clock as a device as well. <br>
* Device - i.MX6 with IEEE 1588 HW timestamp support - of which local clock to be synchronized with grandmaster <br>
 
 
Software utilities required for PTP
$ ptp4l
$ phc2sys
 
For Ubuntu 16.04
$ sudo apt-get install linuxptp
Start the software base timestamping on PC or to become grandmaster clock source which you want to synchronize.<br>
 
Make sure you have following device tree change present on your kernel.<br>
Note that in this example, i2c3 bus is disabled for DART-MX6, in order to free the pins used by the IEEE 1588 hardware timestamping.<br>
For more details about pinmuxing<br>
- VAR-SOM-MX6: https://www.variscite.com/wp-content/uploads/2017/12/VAR-SOM-SOLO_DUAL_Datasheet.pdf<br>
- DART-MX6: https://www.variscite.com/wp-content/uploads/2017/11/DART-MX6-Datasheet.pdf<br>
- VAR-SOM-SOLO/DUAL: https://www.variscite.com/wp-content/uploads/2017/12/VAR-SOM-SOLO_DUAL_Datasheet.pdf<br>
 
You may need to disable certain pins to get the HW EVENTX_IN/OUT and insert in the device tree, to get your external input / output for the HW timer to work.<br>
<br>
Below code example is for DART-MX6
 
<syntaxhighlight lang="diff">
diff --git a/arch/arm/boot/dts/imx6qdl-var-dart.dtsi b/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
index 64e9b91..407c4fe 100644
--- a/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
@@ -217,6 +217,7 @@
        };


==Master Clock==
        ov564x_mipi: ov564x_mipi@3c {
ptp4l -H -A -l 7 -q -i eth0 -m -s
+              status = "disabled";
                compatible = "ovti,ov564x_mipi";
                reg = <0x3c>;
                clocks = <&clks 200>;
@@ -320,16 +321,7 @@
};


&i2c3 {
-      clock-frequency = <100000>;
-      pinctrl-names = "default";
-      pinctrl-0 = <&pinctrl_i2c3_3>;
-      status = "okay";
-
-      /* DS1337 RTC module */
-      rtc@0x68 {
-              compatible = "dallas,ds1337";
-              reg = <0x68>;
-      };
+      status = "disabled";
};


&iomuxc {
@@ -379,6 +371,7 @@
                                MX6QDL_PAD_RGMII_RD2__RGMII_RD2            0x1b0b0
                                MX6QDL_PAD_RGMII_RD3__RGMII_RD3            0x1b0b0
                                MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL      0x1b0b0
+                              MX6QDL_PAD_GPIO_16__ENET_REF_CLK        0x4001b0a8
                        >;
                };
@@ -415,13 +408,6 @@
                        >;
                };
-              pinctrl_i2c3_3: i2c3grp {
-                      fsl,pins = <
-                              MX6QDL_PAD_GPIO_5__I2C3_SCL            0x4001b8b1
-                              MX6QDL_PAD_GPIO_16__I2C3_SDA            0x4001b8b1
-                      >;
-              };
-
                pinctrl_ipu1: ipu1grp {
                        fsl,pins = <
                                MX6QDL_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK      0x10
</syntaxhighlight>
$ sudo ptp4l -i  enp5s0 -m -S
- Here, in this case, the PC sends the timestamp using software timer.<br>
- The timestamp packets are sent over networking infrastructure via switch/router (IEEE 1588 packets) <br>
and then once received on the target, it is used to synchronize the clock with 1μs accuracy. <br>
- Hardware has the test and compares logic to see the drift and jitter.
== Testing on device side ==
ptp4l works as a daemon service. It must be started first before any system level PTP client can work.<br>
Yocto build already contains the ptp4l required resoureces on the target.<br>
Run following commands on target<br>
<pre>
root@var-som-mx6:~# ptp4l -H -A -l 7 -q -i eth0 -m -s &
ptp4l[2175.985]: config item (null).assume_two_step is 0
ptp4l[2175.985]: config item (null).check_fup_sync is 0
ptp4l[2175.985]: config item (null).tx_timestamp_timeout is 1
ptp4l[2175.985]: config item (null).clock_servo is 0
ptp4l[2175.985]: config item (null).time_stamping is 1
ptp4l[2175.985]: config item (null).clock_servo is 0
ptp4l[2175.985]: config item (null).clockClass is 248
ptp4l[2175.985]: config item (null).clockAccuracy is 254
ptp4l[2175.985]: config item (null).offsetScaledLogVariance is 65535
ptp4l[2175.985]: config item (null).productDescription is ';;'
ptp4l[2175.985]: config item (null).revisionData is ';;'
ptp4l[2175.985]: config item (null).userDescription is ''
ptp4l[2175.985]: config item (null).manufacturerIdentity is '00:00:00'
ptp4l[2175.985]: config item (null).domainNumber is 0
ptp4l[2175.986]: config item (null).slaveOnly is 1
ptp4l[2175.986]: config item (null).twoStepFlag is 1
ptp4l[2175.986]: config item (null).priority1 is 128
ptp4l[2175.986]: config item (null).priority2 is 128
ptp4l[2175.986]: config item (null).gmCapable is 1
ptp4l[2175.986]: config item (null).gmCapable is 1
ptp4l[2175.986]: config item (null).free_running is 0
ptp4l[2175.986]: selected /dev/ptp0 as PTP clock
ptp4l[2175.986]: config item (null).uds_address is '/var/run/ptp4l'
ptp4l[2175.986]: section item /var/run/ptp4l.announceReceiptTimeout now 0
ptp4l[2175.986]: section item /var/run/ptp4l.delay_mechanism now 0
ptp4l[2175.986]: section item /var/run/ptp4l.network_transport now 0
ptp4l[2175.986]: section item /var/run/ptp4l.delay_filter_length now 1
ptp4l[2175.986]: config item (null).free_running is 0
ptp4l[2175.986]: config item (null).freq_est_interval is 1
ptp4l[2175.986]: config item (null).gmCapable is 1
ptp4l[2175.986]: config item (null).kernel_leap is 1
ptp4l[2175.986]: config item (null).timeSource is 160
ptp4l[2175.986]: config item (null).pi_proportional_const is 0.000000
ptp4l[2175.986]: config item (null).pi_integral_const is 0.000000
ptp4l[2175.986]: config item (null).pi_proportional_scale is 0.000000
ptp4l[2175.986]: config item (null).pi_proportional_exponent is -0.300000
ptp4l[2175.986]: config item (null).pi_proportional_norm_max is 0.700000
ptp4l[2175.986]: config item (null).pi_integral_scale is 0.000000
ptp4l[2175.986]: config item (null).pi_integral_exponent is 0.400000
ptp4l[2175.986]: config item (null).pi_integral_norm_max is 0.300000
ptp4l[2175.986]: config item (null).step_threshold is 0.000000
ptp4l[2175.986]: config item (null).first_step_threshold is 0.000020
ptp4l[2175.986]: config item (null).max_frequency is 900000000
ptp4l[2175.986]: config item (null).tsproc_mode is 0
ptp4l[2175.986]: config item (null).delay_filter is 1
ptp4l[2175.986]: config item (null).delay_filter_length is 10
ptp4l[2175.986]: config item (null).summary_interval is 0
ptp4l[2175.986]: config item (null).sanity_freq_limit is 200000000
ptp4l[2175.986]: PI servo: sync interval 1.000 kp 0.700 ki 0.300000
ptp4l[2175.987]: config item /var/run/ptp4l.boundary_clock_jbod is 0
ptp4l[2175.987]: config item /var/run/ptp4l.network_transport is 0
ptp4l[2175.987]: config item /var/run/ptp4l.delayAsymmetry is 0
ptp4l[2175.987]: config item /var/run/ptp4l.follow_up_info is 0
ptp4l[2175.987]: config item /var/run/ptp4l.freq_est_interval is 1
ptp4l[2175.987]: config item /var/run/ptp4l.hybrid_e2e is 0
ptp4l[2175.987]: config item /var/run/ptp4l.path_trace_enabled is 0
ptp4l[2175.987]: config item /var/run/ptp4l.ingressLatency is 0
ptp4l[2175.987]: config item /var/run/ptp4l.egressLatency is 0
ptp4l[2175.987]: config item /var/run/ptp4l.delay_mechanism is 0
ptp4l[2175.987]: config item /var/run/ptp4l.fault_badpeernet_interval is 16
ptp4l[2175.987]: config item /var/run/ptp4l.fault_reset_interval is 4
ptp4l[2175.987]: config item /var/run/ptp4l.tsproc_mode is 0
ptp4l[2175.987]: config item /var/run/ptp4l.delay_filter is 1
ptp4l[2175.987]: config item /var/run/ptp4l.delay_filter_length is 1
ptp4l[2175.987]: config item eth0.boundary_clock_jbod is 0
ptp4l[2175.987]: config item eth0.network_transport is 1
ptp4l[2176.285]: config item eth0.delayAsymmetry is 0
ptp4l[2176.285]: config item eth0.follow_up_info is 0
ptp4l[2176.285]: config item eth0.freq_est_interval is 1
ptp4l[2176.285]: config item eth0.hybrid_e2e is 0
ptp4l[2176.285]: config item eth0.path_trace_enabled is 0
ptp4l[2176.285]: config item eth0.ingressLatency is 0
ptp4l[2176.285]: config item eth0.egressLatency is 0
ptp4l[2176.285]: config item eth0.delay_mechanism is 0
ptp4l[2176.285]: config item eth0.fault_badpeernet_interval is 16
ptp4l[2176.285]: config item eth0.fault_reset_interval is 4
ptp4l[2176.285]: config item eth0.tsproc_mode is 0
ptp4l[2176.286]: config item eth0.delay_filter is 1
ptp4l[2176.286]: config item eth0.delay_filter_length is 10
ptp4l[2176.286]: config item eth0.logMinDelayReqInterval is 0
ptp4l[2176.286]: config item eth0.logAnnounceInterval is 1
ptp4l[2176.286]: config item eth0.announceReceiptTimeout is 3
ptp4l[2176.286]: config item eth0.syncReceiptTimeout is 0
ptp4l[2176.286]: config item eth0.transportSpecific is 0
ptp4l[2176.286]: config item eth0.logSyncInterval is 0
ptp4l[2176.286]: config item eth0.logMinPdelayReqInterval is 0
ptp4l[2176.286]: config item eth0.neighborPropDelayThresh is 20000000
ptp4l[2176.286]: config item eth0.min_neighbor_prop_delay is -20000000
ptp4l[2176.286]: config item eth0.udp_ttl is 1
ptp4l[2176.287]: driver changed our HWTSTAMP options
ptp4l[2176.287]: tx_type  1 not 1
ptp4l[2176.287]: rx_filter 1 not 12
ptp4l[2176.287]: config item (null).dscp_event is 0
ptp4l[2176.287]: config item (null).dscp_general is 0
ptp4l[2176.287]: port 1: INITIALIZING to LISTENING on INITIALIZE
ptp4l[2176.287]: config item /var/run/ptp4l.logMinDelayReqInterval is 0
ptp4l[2176.287]: config item /var/run/ptp4l.logAnnounceInterval is 1
ptp4l[2176.287]: config item /var/run/ptp4l.announceReceiptTimeout is 0
ptp4l[2176.287]: config item /var/run/ptp4l.syncReceiptTimeout is 0
ptp4l[2176.287]: config item /var/run/ptp4l.transportSpecific is 0
ptp4l[2176.287]: config item /var/run/ptp4l.logSyncInterval is 0
ptp4l[2176.287]: config item /var/run/ptp4l.logMinPdelayReqInterval is 0
ptp4l[2176.287]: config item /var/run/ptp4l.neighborPropDelayThresh is 20000000
ptp4l[2176.287]: config item /var/run/ptp4l.min_neighbor_prop_delay is -20000000
ptp4l[2176.287]: config item (null).uds_address is '/var/run/ptp4l'
ptp4l[2176.287]: port 0: INITIALIZING to LISTENING on INITIALIZE
ptp4l[2176.288]: interface index 1 is up
ptp4l[2176.288]: interface index 2 is down
ptp4l[2176.288]: interface index 3 is up
ptp4l[2176.288]: port 1: link up
ptp4l[2176.288]: interface index 4 is down
ptp4l[2176.288]: interface index 5 is down
ptp4l[2176.288]: interface index 6 is down
</pre>


==Testing on device side - (Local clock Synchronization)==
The previous step allows the device to receive and make the HW timestamp available to the local clock source or application. <br>
phyc2sys utility works in conjunction with the ptp4l utility to synchronize the local <br>
system clock with the grand master clock source.


==Client Clock==
<pre>
<pre>
root@var-som-mx6:~# phc2sys -s /dev/ptp0 -w -l 6 -q -m (On target)
root@var-som-mx6:~# phc2sys -s /dev/ptp0 -w -l 6 -q -m  
phc2sys[561.207]: Waiting for ptp4l...
phc2sys[561.207]: Waiting for ptp4l...
phc2sys[562.208]: phc offset 1464418821463523 s0 freq      +0 delay  3000
phc2sys[562.208]: phc offset 1464418821463523 s0 freq      +0 delay  3000
phc2sys[563.208]: phc offset 1464419821714028 s1 freq +100000000 delay  2667
phc2sys[563.208]: phc offset 1464419821714028 s1 freq +100000000 delay  2667
phc2sys[564.209]: phc offset 1000271806 s2 freq +100000000 delay  2400
phc2sys[565.209]: phc offset 2000486206 s2 freq +100000000 delay  2400
phc2sys[566.209]: phc offset 3000696407 s2 freq +100000000 delay  2400
phc2sys[567.209]: phc offset 4000886807 s2 freq +100000000 delay  2400
phc2sys[568.209]: phc offset 5001102707 s2 freq +100000000 delay  2400
phc2sys[569.210]: phc offset 6001324458 s2 freq +100000000 delay  2700
phc2sys[570.210]: phc offset 7001534358 s2 freq +100000000 delay  2700
phc2sys[571.210]: phc offset 8001741409 s2 freq +100000000 delay  2400
phc2sys[572.210]: phc offset 9001958659 s2 freq +100000000 delay  2700
phc2sys[573.210]: phc offset 10002176809 s2 freq +100000000 delay  2400
phc2sys[574.211]: phc offset 11002399610 s2 freq +100000000 delay  2400
phc2sys[575.211]: phc offset 12002644460 s2 freq +100000000 delay  2700
phc2sys[576.211]: phc offset 13002853611 s2 freq +100000000 delay  2400
phc2sys[577.211]: phc offset 14003077311 s2 freq +100000000 delay  2400
phc2sys[578.212]: phc offset 15003260811 s2 freq +100000000 delay  2400
phc2sys[579.212]: phc offset 16003465012 s2 freq +100000000 delay  2400
phc2sys[580.212]: phc offset 17003743612 s2 freq +100000000 delay  2400
phc2sys[581.212]: phc offset 18003950213 s2 freq +100000000 delay  2400
phc2sys[582.212]: phc offset 19004196113 s2 freq +100000000 delay  2400
phc2sys[583.213]: phc offset 20004446363 s2 freq +100000000 delay  2700
phc2sys[584.213]: phc offset 21004611264 s2 freq +100000000 delay  2700
phc2sys[585.213]: phc offset 22004810214 s2 freq +100000000 delay  2400
phc2sys[586.213]: phc offset 23005021015 s2 freq +100000000 delay  2400
phc2sys[586.213]: phc offset 23005021015 s2 freq +100000000 delay  2400
phc2sys[587.214]: phc offset 24005243215 s2 freq +100000000 delay  2400
phc2sys[587.214]: phc offset 24005243215 s2 freq +100000000 delay  2400
Line 84: Line 277:
phc2sys[617.221]: phc offset 54012428677 s2 freq +100000000 delay  2700
phc2sys[617.221]: phc offset 54012428677 s2 freq +100000000 delay  2700
phc2sys[618.221]: phc offset 55012704577 s2 freq +100000000 delay  2700
phc2sys[618.221]: phc offset 55012704577 s2 freq +100000000 delay  2700
phc2sys[619.221]: phc offset 56012984828 s2 freq +100000000 delay  2400
phc2sys[620.222]: clockcheck: clock jumped forward or running faster than expected!
phc2sys[620.222]: phc offset 1464483152951603 s0 freq +100000000 delay  3000
phc2sys[621.222]: phc offset 1464484153378019 s2 freq +100000000 delay  2667
phc2sys[622.223]: phc offset 1464485154078390 s2 freq +100000000 delay  2683
phc2sys[623.223]: phc offset 1464486154636636 s2 freq +100000000 delay  2692
phc2sys[624.226]: phc offset 1464487157293498 s2 freq +100000000 delay  2694
phc2sys[625.228]: phc offset 1464488159378244 s2 freq +100000000 delay  2711
phc2sys[626.229]: phc offset 1464489160129296 s2 freq +100000000 delay  2723
phc2sys[627.229]: phc offset 1464490160587105 s2 freq +100000000 delay  2730
phc2sys[628.241]: phc offset 1464491172016447 s2 freq +100000000 delay  3078
phc2sys[629.242]: phc offset 1464492173403906 s2 freq +100000000 delay  3077
phc2sys[630.247]: phc offset 1464493178723071 s2 freq +100000000 delay  2748
phc2sys[631.248]: phc offset 1464494179156799 s2 freq +100000000 delay  3095
phc2sys[632.249]: phc offset 1464495180352481 s2 freq +100000000 delay  3096
phc2sys[633.300]: phc offset 1464496231092783 s2 freq +100000000 delay  2752
phc2sys[634.301]: phc offset 1464497232074798 s2 freq +100000000 delay  2752
phc2sys[635.308]: phc offset 1464498238912004 s2 freq +100000000 delay  2748
phc2sys[636.328]: phc offset 1464499259729610 s2 freq +100000000 delay  2744
phc2sys[637.329]: phc offset 1464500260764369 s2 freq +100000000 delay  2738
phc2sys[638.350]: phc offset 1464501280978216 s2 freq +100000000 delay  2742
phc2sys[639.367]: phc offset 1464502297959788 s2 freq +100000000 delay  2752
phc2sys[640.371]: phc offset 1464503302356247 s2 freq +100000000 delay  2742
phc2sys[641.379]: phc offset 1464504310824799 s2 freq +100000000 delay  2744
phc2sys[642.395]: phc offset 1464505326833637 s2 freq +100000000 delay  2753
phc2sys[643.411]: phc offset 1464506342090385 s2 freq +100000000 delay  2758
phc2sys[644.424]: phc offset 1464507355577673 s2 freq +100000000 delay  2753
phc2sys[645.437]: phc offset 1464508367883499 s2 freq +100000000 delay  2750
phc2sys[646.448]: phc offset 1464509379300274 s2 freq +100000000 delay  2751
phc2sys[647.458]: phc offset 1464510389072999 s2 freq +100000000 delay  2740
phc2sys[648.467]: phc offset 1464511398075267 s2 freq +100000000 delay  2746
phc2sys[649.474]: phc offset 1464512405426873 s2 freq +100000000 delay  2740
phc2sys[650.475]: phc offset 1464513406076841 s2 freq +100000000 delay  2735
phc2sys[651.480]: phc offset 1464514411378537 s2 freq +100000000 delay  2732
phc2sys[652.480]: phc offset 1464515411655088 s2 freq +100000000 delay  2049
phc2sys[653.481]: phc offset 1464516412161301 s2 freq +100000000 delay  2737
phc2sys[654.483]: phc offset 1464517414263811 s2 freq +100000000 delay  3078
phc2sys[655.484]: phc offset 1464518415321128 s2 freq +100000000 delay  3076
phc2sys[656.517]: phc offset 1464519448418178 s2 freq +100000000 delay  2739
phc2sys[657.550]: phc offset 1464520481841954 s2 freq +100000000 delay  2729
phc2sys[658.552]: phc offset 1464521483516703 s2 freq +100000000 delay  3060
phc2sys[659.562]: phc offset 1464522493570265 s2 freq +100000000 delay  2720
phc2sys[660.567]: phc offset 1464523498148818 s2 freq +100000000 delay  2716
phc2sys[661.582]: phc offset 1464524513011071 s2 freq +100000000 delay  2717
phc2sys[662.582]: phc offset 1464525513506641 s2 freq +100000000 delay  2715
phc2sys[663.587]: phc offset 1464526518805566 s2 freq +100000000 delay  2717
phc2sys[664.610]: phc offset 1464527541224573 s2 freq +100000000 delay  2718
phc2sys[665.616]: phc offset 1464528546927259 s2 freq +100000000 delay  2712
phc2sys[666.628]: phc offset 1464529559727846 s2 freq +100000000 delay  2709
phc2sys[667.629]: phc offset 1464530560334336 s2 freq +100000000 delay  2705
phc2sys[668.644]: phc offset 1464531575787318 s2 freq +100000000 delay  2704
phc2sys[669.646]: phc offset 1464532577487481 s2 freq +100000000 delay  2700
phc2sys[670.650]: phc offset 1464533581311024 s2 freq +100000000 delay  2697
phc2sys[671.654]: phc offset 1464534585019924 s2 freq +100000000 delay  2694
phc2sys[672.654]: phc offset 1464535585380900 s2 freq +100000000 delay  2698
phc2sys[673.657]: phc offset 1464536588044348 s2 freq +100000000 delay  2703
phc2sys[674.663]: phc offset 1464537594797125 s2 freq +100000000 delay  2702
phc2sys[675.670]: phc offset 1464538601087119 s2 freq +100000000 delay  3039
phc2sys[676.673]: phc offset 1464539604250909 s2 freq +100000000 delay  2703
phc2sys[677.678]: phc offset 1464540609850135 s2 freq +100000000 delay  2703
phc2sys[678.684]: phc offset 1464541614954166 s2 freq +100000000 delay  2703
phc2sys[679.685]: phc offset 1464542616379699 s2 freq +100000000 delay  2700
phc2sys[680.689]: phc offset 1464543619991720 s2 freq +100000000 delay  2699
phc2sys[681.689]: phc offset 1464544620334491 s2 freq +100000000 delay  2696
phc2sys[682.692]: phc offset 1464545623116924 s2 freq +100000000 delay  2697
phc2sys[683.694]: phc offset 1464546625490602 s2 freq +100000000 delay  3037
phc2sys[684.696]: phc offset 1464547627254258 s2 freq +100000000 delay  2696
phc2sys[685.697]: phc offset 1464548628487392 s2 freq +100000000 delay  2693
phc2sys[686.697]: phc offset 1464549628808513 s2 freq +100000000 delay  2697
phc2sys[687.698]: phc offset 1464550629199606 s2 freq +100000000 delay  2699
^Cphc2sys[688.443]: phc offset 1464551373974242 s2 freq +100000000 delay  2698
root@var-som-mx6:~#
root@var-som-mx6:~#
</pre>
</pre>


= Receiving notifications from BLE devices =
= HW Events =
 
After kernel up, run commands:
Notifications sent from connected BLE devices can be seen in '''gatttool'''. The example below shows notification sent by Android "BLE Peripheral Simulator"
$ ptp4l -A -4 -H -m -i eth0  &
<pre>
[74:B9:AB:CF:13:A9][LE]>
$ echo 1 > /sys/class/ptp/ptp0/pps_enable
Notification handle = 0x002a value: 08 3c 00 00
[74:B9:AB:CF:13:A9][LE]>
</pre>

Latest revision as of 17:49, 25 February 2019

VAR-SOM-MX6 - IEEE 1588 Hardware Timestamp

Overview of IEEE 1588 Hardware Timestamping

For a basic overview of IEEE 1588 and PTP, please refer to https://elinux.org/images/f/f9/Introduction_to_IEEE_1588_Precision_Time_Protocol_%28PTP%29_Using_Embedded_Linux_Systems.pdf

At the very top level, it allows high precision time synchronization over a packet-based network, and can be described by the below image:
IEEE 1588 Basic Overview.png


NXP Supports IEEE 1588 PTP implemented in the SOC Ethernet MAC layer:
IMX IEEE 1588 functions.png

The NXP IEEE 1588 PTP and timer implementation have the following features:

  • Allows reference clock to be chosen independently of network speed.
  • Software-programmable precise time-stamping of ingress and egress frames.
  • Timer monitoring capabilities for system calibration and timing accuracy management.
  • Precise time-stamping of external events with programmable interrupt generation.
  • Programmable event and interrupt generation for external system control.
  • Supports hardware and software-controllable timer synchronization.
  • Provides a 4-channel IEEE 1588 timer. Each channel supports input capture and output compare using the 1588 counter.
  • Distribution of precise time information over the packet-based network.
  • Offers high accuracy (in the sub-microsecond range) over the network.

Hardware Setup

  • For DART-MX6: physically remove U109 (RTC IC) and R137 (i2c3_sda pull-up) from the board.
  • Network Setup: Connect the PC/Grand Master Clock Source and the target to the same Ethernet network (and use ping to verify the connection between the PC and the target).

Software

In the current setup, we will have

  • PC - Grand Master which acts as the clock source which has the GPS clock synchronized

Note: You may choose Device (i.MX6) as grandmaster clock as a device as well.

  • Device - i.MX6 with IEEE 1588 HW timestamp support - of which local clock to be synchronized with grandmaster


Software utilities required for PTP

$ ptp4l
$ phc2sys

For Ubuntu 16.04

$ sudo apt-get install linuxptp

Start the software base timestamping on PC or to become grandmaster clock source which you want to synchronize.

Make sure you have following device tree change present on your kernel.
Note that in this example, i2c3 bus is disabled for DART-MX6, in order to free the pins used by the IEEE 1588 hardware timestamping.
For more details about pinmuxing
- VAR-SOM-MX6: https://www.variscite.com/wp-content/uploads/2017/12/VAR-SOM-SOLO_DUAL_Datasheet.pdf
- DART-MX6: https://www.variscite.com/wp-content/uploads/2017/11/DART-MX6-Datasheet.pdf
- VAR-SOM-SOLO/DUAL: https://www.variscite.com/wp-content/uploads/2017/12/VAR-SOM-SOLO_DUAL_Datasheet.pdf

You may need to disable certain pins to get the HW EVENTX_IN/OUT and insert in the device tree, to get your external input / output for the HW timer to work.

Below code example is for DART-MX6

diff --git a/arch/arm/boot/dts/imx6qdl-var-dart.dtsi b/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
index 64e9b91..407c4fe 100644
--- a/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
@@ -217,6 +217,7 @@
        };

        ov564x_mipi: ov564x_mipi@3c {
+               status = "disabled";
                compatible = "ovti,ov564x_mipi";
                reg = <0x3c>;
                clocks = <&clks 200>;
@@ -320,16 +321,7 @@
 };

 &i2c3 {
-       clock-frequency = <100000>;
-       pinctrl-names = "default";
-       pinctrl-0 = <&pinctrl_i2c3_3>;
-       status = "okay";
-
-       /* DS1337 RTC module */
-       rtc@0x68 {
-               compatible = "dallas,ds1337";
-               reg = <0x68>;
-       };
+       status = "disabled";
 };

 &iomuxc {
@@ -379,6 +371,7 @@
                                MX6QDL_PAD_RGMII_RD2__RGMII_RD2            0x1b0b0
                                MX6QDL_PAD_RGMII_RD3__RGMII_RD3            0x1b0b0
                                MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL      0x1b0b0
+                               MX6QDL_PAD_GPIO_16__ENET_REF_CLK        0x4001b0a8
                        >;
                };

@@ -415,13 +408,6 @@
                        >;
                };

-               pinctrl_i2c3_3: i2c3grp {
-                       fsl,pins = <
-                               MX6QDL_PAD_GPIO_5__I2C3_SCL             0x4001b8b1
-                               MX6QDL_PAD_GPIO_16__I2C3_SDA            0x4001b8b1
-                       >;
-               };
-
                pinctrl_ipu1: ipu1grp {
                        fsl,pins = <
                                MX6QDL_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK      0x10
$ sudo ptp4l -i  enp5s0 -m -S 

- Here, in this case, the PC sends the timestamp using software timer.
- The timestamp packets are sent over networking infrastructure via switch/router (IEEE 1588 packets)
and then once received on the target, it is used to synchronize the clock with 1μs accuracy.
- Hardware has the test and compares logic to see the drift and jitter.

Testing on device side

ptp4l works as a daemon service. It must be started first before any system level PTP client can work.
Yocto build already contains the ptp4l required resoureces on the target.
Run following commands on target

root@var-som-mx6:~# ptp4l -H -A -l 7 -q -i eth0 -m -s &
ptp4l[2175.985]: config item (null).assume_two_step is 0
ptp4l[2175.985]: config item (null).check_fup_sync is 0
ptp4l[2175.985]: config item (null).tx_timestamp_timeout is 1
ptp4l[2175.985]: config item (null).clock_servo is 0
ptp4l[2175.985]: config item (null).time_stamping is 1
ptp4l[2175.985]: config item (null).clock_servo is 0
ptp4l[2175.985]: config item (null).clockClass is 248
ptp4l[2175.985]: config item (null).clockAccuracy is 254
ptp4l[2175.985]: config item (null).offsetScaledLogVariance is 65535
ptp4l[2175.985]: config item (null).productDescription is ';;'
ptp4l[2175.985]: config item (null).revisionData is ';;'
ptp4l[2175.985]: config item (null).userDescription is ''
ptp4l[2175.985]: config item (null).manufacturerIdentity is '00:00:00'
ptp4l[2175.985]: config item (null).domainNumber is 0
ptp4l[2175.986]: config item (null).slaveOnly is 1
ptp4l[2175.986]: config item (null).twoStepFlag is 1
ptp4l[2175.986]: config item (null).priority1 is 128
ptp4l[2175.986]: config item (null).priority2 is 128
ptp4l[2175.986]: config item (null).gmCapable is 1
ptp4l[2175.986]: config item (null).gmCapable is 1
ptp4l[2175.986]: config item (null).free_running is 0
ptp4l[2175.986]: selected /dev/ptp0 as PTP clock
ptp4l[2175.986]: config item (null).uds_address is '/var/run/ptp4l'
ptp4l[2175.986]: section item /var/run/ptp4l.announceReceiptTimeout now 0
ptp4l[2175.986]: section item /var/run/ptp4l.delay_mechanism now 0
ptp4l[2175.986]: section item /var/run/ptp4l.network_transport now 0
ptp4l[2175.986]: section item /var/run/ptp4l.delay_filter_length now 1
ptp4l[2175.986]: config item (null).free_running is 0
ptp4l[2175.986]: config item (null).freq_est_interval is 1
ptp4l[2175.986]: config item (null).gmCapable is 1
ptp4l[2175.986]: config item (null).kernel_leap is 1
ptp4l[2175.986]: config item (null).timeSource is 160
ptp4l[2175.986]: config item (null).pi_proportional_const is 0.000000
ptp4l[2175.986]: config item (null).pi_integral_const is 0.000000
ptp4l[2175.986]: config item (null).pi_proportional_scale is 0.000000
ptp4l[2175.986]: config item (null).pi_proportional_exponent is -0.300000
ptp4l[2175.986]: config item (null).pi_proportional_norm_max is 0.700000
ptp4l[2175.986]: config item (null).pi_integral_scale is 0.000000
ptp4l[2175.986]: config item (null).pi_integral_exponent is 0.400000
ptp4l[2175.986]: config item (null).pi_integral_norm_max is 0.300000
ptp4l[2175.986]: config item (null).step_threshold is 0.000000
ptp4l[2175.986]: config item (null).first_step_threshold is 0.000020
ptp4l[2175.986]: config item (null).max_frequency is 900000000
ptp4l[2175.986]: config item (null).tsproc_mode is 0
ptp4l[2175.986]: config item (null).delay_filter is 1
ptp4l[2175.986]: config item (null).delay_filter_length is 10
ptp4l[2175.986]: config item (null).summary_interval is 0
ptp4l[2175.986]: config item (null).sanity_freq_limit is 200000000
ptp4l[2175.986]: PI servo: sync interval 1.000 kp 0.700 ki 0.300000
ptp4l[2175.987]: config item /var/run/ptp4l.boundary_clock_jbod is 0
ptp4l[2175.987]: config item /var/run/ptp4l.network_transport is 0
ptp4l[2175.987]: config item /var/run/ptp4l.delayAsymmetry is 0
ptp4l[2175.987]: config item /var/run/ptp4l.follow_up_info is 0
ptp4l[2175.987]: config item /var/run/ptp4l.freq_est_interval is 1
ptp4l[2175.987]: config item /var/run/ptp4l.hybrid_e2e is 0
ptp4l[2175.987]: config item /var/run/ptp4l.path_trace_enabled is 0
ptp4l[2175.987]: config item /var/run/ptp4l.ingressLatency is 0
ptp4l[2175.987]: config item /var/run/ptp4l.egressLatency is 0
ptp4l[2175.987]: config item /var/run/ptp4l.delay_mechanism is 0
ptp4l[2175.987]: config item /var/run/ptp4l.fault_badpeernet_interval is 16
ptp4l[2175.987]: config item /var/run/ptp4l.fault_reset_interval is 4
ptp4l[2175.987]: config item /var/run/ptp4l.tsproc_mode is 0
ptp4l[2175.987]: config item /var/run/ptp4l.delay_filter is 1
ptp4l[2175.987]: config item /var/run/ptp4l.delay_filter_length is 1
ptp4l[2175.987]: config item eth0.boundary_clock_jbod is 0
ptp4l[2175.987]: config item eth0.network_transport is 1
ptp4l[2176.285]: config item eth0.delayAsymmetry is 0
ptp4l[2176.285]: config item eth0.follow_up_info is 0
ptp4l[2176.285]: config item eth0.freq_est_interval is 1
ptp4l[2176.285]: config item eth0.hybrid_e2e is 0
ptp4l[2176.285]: config item eth0.path_trace_enabled is 0
ptp4l[2176.285]: config item eth0.ingressLatency is 0
ptp4l[2176.285]: config item eth0.egressLatency is 0
ptp4l[2176.285]: config item eth0.delay_mechanism is 0
ptp4l[2176.285]: config item eth0.fault_badpeernet_interval is 16
ptp4l[2176.285]: config item eth0.fault_reset_interval is 4
ptp4l[2176.285]: config item eth0.tsproc_mode is 0
ptp4l[2176.286]: config item eth0.delay_filter is 1
ptp4l[2176.286]: config item eth0.delay_filter_length is 10
ptp4l[2176.286]: config item eth0.logMinDelayReqInterval is 0
ptp4l[2176.286]: config item eth0.logAnnounceInterval is 1
ptp4l[2176.286]: config item eth0.announceReceiptTimeout is 3
ptp4l[2176.286]: config item eth0.syncReceiptTimeout is 0
ptp4l[2176.286]: config item eth0.transportSpecific is 0
ptp4l[2176.286]: config item eth0.logSyncInterval is 0
ptp4l[2176.286]: config item eth0.logMinPdelayReqInterval is 0
ptp4l[2176.286]: config item eth0.neighborPropDelayThresh is 20000000
ptp4l[2176.286]: config item eth0.min_neighbor_prop_delay is -20000000
ptp4l[2176.286]: config item eth0.udp_ttl is 1
ptp4l[2176.287]: driver changed our HWTSTAMP options
ptp4l[2176.287]: tx_type   1 not 1
ptp4l[2176.287]: rx_filter 1 not 12
ptp4l[2176.287]: config item (null).dscp_event is 0
ptp4l[2176.287]: config item (null).dscp_general is 0
ptp4l[2176.287]: port 1: INITIALIZING to LISTENING on INITIALIZE
ptp4l[2176.287]: config item /var/run/ptp4l.logMinDelayReqInterval is 0
ptp4l[2176.287]: config item /var/run/ptp4l.logAnnounceInterval is 1
ptp4l[2176.287]: config item /var/run/ptp4l.announceReceiptTimeout is 0
ptp4l[2176.287]: config item /var/run/ptp4l.syncReceiptTimeout is 0
ptp4l[2176.287]: config item /var/run/ptp4l.transportSpecific is 0
ptp4l[2176.287]: config item /var/run/ptp4l.logSyncInterval is 0
ptp4l[2176.287]: config item /var/run/ptp4l.logMinPdelayReqInterval is 0
ptp4l[2176.287]: config item /var/run/ptp4l.neighborPropDelayThresh is 20000000
ptp4l[2176.287]: config item /var/run/ptp4l.min_neighbor_prop_delay is -20000000
ptp4l[2176.287]: config item (null).uds_address is '/var/run/ptp4l'
ptp4l[2176.287]: port 0: INITIALIZING to LISTENING on INITIALIZE
ptp4l[2176.288]: interface index 1 is up
ptp4l[2176.288]: interface index 2 is down
ptp4l[2176.288]: interface index 3 is up
ptp4l[2176.288]: port 1: link up
ptp4l[2176.288]: interface index 4 is down
ptp4l[2176.288]: interface index 5 is down
ptp4l[2176.288]: interface index 6 is down

Testing on device side - (Local clock Synchronization)

The previous step allows the device to receive and make the HW timestamp available to the local clock source or application.
phyc2sys utility works in conjunction with the ptp4l utility to synchronize the local
system clock with the grand master clock source.

root@var-som-mx6:~# phc2sys -s /dev/ptp0 -w -l 6 -q -m 
phc2sys[561.207]: Waiting for ptp4l...
phc2sys[562.208]: phc offset 1464418821463523 s0 freq      +0 delay   3000
phc2sys[563.208]: phc offset 1464419821714028 s1 freq +100000000 delay   2667
phc2sys[586.213]: phc offset 23005021015 s2 freq +100000000 delay   2400
phc2sys[587.214]: phc offset 24005243215 s2 freq +100000000 delay   2400
phc2sys[588.214]: phc offset 25005490315 s2 freq +100000000 delay   2400
phc2sys[589.214]: phc offset 26005730816 s2 freq +100000000 delay   2400
phc2sys[590.214]: phc offset 27005974016 s2 freq +100000000 delay   2400
phc2sys[591.214]: phc offset 28006201017 s2 freq +100000000 delay   2400
phc2sys[592.215]: phc offset 29006428317 s2 freq +100000000 delay   2400
phc2sys[593.215]: phc offset 30006676017 s2 freq +100000000 delay   2400
phc2sys[594.215]: phc offset 31006943218 s2 freq +100000000 delay   2400
phc2sys[595.215]: phc offset 32007195118 s2 freq +100000000 delay   2400
phc2sys[596.216]: phc offset 33007442819 s2 freq +100000000 delay   2400
phc2sys[597.216]: phc offset 34007662169 s2 freq +100000000 delay   2700
phc2sys[598.216]: phc offset 35007934919 s2 freq +100000000 delay   2400
phc2sys[599.216]: phc offset 36008207820 s2 freq +100000000 delay   2400
phc2sys[600.217]: phc offset 37008466620 s2 freq +100000000 delay   2400
phc2sys[601.217]: phc offset 38008680421 s2 freq +100000000 delay   2400
phc2sys[602.217]: phc offset 39008935621 s2 freq +100000000 delay   2400
phc2sys[603.217]: phc offset 40009183021 s2 freq +100000000 delay   2400
phc2sys[604.218]: phc offset 41009422622 s2 freq +100000000 delay   2400
phc2sys[605.218]: phc offset 42009670922 s2 freq +100000000 delay   2400
phc2sys[606.218]: phc offset 43009915323 s2 freq +100000000 delay   2400
phc2sys[607.218]: phc offset 44010150723 s2 freq +100000000 delay   2400
phc2sys[608.219]: phc offset 45010369773 s2 freq +100000000 delay   2700
phc2sys[609.219]: phc offset 46010583124 s2 freq +100000000 delay   2400
phc2sys[610.219]: phc offset 47010823024 s2 freq +100000000 delay   2400
phc2sys[611.219]: phc offset 48010995125 s2 freq +100000000 delay   2400
phc2sys[612.219]: phc offset 49011205925 s2 freq +100000000 delay   2400
phc2sys[613.220]: phc offset 50011483625 s2 freq +100000000 delay   2400
phc2sys[614.220]: phc offset 51011699826 s2 freq +100000000 delay   2400
phc2sys[615.220]: phc offset 52011934926 s2 freq +100000000 delay   2400
phc2sys[616.220]: phc offset 53012195227 s2 freq +100000000 delay   2400
phc2sys[617.221]: phc offset 54012428677 s2 freq +100000000 delay   2700
phc2sys[618.221]: phc offset 55012704577 s2 freq +100000000 delay   2700
root@var-som-mx6:~#

HW Events

After kernel up, run commands:

$ ptp4l -A -4 -H -m -i eth0  &

$ echo 1 > /sys/class/ptp/ptp0/pps_enable