Author Topic: Add rtc support for cubieboard(a10/a20)  (Read 15184 times)

Offline benn

  • Newbie
  • *
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Add rtc support for cubieboard(a10/a20)
« on: July 23, 2013, 08:41:56 am »
There is a simple way to add RTC support for cubieboard(a10/a20).

I do this at cubieboard2(A20), with ubuntu-12.04-v1.04beta OS
(http://cubiebook.org/index.php?title=Cubieboard2/Lubuntu_12.04_Desktop)

1. Buy a Arduino DS1307 RTC
there is a link for that
http://item.taobao.com/item.htm?spm=a230r.1.14.204.ubPqav&id=16665162201


2. wired the RTC board to Cubieboard
VCC -> UART Debug Port's VCC
GND-> UART Debug Port's GND
SCK-> PB18
SDA->PB19

see http://linux-sunxi.org/Cubieboard/ExpansionPorts

3. Dump data with i2c-tools
#i2cdetect 1
#i2cdump 1 0x68

If you don't have i2c-tools, please install it,
for ubuntu:
apt-get install i2c-tools





Offline wantmymoneyback

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +4/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #1 on: July 23, 2013, 03:15:57 pm »
I have the Cubieboard 1 and have been trying to do this for over a month.
I use pin 1 and 20 for the 5V and GND. With a multimeter I get 4.xx volts on the header pins attached to the RTC board.
But i2ctools -y 0 only shows UU at 0x34.
I followed advice to get /dev/i2c-0, -1, -2 at boot, and lsmod indicates that rtc_ds1307 is loaded but used by 0 processes.
Where did you put the modprobe to load rtc_ds1307? Why is it rtc-ds1307 when loaded and rtc_ds1307 with lsmod?

I then have used hwclock -s to set the time, but it never works.
I trimmed a bit of plastic off the ends of the female header pins to get the correct contacts, it seems the Cubieboard bottom pins are not long enough otherwise.
So since I can measure ~5 V on the RTC, it seems that PB18 and 19 must also be making contact.

What software do you have to get the clock read at boot? Arduino says that in the boot sequence, rtc will be listed but I can not get that to happen.

Offline wantmymoneyback

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +4/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #2 on: July 24, 2013, 02:48:04 pm »
Further information: I get lsmod showing rtc_ds1307 is installed but not used by any process, and /dev/i2c0, /dev/i2c1, and /devi2c2 at boot. There is /dev/rtc0 at boot also, but no link to rtc, which the /sys/class/i2c stuff seems to want. If I shutdown -r now, I then have a /dev/rtc link, and hwclock -s works.

How do I get /dev/rtc link at boot?

What are the i2c tool for seeing if the RTC board is even working? I'm beginning to think that I am setting the A10 RTC, not my i2c Tiny RTC.

yang.zheng

  • Guest
Re: Add rtc support for cubieboard(a10/a20)
« Reply #3 on: December 29, 2013, 08:58:09 am »
Hi guys,

I was also confused by this RTC (ds1307) module issue when I tried it on my CB2.
But, like benn, I DO get it work on my CB1.  Once it was realized that the kernel was different.

When I got latest kernel branch sunxi-3.4 from https://github.com/linux-sunxi/linux-sunxi, rtc ds1307 can't be detect with cmd "i2cdetect -y 1" on CB2. While it CAN be when the kernel (as far as I know pat 3.4.43) from https://github.com/patrickhwood/linux-sunxi.

So I guess the kernel used by benn is Cubiuntu, Cubieez or other distros based on patwood's work.

Unfortunately I don't know why  :-[ (any detail about it if somebody knew, please share it  :)) .

Related threads:
1. excellent works from patwood
http://www.cubieforums.com/index.php/topic,472.0.html
2. Cubieez from drkbcn
http://www.cubieforums.com/index.php/topic,528.30.html


BTW, with proper kernel, connecting rtc ds1307 correctly as described by benn, it can be detected by cmd "i2cdetect - y 1".  Running "modprobe rtc-ds1307" or "insmod /lib/modules/***/kernel/driver/rtc/rtc-ds1307.ko",   and after
 "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device", /dev/rtc1 would be created if everything was OK.   Then hwclock can work sequencely.

thanks
yang.zheng
« Last Edit: December 30, 2013, 10:46:44 am by yang.zheng »

Offline wantmymoneyback

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +4/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #4 on: December 29, 2013, 02:40:05 pm »
OK so you give a kernel source that is a page long!!! WHAT from there do I need to download, compile and then install to get my Fedora 18 to actually detect an RTC?

Offline patwood

  • Linux geek
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1660
  • Karma: +129/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #5 on: December 29, 2013, 11:01:14 pm »
Hi guys,

I was also confused by this RTC (ds1307) module issue when I tried it on my CB2.
But, like benn, I DO get it work on my CB1.  Once it was realized that the kernel was different.

When I got latest kernel branch sunxi-3.4 from https://github.com/linux-sunxi/linux-sunxi, rtc ds1307 can't be detect with cmd "i2cdetect -y 1" on CB2. While it CAN be when the kernel (as far as I know pat 3.4.43) from https://github.com/patrickhwood/linux-sunxi.

So I guess the kernel used by benn is Cubiuntu, Cubieez or other distros based on patwood's work.

Unfortunately I don't know why  :-[ (any detail about it if somebody knew, please share it  :)) .

Neither do I!  Nothing in my branches have anything extra for i2c.  My pat-3.4.xx branches on github are fairly up-to-date with the corresponding ones in the stage/sunxi-3.4 branch on linux-sunxi/linux-sunxi (the pat-3.4.67 and pat-3.4.75 are the most recent, by the way).  If you are using the sunxi-3.4 branch on linux-sunxi/linux-sunxi and not the stage/sunxi-3.4 branch, you're getting older code, which might be why it's not working for you.

yang.zheng

  • Guest
Re: Add rtc support for cubieboard(a10/a20)
« Reply #6 on: December 30, 2013, 10:27:32 am »
Hi guys,

I was also confused by this RTC (ds1307) module issue when I tried it on my CB2.
But, like benn, I DO get it work on my CB1.  Once it was realized that the kernel was different.
....

Unfortunately I don't know why  :-[ (any detail about it if somebody knew, please share it  :)) .

Neither do I!  Nothing in my branches have anything extra for i2c.  My pat-3.4.xx branches on github are fairly up-to-date with the corresponding ones in the stage/sunxi-3.4 branch on linux-sunxi/linux-sunxi (the pat-3.4.67 and pat-3.4.75 are the most recent, by the way).  If you are using the sunxi-3.4 branch on linux-sunxi/linux-sunxi and not the stage/sunxi-3.4 branch, you're getting older code, which might be why it's not working for you.

en..

In my memory about my CB2 board,  the issue occured with  two branches https://github.com/cubiboard2/linux-sunxi (definitely it's dead) and https://github.com/linux-sunxi/linux-sunxi. Regarding to the last one, I'm not sure now (two weeks ago). Probably wrong branch was cloned due to some decrepted instructions.

So far as pat pointed out, I'll do my test again with that stage in the following days.

yang.zheng

  • Guest
Re: Add rtc support for cubieboard(a10/a20)
« Reply #7 on: December 30, 2013, 10:42:21 am »
OK so you give a kernel source that is a page long!!! WHAT from there do I need to download, compile and then install to get my Fedora 18 to actually detect an RTC?

Well, I think I2C module in the kernel is the key point in this issue.

So if you don't want to spend your time on compiling kernel, I may suggest you to try:
http://dl.cubieforums.com/patwood/A20-kernel-3.4.67.tar.gz
or http://dl.cubieforums.com/patwood/A20-kernel-3.4.61.tar.gz

with your favoured rootfs like Fedora XX.

Please use rtc-ds1307.ko correspoinding to your choiced branch.

Hope it's useful for you.
« Last Edit: December 30, 2013, 10:48:52 am by yang.zheng »

Offline patwood

  • Linux geek
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1660
  • Karma: +129/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #8 on: December 30, 2013, 12:32:45 pm »
Hi guys,

I was also confused by this RTC (ds1307) module issue when I tried it on my CB2.
But, like benn, I DO get it work on my CB1.  Once it was realized that the kernel was different.
....

Unfortunately I don't know why  :-[ (any detail about it if somebody knew, please share it  :)) .

Neither do I!  Nothing in my branches have anything extra for i2c.  My pat-3.4.xx branches on github are fairly up-to-date with the corresponding ones in the stage/sunxi-3.4 branch on linux-sunxi/linux-sunxi (the pat-3.4.67 and pat-3.4.75 are the most recent, by the way).  If you are using the sunxi-3.4 branch on linux-sunxi/linux-sunxi and not the stage/sunxi-3.4 branch, you're getting older code, which might be why it's not working for you.

en..

In my memory about my CB2 board,  the issue occured with  two branches https://github.com/cubiboard2/linux-sunxi (definitely it's dead) and https://github.com/linux-sunxi/linux-sunxi. Regarding to the last one, I'm not sure now (two weeks ago). Probably wrong branch was cloned due to some decrepted instructions.

So far as pat pointed out, I'll do my test again with that stage in the following days.

Those are the repos, but there are multiple branches in each.

git branch

Shows you the available branches.

git checkout

Allows you to switch.  I think the default branch at linux-sunxi is the stable sunxi-3.4 branch, not the newer stage branch.

Offline wantmymoneyback

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +4/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #9 on: December 30, 2013, 04:21:53 pm »
Hello Everyone:
I hope yesterday's post from me didn't seem too impolite, sorry if you thought it was.
I forgot to bring with me the piece of paper on which I wrote the boot message, but I get a sunxi can't find rtc or something similar when I boot. Last summer with Fedora 18 from Hans, I had an rtc-1307 ko module that I loaded at boot. Some times, and today is one of the times after yesterday when I put the make /dev/i2c command in modules-load.d, the time is 31 DEC 2009, not the usual start up 31 DEC 1969, 7 PM. So something at times seems to try to read a default from the ds1307. But busybox or any other method of setting the hardware clock does not work.

When I turn off and reboot, the time stays correct; this can continue for a  few minutes. That causes many problems trying to determine if I have set the ds1307 clock or if some persistence in the ARM chip clock is working.

I see the Arduino methods, but they have special header files that are telescoped so that trying to install one and compile just ends up with more and more unfound headers.

There must be some way to describe to me and everyone else in the world how to attach, set, and subsequently read a ds1307 RTC by a Cubieboard 1.

Offline @lex

  • Full Member
  • ***
  • Posts: 157
  • Karma: +4/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #10 on: July 16, 2015, 07:33:31 pm »
Ok, i need to revive this thread because something is wrong with this information/instructions or wrong with my cb2.

Recently i needed to have this external rtc attached and working on my CB2 but for some reason or the lack of knowledge (hardware) from me, did not work! And perhaps it will not work as expected.

I have followed this instructions verbatim (double checked, triple checked) and i have the following issue:
* if i turn OFF the CB2, the rtc is not detected on next boot, but i can see i2c finds the rtc at the address.
* if i reboot the CB2, everything works as expected, i can set the date and time and the next reboot i get the correct date and time.

At fisrt, i had a similar rtc module, not the exact one pointed by Benn.
After many troubles and tries i gave up with this one and ordered the one from the link, and same problem.

I googled and found DS1307 needs 5v as VCC input, i measured the UART Debug Port's VCC on my cb2 to have 3.25v and i think that is the source of problem.
For some reason, both rtc modules don't have a level shifter,  if they do i don't know how to turn it on , or worse the UART Debug Port's VCC should be 5v and mine is 3.25v.

I can measure during reboot that the UART Debug Port's VCC is never 0v ( stays at ~0.52v )and that could trigger the rtc module to be detected.

Does any one have this setup working? (using 3.25v)
Can you suggest some work around? I don't have any 5v pin available, unless i can share it and it is safe to do it.

PS: i just found CB1 UART Debug Port's VCC runs on ~3.81v!!
Update: used 5v as input, still the same.
« Last Edit: July 17, 2015, 11:05:53 am by @lex »

Offline @lex

  • Full Member
  • ***
  • Posts: 157
  • Karma: +4/-0
    • View Profile
Re: Add rtc support for cubieboard(a10/a20)
« Reply #11 on: July 18, 2015, 08:10:54 pm »
I finally got it working on sunxi kernel 3.4.103.
I could not see anything wrong with the rtc-sun4i, there are some minor changes since kernel 3.4.39 and i could not figure out what was wrong, maybe it should wait a bit more for reading the register, or the i2c bus is busy at cold boot (it is just a guess...don't bother).

How i did it:
* Disabled the RTC SUN4I (sunxi-rtc)
* Enabled the RTC ds-1307 as a module
* loaded the ds-1307 driver module
* instantiate it to create /dev/rtc0 (our rtc clock)
* update the time from your preferred place, i use ubuntu: ntpdate -u ntp.ubuntu.com
* write it to rtc chip after your time is updated on task bar (wait a few seconds!): hwclock -w

you can check the time:
cat /proc/driver/rtc
and from the chip:
hwclock -r

If you want you can write the time directly to the chip:
hwclock --set --date="07/18/15 17:00:00"
and then you can update the ubuntu from the chip:
hwclock -s

Now we have the date and time on the rtc memory chip.

Note:
the rtc module described in the original link needs 5v vcc input, but i found one that tolerates 3.2v