Friday 20 February 2015

Losing time

This week didn't quite go according to plan, I was planning to be test-driving the logger by now, but it hasn't happened.  Why?  Well, mainly because of the very recent change in Raspbian Wheezy to use kernel 3.18.7+.  This brings about a huge change - device tree support.  I had never even heard of device trees before and to be honest didn't know I needed to know about them.  As will all things technology there has been a huge amount of banging my head on the desk, and the odd sweary word!! Why did it affect this project?  Well, i2c is now controlled by device-tree rather than just loading modules.  This change meant that i2c no longer loaded at all in fact.

It turns out that raspi-config has been updated to use device trees, and using it to enable i2c at boot works fine.  If you go to the raspi-config advanced menu, i2c can now be enabled.  Just choose enable and load modules on boot.  This means that the RTC should again be available on the bus at boot.

This doesn't entirely solve the problem though - you actually have to get raspbian to use it, something it's not overly keen on doing. What I had been doing was this, but I wan't happy with editing the hwclock.sh script to that extent, and disabling the udev calls didn't sit well either.  Even with this, the RTC wasn't loaded until quite a way into the boot process.  There must be a better way...

(I'll spare you details of the three days I spent delving into device trees, and get straight to the point)

There is a device tree overlay provided as part of 2015-02-16-raspbian-wheezy:
/boot/overlays/ds1307-rtc-overlay.dtb

This overlay is specifically designed to load the rtc_ds1307 kernel module, which supports many of the common RTCs, including my DS3231 unit.  All one needs to do is to call it from /boot/config.txt:
dtoverlay=ds1307-rtc

Believe it or not, you will now have a running RTC straight away at boot time!  The i2c drivers will be loaded and /dev/rtc0 will be ready and waiting for you.

That's not quite the end of the story though, you'll find that the system time is still set to Jan 1st 1970 after boot. Thankfully, Sob's post pointed me to an issue with the udev helper /lib/udev/hwclock-set.  It's only designed to set the timezone, not the system time.  Thankfully that's a trivial fix; just change --systz to --hctosys.  When booting you should find your Pi now has the correct time copied from the RTC to the system time.

The last time related issue is to do with the PPS pin on the GPS.  Now that device tree is in effect, enabling PPS on a GPIO pin is no longer done with a parameter in /boot/cmdline.txt.  Instead there's an overlay for that too!.  Just add dtoverlay=pps-gpio,gpiopin=18 (or whichever pin you want to use) to /boot/config.txt and the PPS pin will be configured and /dev/pps0 will be up and running right after boot.

It's been a bit of a bumpy ride this week, but it's been well worth it!




1 Comments:

At 9 July 2016 at 08:26 , Blogger Geophysicist said...

This comment has been removed by the author.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home