Getting a serial port automatically set up at boot

Achim Gratz Stromeko at nexgo.de
Sun Apr 7 18:56:07 UTC 2019


I have a few refclocks that are connected via a serial port (either USB
or a real one) and here's what needs to be set up for udev and systemd setting
those up correctly at boot, so you don't have to remember to run the
respective commands by hand.  The udev part is easy to find, it took me
a while to get systemd to set up the PPS.


A DCF77 receiver connected to the first serial port on a plain vanilla
(old) PC:

/etc/udev/rules.d/77-dcf77.rules 
--8<---------------cut here---------------start------------->8---
KERNEL=="ttyS0" SYMLINK+="refclock-0" GROUP="ntp"
KERNEL=="pps0"  SYMLINK+="refclockpps-0" GROUP="ntp"
KERNEL=="ttyS0" RUN+="/bin/setserial /dev/%k low_latency"
--8<---------------cut here---------------end--------------->8---

Now, you cannot do anything from a udev rule that runs for longer than
about three seconds (it'll get killed).  So for PPS via ldattach, you
need to ask systemd to do that:

/etc/systemd/system/pps0.service 
--8<---------------cut here---------------start------------->8---
[Unit]
Description=PPS activation
BindsTo=dev-ttyS0.device
After=dev-ttyS0.device

[Service]
Type=forking
ExecStart=/usr/sbin/ldattach PPS /dev/ttyS0
--8<---------------cut here---------------end--------------->8---


A GPS connected to an FTDI USB serial (which can relay PPS via DCD) on a
rasPi. There is already a /dev/pps0 running via PPS-GPIO, so /dev/pps1
is used for this GPS (which is the second one on this system, so
/dev/gps1):

/etc/udev/rules.d/99-navspark.rules 
--8<---------------cut here---------------start------------->8---
KERNEL=="pps1" SYMLINK+="gpspps1" GROUP="ntp"
KERNEL=="ttyUSB0" RUN+="/bin/setserial /dev/%k low_latency" RUN+="/bin/stty -F /dev/%k 115200" SYMLINK+="navspark-%n" SYMLINK+="gps1" GROUP="ntp"
--8<---------------cut here---------------end--------------->8---

/etc/systemd/system/pps1.service
--8<---------------cut here---------------start------------->8---
[Unit]
Description=PPS activation
BindsTo=dev-ttyUSB0.device
After=dev-ttyUSB0.device

[Service]
Type=forking
ExecStart=/usr/sbin/ldattach PPS /dev/ttyUSB0
--8<---------------cut here---------------end--------------->8---


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds



More information about the devel mailing list