FreeBSD 14 Pi 4 M8T - BYO-NTP/recipes GitHub Wiki
date | server | os | gnss | daemon | 🎯 | 🗣️ |
---|---|---|---|---|---|---|
2025-05 | Raspberry Pi 4 | FreeBSD 14 |
Huawei WD22UGRC u-blox LEA-M8T |
chrony NTPsec ntp |
1.41 µs | discuss |
1.1 Install FreeBSD on Pi 4
1.2 Install a silent u-boot
2.1 Wire the WD22UGRC to a USB to serial TTL adapter. Connect the assembly to a Windows computer with u-blox u-center installed. Configure the LEA-M8T per the recommendations on the gnss page.
2.2 Wire the WD22UGRC to the Pi 4 GPIO headers as shown in the assembly photos below. There's also a Bill of Materials. USB only (no serial) instructions are here.
Tell getty to ignore ttyu0 (aka cuau0), the GPS serial port:
sed -i '' -e '/^ttyu0/ s/onifconsole/off/' /etc/ttys
kill -HUP 1
The NTP daemons look to /dev/gps0
by default, so link gps0
to the serial port using devfs:
test -L /dev/gps0 && rm /dev/gps0
grep -q gps0 /etc/devfs.conf && sed -i '' -e 's/^link.*gps0$//g' /etc/devfs.conf
echo 'link cuau0 gps0' >> /etc/devfs.conf
service devfs restart
The distributed FreeBSD image is missing most Pi overlays. Install them and copy to the SD card.
pkg install -y rpi-firmware
cp -p /usr/local/share/rpi-firmware/overlays/* /boot/efi/overlays/
Enable the pps-gpio overlay by adding this block to the [all]
section of /boot/efi/config.txt
grep -q pps-gpio /boot/efi/config.txt || cat >> /boot/efi/config.txt <<EOF
# Huawei WD22UGRC
dtoverlay=pps-gpio,gpiopin=18
enable_uart=1
EOF
Load the gpsiopps kernel module and link it to /dev/pps0
.
kldload gpiopps
sysrc -f /boot/loader.conf gpiopps_load="YES"
grep -q pps0 /etc/devfs.conf && sed -i '' -e 's/^link.*pps0$//g' /etc/devfs.conf
echo 'link gpiopps0 pps0' >> /etc/devfs.conf
Grant ntpd
access to /dev/gpiopps0
:
cat >> /etc/devfs.rules <<EONTP
[devfsrules_ntp=10]
add path 'gpiopps0' mode 0660 group ntpd
EONTP
sysrc devfs_system_ruleset+="devfsrules_ntp"
Power off your Pi (poweroff
), connect the wires, and then verify that it works:
dmesg | egrep '(uart|pps)'
gpiopps0: <GPIO PPS> on ofwbus0
gpiopps0: PPS input on gpio0 pin 18
uart0: <PrimeCell UART (PL011)> mem 0x7e201000-0x7e2011ff irq 16 on simplebus0
Read some data from gps0: (Control-C to disconnect):
stty -f /dev/gps0 raw 115200 cs8 clocal -cstopb
cat /dev/gps0
$GNRMC,203047.00,A,4746.15203,N,12219.54384,W,0.000,,120525,,,A,V*06
$GNZDA,203047.00,12,05,2025,00,00*79
$GNRMC,203048.00,A,4746.15203,N,12219.54384,W,0.000,,120525,,,A,V*09
$GNZDA,203048.00,12,05,2025,00,00*76
$GNRMC,203049.00,A,4746.15203,N,12219.54
^C
It works!
Each section heading is a link with many more details about installing, configuring, and verifying that particular NTP daemon.
export NTP_REFCLOCKS=$(cat <<EO_CHRONY
refclock SHM 0 refid NMEA precision 0.02 poll 4 offset 0.140
refclock PPS /dev/pps0 refid PPS precision 4e-7 poll 2 lock NMEA trust
EO_CHRONY
)
curl -sS https://byo-ntp.github.io/tools/chrony/install.sh | sh
export NTP_REFCLOCKS=$(cat <<EO_NTPSEC
refclock nmea refid NMEA minpoll 3 maxpoll 4 time2 0.124 prefer mode 8 baud 115200
refclock pps refid PPS minpoll 1 maxpoll 2 time1 0.0
EO_NTPSEC
)
curl -sS https://byo-ntp.github.io/tools/ntpsec/install.sh | sh
export NTP_REFCLOCKS=$(cat <<EO_NTP
server 127.127.20.0 minpoll 3 maxpoll 4 mode 88 prefer
fudge 127.127.20.0 refid NMEA time2 0.124 minjitter 0.3
server 127.127.22.0 minpoll 3 maxpoll 4 prefer
fudge 127.127.22.0 refid PPS time1 0.0 minjitter 0.01
EO_NTP
)
curl -sS https://byo-ntp.github.io/tools/ntp/install.sh | sh
- watch the status in near real time (requires installing gnu-watch):
- printf '\e[8;9;80t'; ssh -t pi5 gnu-watch -n2 chronyc sources
- printf '\e[8;9;80t'; ssh -t pi5 gnu-watch -n2 ntpq -c peer
- Measure the offset
- Gather statistics with telegraf + influxdb + grafana or similar.
- FreeBSD wiki USB/Peripheral/Serial
- FreeBSD man page uftdi
- ntpq
- ntp, Configuring NMEA Refclocks NEO-M8T
- Austins Nerdy Things - Revisiting Microsecond Accurate NTP
- Raspberry Pi pinout
- GNSS
- NTP daemons
Item | Vendor(s) | Cost |
---|---|---|
Huawei WD22UGRC GPS module | eBay | $25 |
SMA-F to SMB-F connector | Amzn | $5 |
Active GPS Antenna | Amzn | $11 |
2P-F to 1P-F 2mm to 2.54mm Jumper wires | Amzn | $8 |
Total | $49 |
The Huawei GNSS module has a LEA-M8T chip which supports GPS, Galileo, Beidou, and GLONASS. In the PNW, I regularly get simultaneous 3D fixes from both GPS and Galileo satnav systems.
This photo shows the pinouts on the board. Note that you MUST cross the TxD and RxD pins. If the module isn't spewing data, check that the pins are crossed. If your antenna supports it (all of mine do), connect 5V to pin 1
.
Pins: 1 ANT 3V3, 2 3V3/VCC, 3 TXD, 4 NC, 5 RXD, 6 TP1/1PPS, 7 NC TP2, 8 GND
Click photos to embiggen.
Here it's wired to a USB adapter:
Here it's wired to the Pi GPIO:
Chrony
NTPsec
ntp