smalllife // packet & bench

Stratum-1 time on the shelf with a UART GNSS module and chrony

2025-05-18 · timekeeping, ntp, embedded

Public NTP pools over FTTH are already within two milliseconds, so building a local stratum-1 source is mostly an exercise in curiosity and keeping clean timestamps in logs when the fiber cut down the street takes six hours to splice.

Why NMEA alone jitters by tens of milliseconds

A cheap u-blox M8 breakout emits two completely different signals: an ASCII $GPRMC sentence at 9600 bps whose arrival time wanders depending on how many satellites are in $GPGSV, and a dedicated PPS pin whose rising edge aligns to the UTC second within ~30–50 ns once 3D fix locks. PPS tells you when the second ticked; NMEA tells you which second that was.

Wiring to Linux pps-gpio and chrony

On the tiny i.MX6ULL board (ntp01), PPS goes straight to a 3.3 V GPIO configured via device-tree overlay as pps-gpio (exposing /dev/pps0), while UART2 feeds gpsd -n so chrony can lock the PPS pulse against coarse SHM time:

# /etc/chrony/chrony.conf
refclock SHM 0 refid NMEA offset 0.135 precision 1e-3 noselect
refclock PPS /dev/pps0 refid PPS lock NMEA precision 1e-7 prefer poll 3

allow 10.10.0.0/16
allow fd42:7710::/32
local stratum 10 orphan

After letting it settle overnight with a magnetic patch puck taped inside the north window frame:

$ chronyc sources -v
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
#- NMEA                          0   4   377    14  +4120us[+4120us] +/-   42ms
#* PPS                           0   3   377     6    +94ns[ +118ns] +/-  380ns
^+ time.cloudflare.com           3   8   377   192   -310us[ -310us] +/- 6410us

Keeping two internet servers configured without prefer acts as a sanity check against GPS week-number rollover bugs or a slipped window antenna without polluting the local sub-microsecond loop.