How to PCF8563 RTC Module on the Odroid C2

Preparations

  • ODROID-C2
  • uSD-Card ⇒ over 8GB or eMMC Module
  • PCF8563 RTC Module
  • Linux Kernel 3.14.65-66 or higher.how-to-update-kernel

Configuration

Ubuntu

  1. Insert the RTC Shield on your C2 as the above pictures and turn on the system.
  2. Enable RTC Shield driver in Device Tree file and add the I2C driver
    odroid@odroid:~$ sudo apt install device-tree-compiler
    odroid@odroid:~$ sudo fdtput -t s /media/boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"
    odroid@odroid:~$ echo "aml_i2c"|sudo tee -a /etc/modules
    odroid@odroid:~$ echo "rtc_pcf8563"|sudo tee -a /etc/modules
    odroid@odroid:~$ reboot
  3. Check the I2C & RTC module status after reboot:
    odroid@odroid64:~$ cat /etc/modules                                             
    # /etc/modules: kernel modules to load at boot time.                            
    #                                                                               
    # This file contains the names of kernel modules that should be loaded          
    # at boot time, one per line. Lines beginning with "#" are ignored.             
    aml_i2c
    
    odroid@odroid64:~$ ls /dev/rtc                                                  
    /dev/rtc
    
    odroid@odroid64:~$ lsmod
    .....
    rtc_pcf8563             3996  0
    aml_i2c                16898  0
    .....
  4. Next you want to update system Time/Calendar from the HW RTC at boot time by editing /etc/rc.local file
    odroid@odroid:~$ sudo nano /etc/rc.local
    
    if [ -f /aafirstboot ]; then /aafirstboot start ; fi
    
    hwclock -s
    
    exit 0
    odroid@odroid:~$

    Add the following at the bottom of the page above exit 0. ^x exit and save the file. Reboot your ODROID-C2.

    odroid@odroid:~$ sudo reboot

    If everything worked correctly the RTC on ODROID-C2 should be initialised on boot and the current date and time will be loaded into Linux. You need to check the existence of “rtc-pcf8563” in the output of “lsmod” command when the HW RTC doesn't work correctly.

  5. You can check the current time on the RTC on ODROID-C2 with:
    odroid@odroid:~$ sudo hwclock -r

    If this is the first time you have run the RTC on ODROID-C2 it will display a date of APR 20th 2016.

  6. If the ODROID-C2 is connected to the internet the correct date and time should be set automatically otherwise you can set the current date and time using:
    odroid@odroid:~$ sudo date -s "20 APR 2016 18:00:00" 

    You can check the current linux date with the command (date).

  7. To save the date into the RTC chip on ODROID-C2 use the following command:
    odroid@odroid:~$ sudo hwclock -w 

    Verify the date has been saved onto the RTC on ODROID-C2 with:

    odroid@odroid:~$ sudo hwclock -r

Kernel update will break the RTC functionality
To avoid this problem, you can use this workaround that will patch the dtb all the time

sudo -s
echo '#!/bin/sh' > /etc/kernel/postinst.d/rtc
echp 'fdtput -t s /boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"' >> /etc/kernel/postinst.d/rtc
chmod +x /etc/kernel/postinst.d/rtc


Android

This guide works on Android 5.1 V2.8 and V2.9 images only.

Open File Manager app.

Edit /storage/internal/boot.ini like this. (near end of file).

Before edit.

movi read dtb 0 ${dtbaddr}
# load kernel from vat or boot partition.
movi read boot 0 ${loadaddr}
#fatload mmc 0:1 ${loadaddr} Image_android
booti ${loadaddr} - ${dtbaddr}

After edit.

movi read dtb 0 ${dtbaddr}
# load kernel from vat or boot partition.
#movi read boot 0 ${loadaddr}
fatload mmc 0:1 ${loadaddr} Image_android
booti ${loadaddr} - ${dtbaddr}

Load kernel image from vfat partition built rtc module.

If you could not find 'fatload' command, remove /storage/internal/boot.ini file and reboot system.

Don't use NTP service

Update
If your network firewall is blocking the ntp service or no internet connection, you must stop the ntp service. Once the NTP failed, the RTC value could be reset !!!


Credit:
This instruction was made by phaseshifter (our forum member).
Original Post

To stop ntpd:

 sudo /etc/init.d/ntp stop 

or

 sudo service ntp stop 

To prevent it from starting at boot:

 sudo update-rc.d -f ntp remove 

Estimated life cycle of the battery

We cleanly installed Android 5.1 V3.3 image and measured the power consumption.
When C2 turns on, it consumes less than 1uA.
When C2 turns off, it consumes around 15uA.

According to CR2032 Panasonic datasheet, its nominal capacity is 225mAh.
http://www.cr2032.co/cms/prodimages/panasonic_cr2032_datasheet.pdf
So its backup time could be around 15000 hours (~ two years).
If on/off ratio is 1:1, it can be 3~4 years.

en/pcf8563rtc.txt · Last modified: 2017/07/05 14:04 by codewalker
CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0