Success: GL-MT300N-V2 with PPS/GPS/NTP time source

I have just set up a GL-MT300N-V2 as an NTP server with a GPS/PPS reference clock. Seems to be working well, but I need a better GPS signal to be sure.

I pretty much followed the Raspberry Pi method given in Building a Raspberry-Pi Stratum-1 NTP Server but needed to modify the device tree and build my own kernel as openwrt doesn’t support device tree overlays.

Here is an outline:

  • uBlox NEO-7M 3.3V GPS module from eBay
  • GPS wired to GL-MT300N-V2 using second serial port /dev/ttyS1 (GND, 3.3V, TX1,RX1, PPS to GPIO4)
  • openwrt 18.06 snapshot with device tree patch below and pps and pps-gpio kernel modules
  • gpsd connected to /dev/ttyS1
  • disable sysntpd
  • ntpd and ntp-utils packages
  • hacks to ntp startup files to append reference clock info (below)

After stabilizing for a couple of hours the NTP daemon on the router has an offset and jitter of a few microseconds compared to the GPS/PPS clock. Happy to provide further details, but this is my first attempt at modifying and building openwrt.

Note: Initially I tried using the first serial port /dev/ttyS0, but the router wouldn’t boot. I assume that data returned from the GPS interrupted uboot.

----------  reference clock configuration for /etc/ntpd.conf ----------
# At least one server or reference clock must have "prefer" for PPS to work
# time1 value - here 0.125s - must be adjusyed to suit
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 refid GPS stratum 5 time1 0.125 flag1 1

#added for PPS accuracy:
server 127.127.22.0 minpoll 4 maxpoll 4
fudge 127.127.22.0 refid PPS

----------  patch to  GL-MT300N-V2.dts ----------
--- a/target/linux/ramips/dts/GL-MT300N-V2.dts
+++ b/target/linux/ramips/dts/GL-MT300N-V2.dts
@@ -74,6 +74,11 @@
                };
        };

+       pps {
+               compatible = "pps-gpio";
+               gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
+               status = "okay";
+       };
 };

 &pinctrl {
-----------------------------------------------------------------
2 Likes

The poor GPS signal only provided intermittent time data. The oscillator on the router drifts - as expected - when is isn’t disciplined by the PPS signal.

I bought an active GPS antenna and now have a reliable PPS signal from the GPS. NTP reference clock has stabilized with offset of less than 2μs and a jitter of around 4 μs. NTP clients on the LAN are within 1 ms with a jitter of around 0.5 ms.

One addition to the ntpd.conf file above. Increase mindist, the minimum distance used by the selection and anticlockhop algorithm, with the line

tos mindist 0.02  

This allows for the variation in the serial port NMEA data used by the GPS reference clock. The default is 0.001. A value of 0.01 to 0.02 works for me.

For long term use as a stand alone server I need to add and maintain a leap second file.

To summarize, the GL-MT300N-V2 is working very well as a Stratum 1 NTP server provided the attached GPS unit has a reliable signal. The complexity was similar to the RaspberryPi Zero W:

  • hardware mods are similar - attach 5 wires
  • needed to compile a kernel for the MT300N to add pps gpio to device tree, whereas RPi uses a device tree overlay
  • needed to recompile ntpd for RPi as it isn’t configured with PPS reference clock 22, while stock ntpd for openwrt is
  • ethernet interface on MT300N has less delay and less jitter than wifi interface on RPi
2 Likes

great work, thanks very much for sharing.