Utalising an i2c RTC module


#1

I’ve been trying for the past few hours to get resin to look at a hardware clock at boot time as I need a rough approximation of the time when used in a closed network (can’t always guarantee that the device will be able to sync with ntp).

Traditionally, this involves putting a little code in /etc/rc.local such that it is executed at boot time, however I cannot find a way to either replicate this from the container, or inject the code into the base OS (preferably into the image so it is a one off process).

The code to be executed is (roughly)
echo ds3231 0x68 >/sys/bus/i2c/devices/i2c-1/new_device echo BB-I2C1 > /sys/devices/bone_capemgr.9/slots sleep 1 hwclock -f /dev/rtc1 -s


#2

Running on host OS start would be tricky, but can’t see a reason why it couldn’t be part of the container startup, using systemd for example (having a one-off systemd service and ENV INITSYSTEM on, if you use Debian or Fedora). The both /sys and /dev should be exposed for you, so the commands should theoretically work.

What ways have you tried so far to replicate it from the container?
(mostly just brainstorming here:)


#3

So it turns out I was being an idiot, and theres actually two mistakes in here which means this won’t work.

Firstly the first line is infact two commands and should have been on two lines.
Secondly the second command on that line is for an old kernel version before the capemgr got moved to /sys/devices/platform/bone_capemgr/slots.

Fixing those two works perfectly (backdated the hwclock and logged on start to test).

I’m now having issues trying to debug the capemgr though as attempting to remove a slot causes the world of exceptions and the SSH session to terminate.


#4

That looks intriguing, @ItsGhost, haven’t used capemgr myself before :smiley:

How are you removing slots? Something like described here? https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/exporting-and-unexporting-an-overlay What sort of exceptions do you see and how do you debug the capemgr (what is actually your workflow?)


#5

That’s pretty much exactly how I’m doing it, the only difference being the persistence (which is done via the bash start script instead of uEnv.txt).

In terms of debugging it and exceptions, as best I can tell they are coming from attempting to remove an overlay (as described with -x written to slots), at which point the console turns to gibberish, the SSH session terminates, and the device stops responding until rebooted.

The best way I have found to debug it is to disable the overlay in the startup script, SSH in and run the appropriate lines manually then go from there. Once I had the correct commands I simply added them back into the startup script (in this case enabling I2C-1 and UART-1).


#6

Hi…as per my knowledge the RTC subsytem with 32kHz crystal is running for the needs of scheduler, but there is no implementation yet for date/time.For now it should be possible to use STM32 HAL library, which is in the BigClown SDK, hovewer we try to avoid these libraries because of the code size and implement the functionality ourselves.

multilayer pcb