domschl / RaspberryNtpServer

Stratum-1 time server with Raspberry Pi and GPS
MIT License
79 stars 5 forks source link

CM4 and Timebeat LEA-M8F Baseboard #11

Closed p47-6 closed 7 months ago

p47-6 commented 7 months ago

Hi, i've tried to follow the setup as close as possible with a CM4 but i wanted to use the SYNC_IN pin on the CM4 breakout port since i've got a LEA-M8F Board from Timebeat (https://store.timebeat.app/products/gnss-raspberry-pi-cm4-module?variant=42280855699627).

My problem is that i still get timeouts with ppsteston pps0 and i cannot figure out why:

$ sudo ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
time_pps_fetch() error -1 (Connection timed out)
time_pps_fetch() error -1 (Connection timed out)
time_pps_fetch() error -1 (Connection timed out)
time_pps_fetch() error -1 (Connection timed out)

With test ptp i do not get a problem:

$ sudo ./testptp -d /dev/ptp0 -L 0,1
set pin function okay
$ sudo  ./testptp -d /dev/ptp0 -e 5
external time stamp request okay
event index 0 at 9036.169914149
event index 0 at 9037.169893564
event index 0 at 9038.169871992
event index 0 at 9039.169849439
event index 0 at 9040.169825905

also if i hook up a logic analyzer on the physical pin i get a clean 1pps signal as soon as the GPS locks.

here some extra info:

$ uname -a
Linux cm4 6.6.16-v8+ #1728 SMP PREEMPT Tue Feb  6 17:21:42 GMT 2024 aarch64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm
$ sudo chronyc
chrony version 4.3
Copyright (C) 1997-2003, 2007, 2009-2022 Richard P. Curnow and others
chrony comes with ABSOLUTELY NO WARRANTY.  This is free software, and
you are welcome to redistribute it under certain conditions.  See the
GNU General Public License version 2 for details.

chronyc> sourcestats
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
PPS0                        0   0     0     +0.000   2000.000     +0ns  4000ms
GPS                         7   4    97   +128.275    353.883   +646ms  4399us
185.13.148.71               7   5   25m     +0.141      1.468  -1105us   258us
vif1201.leaf2.network.pr>   6   3   773     -0.500      1.174   +264us    85us
nono.com                    7   4   453     -0.311      0.473   -479us    29us
ntp1.aew1.soe.as49436.net   6   3   21m     +0.339      3.956   +332us   423us
172.28.100.10              11   9   644     -0.188      0.097   +376us    14us
chronyc> sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
#? PPS0                          0   4     0     -     +0ns[   +0ns] +/-    0ns
#? GPS                           0   4   377    23   +645ms[ +645ms] +/-  200ms
^+ 185.13.148.71                 2   8   377    90  -1429us[-1429us] +/-   12ms
^+ vif1201.leaf2.network.pr>     2   7   377    24   +332us[ +332us] +/-   16ms
^- nono.com                      2   6   377    24   -577us[ -577us] +/-   49ms
^* ntp1.aew1.soe.as49436.net     1   8   377    93   +297us[ +378us] +/-   11ms
^- 172.28.100.10                 3   6   377    30   +362us[ +362us] +/-   49ms

any suggestions ?

domschl commented 7 months ago

Did you check dmesg for the pps related messages?

How did you configure the raspberry pi kernel driver to use sync-in?

p47-6 commented 7 months ago

Here is the dmesg output:

[    0.083028] pps_core: LinuxPPS API ver. 1 registered
[    0.083048] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[   10.107286] pps_ldisc: PPS line discipline registered
[   10.108043] pps pps0: new PPS source serial0
[   10.108078] pps pps0: source "/dev/ttyS0" added

I've acually did nothing special to configure it. It more or less had ptp0 out-of-the-box. While i was researching the topic i've found https://github.com/jclark/rpi-cm4-ptp-guide but to be honest i did not realy understand whats going on. I've just used the testptp commands to doublecheck if something is working and tried to stick to your guide as close as possible.

domschl commented 7 months ago

Both the rpi-cm-ptp-guide and that original product spec basically talk about PTP. I guess there is some missing information about the configuration of PPS kernel module: the PPS signal from the clock hardware has to be connected to some pin of Raspberry PI. For the hardware I tested with, one specifies this GPIO for the kernel modules with bcm2708.pps_gpio_pin=4 and/or dtoverlay=pps-gpio,gpiopin=4 (GPIO 4 in this example). That results in a dmesg log output new PPS source pps@4.-1 and Registered IRQ 166 as PPS source which shows that an interrupt driver is allocated by the kernel driver to handle the PPS signal.

I fear that the output you listed uses some (incomplete) defaults, and that there is something missing to configure your hardware. I didn't find any technical description on the company's web-site. Maybe you contact their support and ask how to configure the Raspberry kernel drivers for PPS (not just PTP) for their hardware?

We are missing something here.

domschl commented 7 months ago

That documentation refers to pin 18:

dtoverlay=pps-gpio,gpiopin=18 (is that your hardware?)

https://github.com/jclark/rpi-cm4-ptp-guide/blob/853f200106f40fcfa697ef4e94829931a5cf3dd5/os.md?plain=1#L42

p47-6 commented 7 months ago

That documentation refers to pin 18:

dtoverlay=pps-gpio,gpiopin=18 (is that your hardware?)

https://github.com/jclark/rpi-cm4-ptp-guide/blob/853f200106f40fcfa697ef4e94829931a5cf3dd5/os.md?plain=1#L42

I've added

# Enable GPIO pin 18 for PPS (not always necessary, but useful for testing)
dtoverlay=pps-gpio,gpiopin=18
# realtime clock
dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi
# fan
#dtoverlay=i2c-fan,emc2301,i2c_csi_dsi
# Make /dev/ttyAMA0 be connected to GPIO header pins 8 and 10
# This always disables Bluetooth
dtoverlay=disable-bt

to the config and now the dmesg output is the following:

$ dmesg |grep pps
[    0.089020] pps_core: LinuxPPS API ver. 1 registered
[    0.089040] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    7.552241] pps pps0: new PPS source pps@12.-1
[    7.552381] pps pps0: Registered IRQ 38 as PPS source
[   11.251002] pps_ldisc: PPS line discipline registered
[   11.252736] pps pps1: new PPS source serial0
[   11.252820] pps pps1: source "/dev/ttyS0" added

The problem is i get on pps0 and pps1 a timeout.

btw.: I totally mixed up ptp and pps in my head. I've also contacted the board vendor a while ago and they just referred to their docs.

domschl commented 7 months ago

I finally found the documentation of your board on the manufacturers site.

From what I understood this board does not support the PPS configuration used in this project. They seem to connect the PPS signal only to the network hardware of the CM4 (the PTP protocol uses specific ethernet hardware to transport the time signal via ethernet, and the CM4 has such a chip). That way the Raspberry PI Linux kernel doesn't have access to the 1PPS signal.

Unfortunately they do not seem to provide a mechanism to route the PPS signal from the M8N GPS chip to the Raspberry PI GPIOs.

Just to clarify again the differences between PTP and PPS linux protocols:

PTP is basically a legacy protocol used in lab or telecom environments that uses specific hardware extensions to ethernet to transmit time signals. Every instance in the PTP network (switches, all network clients) need to support PTP for it to work.

If you do not have PTP network requirements (e.g. you are not in such a lab), then you could still follow the complete rpi-cm4-ptp-guide instructions. This also sets up a chronyd time server that receives its time-sync information via PTP. You could then simply use that chronyc to sync time clients in your network completely ignoring the PTP stuff.

You would then not use any information of this project.

p47-6 commented 7 months ago

Thank you for the clarification.