From Brandon's Tinkerings
Jump to: navigation, search
(Random Notes (The building blocks))
(Random Notes (The building blocks))
Line 84: Line 84:
  
 
rpi-update
 
rpi-update
 
reboot
 
  
 
apt-get install pps-tools snmp libcap-dev i2c-tools
 
apt-get install pps-tools snmp libcap-dev i2c-tools
Line 91: Line 89:
 
edit /boot/config.txt: add --
 
edit /boot/config.txt: add --
  
dtoverlay=pps-gpio,gpiopin=<x>
+
dtoverlay=pps-gpio,gpiopin=23
  
 
Custom PCB uses GPIO23
 
Custom PCB uses GPIO23
  
======================================================================
+
dtoverlay=i2c-rtc,ds3231
OLD/INVALID
 
  
edit /boot/cmdline.txt, remove serial references (AMA0) (only needed if you don't select to turn off serial console above)
+
Enables the DS3231 i2c clock at boot.
  
edit /etc/inittab, remove serial console (only needed if you don't select to turn off serial console above)
+
reboot
  
 +
Upon reboot, you should see things like this toward the end of the kernel messages:
 +
 +
[    5.401032] pps_core: LinuxPPS API ver. 1 registered
 +
[    5.506199] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
 +
[    5.638198] pps pps0: new PPS source pps.-1
 +
[    5.741468] pps pps0: Registered IRQ 417 as PPS source
 +
[    5.822304] bcm2708_i2c_init_pinmode(1,2)
 +
[    5.961135] bcm2708_i2c_init_pinmode(1,3)
 +
[    6.260785] rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0
 +
[    6.369424] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)
  
 
KERNEL TIME
 
KERNEL TIME
 +
 +
Recommend to compile kernel on another system --http://elinux.org/Raspberry_Pi_Kernel_Compilation
  
 
Build Machine
 
Build Machine
  
 
crossdev -S -v -t arm-unknown-linux-gnueabi
 
crossdev -S -v -t arm-unknown-linux-gnueabi
 
Recommend to compile kernel on another system --http://elinux.org/Raspberry_Pi_Kernel_Compilation
 
  
 
export CCPREFIX=arm-unknown-linux-gnueabi-
 
export CCPREFIX=arm-unknown-linux-gnueabi-
Line 123: Line 130:
 
modify kernelmake ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig
 
modify kernelmake ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig
  
(Required!)General -> Default Hostname (NTP1)
+
General -> Timers Subsystem -> Deselect "Old Idle Dynticks Config"Device Drivers -> PPS Support -> Enable: PPS Kernel Consumer Support (Will not show up if the timer subsystem options above are not set)
  
General -> Timers Subsystem -> Timer Tick Handling (Idle Dynticks System (Tickless Idle)) -> Periodic Timer Ticks (Constant rate, no dynticks) -- This is needed for NTP_PPSGeneral
+
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4
  
-> Deselect "Old Idle Dynticks Config"
+
mkdir modtmp
  
Boot Options -> Default Kernel Command -> Remove "console=ttyAMA0,115200"
+
make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=./modtmp modules_install
  
Device Drivers -> PPS Support (*)-> (*) PPS Kernel Consumer Support (Will not show up if the timer subsystem options above are not set)
+
Compress files
  
-> (*) PPS Client using GPIO
+
tar -cjf modules.tar.bz2 modtmp/
  
Device Drivers -> Real Time Clock -> (*) Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSon RX-8025 (For RTC 3231 option below)
+
tar -cjf dts.tar.bz2 arch/arm/boot/dts/
  
(Optional)Kernel Features -> memory split -> 2G/2G
+
Transfer Files
  
Preemption Model -> No forced preemption (Server)
+
scp modules.tar.bz2 root@ntp1:~/
  
CPU Power Management -> CPU Frequency Scaling -> Default CPU Freq Governor -> Performance
+
scp dts.tar.bz2 root@ntp1:~/
  
OldKernel
+
scp arch/arm/boot/Image root@10.0.3.14:/boot/Image-3187
  
Patch Kernel: http://ntpi.openchaos.org/pps_pi/ - https://raw.githubusercontent.com/lampeh/rpi-misc/master/linux-pps/linux-rpi-pps-gpio-bcm2708.diff
+
Extract and move modules
  
Note: Line numbers are different with newer kernel. Provide updated patch....
+
tar -xjf modules.tar.bz2
  
NewKernel
+
mv /lib/modules/<version> /lib/modules/<version>-orig
  
>=3.18.x?
+
mv modtmp/lib/modules/<version> /lib/modules
  
Use DeviceTable - No patching
+
cp -R modtmp/lib/firmware/* /lib/firmware
 
 
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4
 
 
 
mkdir modtmp
 
  
make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=./modtmp modules_install
+
extract and move DTB's
  
tar -cjf modules.tar.bz2 modtmp/
+
tar -xjf dts.tar.bz2
  
scp modules.tar.bz2 root@ntp1:~/
+
cp arch/arm/boot/dts/*.dtb /boot/overlays
  
scp arch/arm/boot/Image root@10.0.3.14:/boot/Image-31229
+
mv /boot/overlays/bcm*.dtb /boot
  
tar -xjf modules.tar.bz2
 
  
mv /lib/modules/<version> /lib/modules/<version>-orig
+
grab mkknlimg(https://github.com/raspberrypi/tools/blob/master/mkimage/mkknlimg), and sign the kernel:
  
mv modtmp/lib/modules/<version> /lib/modules
+
mkknlimg /boot/Image-3187 /boot/Image-3187S
  
cp -R modtmp/lib/firmware/* /lib/firmware
+
grab knlinfo(https://github.com/raspberrypi/tools/blob/master/mkimage/knlinfo) and verify:
  
edit /boot/config.txt
+
knlinfo /boot/Image-3187S
  
add:
+
Should show something like:
  
kernel=Image-3187
+
./knlinfo /boot/Image-3187S
 +
Kernel trailer found at 8697996/0x84b88c:
 +
  KVer: "Linux version 3.18.7+ (root@XXXXXXXX) (gcc version 4.8.3 (Gentoo 4.8.3 p1.1, pie-0.5.9) ) #1 PREEMPT Thu Feb 19 20:30:48 EST 2015"
 +
  DTOK: true
  
 +
Edit /boot/config.txt, add:
  
 +
kernel=Image-3187S
  
=============================================================================================
+
Configuring NTP
  
Grab latest NTP from: http://www.ntp.org/downloads.html, for compile computer
+
Grab latest NTP from: http://www.ntp.org/downloads.html,
  
 
extract
 
extract
Line 191: Line 198:
 
./configure --prefix=/usr --enable-ATOM --enable-NMEA --enable-GPSD --enable-SHM --enable-WWV --with-ntpsnmpd --enable-ipv6 --enable-linuxcaps --enable-clockctl
 
./configure --prefix=/usr --enable-ATOM --enable-NMEA --enable-GPSD --enable-SHM --enable-WWV --with-ntpsnmpd --enable-ipv6 --enable-linuxcaps --enable-clockctl
  
make
+
make && make install
  
 
now wait ~20minutes
 
now wait ~20minutes
  
rm /var/lib/ntp/ntp.conf.dhcp if DHCP, static recommended
 
  
##Cross-compile NTP:
+
Configure network:
 +
#Static IP
 +
 
 +
Edit /etc/networking/interfaces
 +
 
 +
iface eth0 inet static
 +
 
 +
address 10.10.10.10
 +
 
 +
netmask 255.255.255.0
  
##mkdir tmpinstall##make -j2##make install
+
gateway 10.10.10.1
  
##tar -cjf ntp.tar.bz2 tmpinstall
 
  
##copy files out cp bin/ntpd bin/ntp-wait bin/ntptime /usr/sbin
+
rm /var/lib/ntp/ntp.conf.dhcp
  
##https://support.ntp.org/bin/view/Dev/Cross-compilingNTP
+
GPS/UDEV Rules
  
 
create /etc/udev/rules/09-gps.rules
 
create /etc/udev/rules/09-gps.rules
Line 237: Line 251:
 
Tune the offset http://www.catb.org/gpsd/gpsd-time-service-howto.html
 
Tune the offset http://www.catb.org/gpsd/gpsd-time-service-howto.html
  
## RTC
 
 
modules/i2c already enabled in kernel from above
 
 
i2c-dev module
 
 
i2cdetect -y 1 - verify on 68
 
 
echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device
 
  
 
set timezone -
 
set timezone -
Line 262: Line 267:
  
 
The RTC isn't handled by udev, so this check needs to be removed.
 
The RTC isn't handled by udev, so this check needs to be removed.
 
Add after unset TZ in hwclock.sh
 
 
modprobe i2c-bcm2708
 
 
modprobe i2c-dev
 
 
modprobe rtc-ds1307
 
 
echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device
 
 
#Static IP
 
 
Edit /etc/networking/interfaces
 
 
iface eth0 inet static
 
 
address
 
 
netmask
 
 
gateway
 
  
 
#http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=16218
 
#http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=16218
Line 296: Line 279:
  
 
update-rc.d x11-common disable
 
update-rc.d x11-common disable
 +
 +
 +
  
 
## OLD
 
## OLD
Line 324: Line 310:
  
 
Uninstall existing ntp, compile/install latest ntp
 
Uninstall existing ntp, compile/install latest ntp
 +
 +
=============
 +
-> (*) PPS Client using GPIO
 +
 +
Device Drivers -> Real Time Clock -> (*) Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSon RX-8025 (For RTC 3231 option below)
 +
 +
(Optional)Kernel Features -> memory split -> 2G/2G
 +
 +
Preemption Model -> No forced preemption (Server)
 +
 +
CPU Power Management -> CPU Frequency Scaling -> Default CPU Freq Governor -> Performance
 +
 +
OldKernel
 +
 +
Patch Kernel: http://ntpi.openchaos.org/pps_pi/ - https://raw.githubusercontent.com/lampeh/rpi-misc/master/linux-pps/linux-rpi-pps-gpio-bcm2708.diff
 +
 +
Note: Line numbers are different with newer kernel. Provide updated patch....
 +
 +
NewKernel
 +
 +
>=3.18.x?
 +
 +
Use DeviceTable - No patching
 +
 +
===============================
 +
##Cross-compile NTP:
 +
 +
##mkdir tmpinstall##make -j2##make install
 +
 +
##tar -cjf ntp.tar.bz2 tmpinstall
 +
 +
##copy files out cp bin/ntpd bin/ntp-wait bin/ntptime /usr/sbin
 +
 +
##https://support.ntp.org/bin/view/Dev/Cross-compilingNTP
 +
 +
## RTC
 +
 +
modules/i2c already enabled in kernel from above
 +
 +
i2c-dev module
 +
 +
i2cdetect -y 1 - verify on 68
 +
 +
echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device
 +
 +
 +
Add after unset TZ in hwclock.sh
 +
 +
modprobe i2c-bcm2708
 +
 +
modprobe i2c-dev
 +
 +
modprobe rtc-ds1307
 +
 +
echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device

Revision as of 20:09, 19 February 2015

Intro

Here are my notes for getting a NavSpark GPS+GLONASS module working with a Raspberry Pi (Model B) for Timing/NTP purposes. They have since come out with a specific timing module that would probably be better suited for this. But alas, it's not what I have right now :)

What is this all about?

For a long time now, I've wanted to setup a Stratum 1 time source. It allows better matching of logs for debugging, and allows a more accurate time source for local network devices.

This page goes over the module, getting it wired up to a Pi, then getting the Pi working with the module. I've also added a i2c TCXO RTC (DS3231) for timekeeping while the unit does not have power. This was added as the Pi does not have an RTC built in, and it may take some time for the Pi to sync with peers and/or GPS to get time set.

This will give me a time source on my network that is extremely accurate for my needs.

I created a custom PCB for attaching the NavSpark module, DS3231, and associated parts to the Pi. This makes it nice and compact to put to the side to just run. Gives it a nice SAF. (Spouse Approval Factor)

What does this page assume?

  • You have a NavSpark (or similar) GPS Module that outputs RS232 TTL NEMA GPS code, as well as a 1PPS (Pulse per second) output.
  • You have a Raspberry Pi (B or B+ preferred, since it has the wired network interface already on it)
  • You know how to wire/breadboard stuff to the Pi
  • Fresh install of Raspbian (either directly or through NOOBS)

Other

  • Logic Level Converter - If your GPS module outputs 5v, as the Pi need 3v in. (Note: The NavSpark outputs 3v)
  • Solder
  • Soldering Iron
  • Materials in BOM below if using custom adapter board
  • Pi Case
  • Good, solid/stable output, 5v USB Power Supply (a good quality power supply can make a big difference, especially when used in timing situations)
  • Setting up a cross-compile environment
  • Comfortable compiling and installing software/kernel
  • Comfortable applying patches

My Testing Environment

DevSetup.jpg



The Code

Caveats

Resources Used to Complete this

Fin

Random Notes (The building blocks)

http://www.satsignal.eu/ntp/Raspberry-Pi-NTP.html

set user password

Advanced options

-set hostname - NTP1

-Change GPU memory to 16M (not used for NTP, more memory available to the system)

-Enable Kernel i2c

-Disable Kernel/Shell over Serial

finish, reboot.

login as pi

sudo -s

set root password

Update Pi

apt-get update

apt-get dist-upgrade

rpi-update

apt-get install pps-tools snmp libcap-dev i2c-tools

edit /boot/config.txt: add --

dtoverlay=pps-gpio,gpiopin=23

Custom PCB uses GPIO23

dtoverlay=i2c-rtc,ds3231

Enables the DS3231 i2c clock at boot.

reboot

Upon reboot, you should see things like this toward the end of the kernel messages:

[ 5.401032] pps_core: LinuxPPS API ver. 1 registered [ 5.506199] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it> [ 5.638198] pps pps0: new PPS source pps.-1 [ 5.741468] pps pps0: Registered IRQ 417 as PPS source [ 5.822304] bcm2708_i2c_init_pinmode(1,2) [ 5.961135] bcm2708_i2c_init_pinmode(1,3) [ 6.260785] rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0 [ 6.369424] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)

KERNEL TIME

Recommend to compile kernel on another system --http://elinux.org/Raspberry_Pi_Kernel_Compilation

Build Machine

crossdev -S -v -t arm-unknown-linux-gnueabi

export CCPREFIX=arm-unknown-linux-gnueabi-

may need gcc-config to set current version if updated

get kernel source: git clone --depth 1 git://github.com/raspberrypi/linux.git pikern

grab default /proc/config.gz from Pi, uncompress and copy to pikern/.config

make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig

modify kernelmake ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig

General -> Timers Subsystem -> Deselect "Old Idle Dynticks Config"Device Drivers -> PPS Support -> Enable: PPS Kernel Consumer Support (Will not show up if the timer subsystem options above are not set)

make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4

mkdir modtmp

make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=./modtmp modules_install

Compress files

tar -cjf modules.tar.bz2 modtmp/

tar -cjf dts.tar.bz2 arch/arm/boot/dts/

Transfer Files

scp modules.tar.bz2 root@ntp1:~/

scp dts.tar.bz2 root@ntp1:~/

scp arch/arm/boot/Image root@10.0.3.14:/boot/Image-3187

Extract and move modules

tar -xjf modules.tar.bz2

mv /lib/modules/<version> /lib/modules/<version>-orig

mv modtmp/lib/modules/<version> /lib/modules

cp -R modtmp/lib/firmware/* /lib/firmware

extract and move DTB's

tar -xjf dts.tar.bz2

cp arch/arm/boot/dts/*.dtb /boot/overlays

mv /boot/overlays/bcm*.dtb /boot


grab mkknlimg(https://github.com/raspberrypi/tools/blob/master/mkimage/mkknlimg), and sign the kernel:

mkknlimg /boot/Image-3187 /boot/Image-3187S

grab knlinfo(https://github.com/raspberrypi/tools/blob/master/mkimage/knlinfo) and verify:

knlinfo /boot/Image-3187S

Should show something like:

./knlinfo /boot/Image-3187S Kernel trailer found at 8697996/0x84b88c:

 KVer: "Linux version 3.18.7+ (root@XXXXXXXX) (gcc version 4.8.3 (Gentoo 4.8.3 p1.1, pie-0.5.9) ) #1 PREEMPT Thu Feb 19 20:30:48 EST 2015"
 DTOK: true

Edit /boot/config.txt, add:

kernel=Image-3187S

Configuring NTP

Grab latest NTP from: http://www.ntp.org/downloads.html,

extract

./configure --prefix=/usr --enable-ATOM --enable-NMEA --enable-GPSD --enable-SHM --enable-WWV --with-ntpsnmpd --enable-ipv6 --enable-linuxcaps --enable-clockctl

make && make install

now wait ~20minutes


Configure network:

  1. Static IP

Edit /etc/networking/interfaces

iface eth0 inet static

address 10.10.10.10

netmask 255.255.255.0

gateway 10.10.10.1


rm /var/lib/ntp/ntp.conf.dhcp

GPS/UDEV Rules

create /etc/udev/rules/09-gps.rules

file contents:

  1. Adds symlink from serial interface to /dev/gps0 for ntpd

KERNEL=="ttyAMA0", SYMLINK+="gps0"

Edit /etc/ntp.conf

enable calibrate

enable kernel

  1. GPS Module

server 127.127.20.0 mode 82 minpoll 4 maxpoll 6

fudge 127.127.20.0 time2 +0.1939

  1. PPS of GPS Module

server 127.127.22.0 minpoll 4

fudge 127.127.22.0 flag3 1

Add other servers/peers, set one as prefer (needed to get PPS lock, see http://ntpi.openchaos.org/pps_pi/)

Tune the offset http://www.catb.org/gpsd/gpsd-time-service-howto.html


set timezone -

rm /etc/localtime

ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

edit /etc/default/hwclock

HWCLOCKACCESS=YES

HCTOSYS_DEVICE=rtc0

edit /etc/init.d/hwclock.sh, line 64, comment out if statement for udev

The RTC isn't handled by udev, so this check needs to be removed.

  1. http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=16218

dpkg --purge fake-hwclock

    1. cd /etc/rcS.d

update-rc.d hwclock.sh enable

update-rc.d alsa-utils disable

update-rc.d x11-common disable



    1. OLD

apt-get install gpsd gpsd-clients python-gps

edit /etc/defaults/gpsd

start_daemon = true

devices="/dev/ttyAMA0"

flags -b -n

stty -F /dev/ttyAMA0 115200

set base_baud before gpsd starts, scans faster.

service gpsd enable

reboot, confirm with cgps -s

apt-get install libncurses5-dev bc

edit modules, include pps-gpio

Instead of gpsd - symlink /dev/ttyAMA0 to /dev/gps0, use 127.127.20.0 mode 82 in ntp config, adds GPS_NEMA driver

Uninstall existing ntp, compile/install latest ntp

=

-> (*) PPS Client using GPIO

Device Drivers -> Real Time Clock -> (*) Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSon RX-8025 (For RTC 3231 option below)

(Optional)Kernel Features -> memory split -> 2G/2G

Preemption Model -> No forced preemption (Server)

CPU Power Management -> CPU Frequency Scaling -> Default CPU Freq Governor -> Performance

OldKernel

Patch Kernel: http://ntpi.openchaos.org/pps_pi/ - https://raw.githubusercontent.com/lampeh/rpi-misc/master/linux-pps/linux-rpi-pps-gpio-bcm2708.diff

Note: Line numbers are different with newer kernel. Provide updated patch....

NewKernel

>=3.18.x?

Use DeviceTable - No patching

===================
    1. Cross-compile NTP:
    1. mkdir tmpinstall##make -j2##make install
    1. tar -cjf ntp.tar.bz2 tmpinstall
    1. copy files out cp bin/ntpd bin/ntp-wait bin/ntptime /usr/sbin
    1. https://support.ntp.org/bin/view/Dev/Cross-compilingNTP
    1. RTC

modules/i2c already enabled in kernel from above

i2c-dev module

i2cdetect -y 1 - verify on 68

echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device


Add after unset TZ in hwclock.sh

modprobe i2c-bcm2708

modprobe i2c-dev

modprobe rtc-ds1307

echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device