Help us understand the problem. What is going on with this article?

ASUS Tinker Board: リアルタイムクロックモジュール(RTC DS3231)を使う

More than 1 year has passed since last update.

概要

ラズパイで使ったことのある、RTCモジュール DS3231 を、ASUS TinkerBoardで使ってみる。

環境

  • TinkerOS debian 2.0.1 beta

    linaro@linaro-alip:~$ uname -a
    Linux linaro-alip 4.4.71+ #1 SMP Thu Aug 17 00:28:01 CST 2017 armv7l GNU/Linux
    
  • DS3231 module (I2C)

tl;dr

  1. Kernel setting & Sync RTC

    # Switch to 'root'
    sudo -s
    # Get files
    wget https://raw.githubusercontent.com/mt08xx/files/master/TinkerBoard/kernel_module/lib/modules/4.4.71/kernel/drivers/rtc/rk3288-miniarm.dtb
    wget https://raw.githubusercontent.com/mt08xx/files/master/TinkerBoard/kernel_module/lib/modules/4.4.71/kernel/drivers/rtc/rtc-ds1307.ko
    # rk3288-miniarm.dtb : backup & copy
    [ ! -e /boot/rk3288-miniarm.dtb.org ] && mv -v /boot/rk3288-miniarm.dtb  /boot/rk3288-miniarm.dtb.org
    mv -v ./rk3288-miniarm.dtb  /boot/rk3288-miniarm.dtb 
    # rtc-ds1307.ko
    mkdir -p /lib/modules/4.4.71+/kernel/drivers/rtc/
    mv -v ./rtc-ds1307.ko /lib/modules/4.4.71+/kernel/drivers/rtc/
    #
    depmod -a
    # Reboot
    sync && sleep 5 && reboot
    # After reboot, you can see /dev/rtc1 .
    

    => /dev/rtc1 が現れる

  2. ファイルを4つ編集 / Edit 4 files.

    • rtc0 => rtc1

      /etc/default/hwclock
      ...
      ...
      HCTOSYS_DEVICE=rtc1
      
      /lib/udev/rules.d/85-hwclock.rules
      KERNEL=="rtc1", RUN+="/lib/udev/hwclock-set $root/$name"
      
      /lib/udev/rules.d/50-udev-default.rules
      SUBSYSTEM=="rtc", KERNEL=="rtc1", SYMLINK+="rtc", OPTIONS+="link_priority=-100"
      
    • Comment out

      /lib/udev/hwclock-set
      #if [ -e /run/systemd/system ] ; then
      #    exit 0
      #fi
      
  3. RTCモジュールの時刻同期 / Sync time for RTC module

    # Switch to 'root'
    sudo -s
    # Check Current RTC time.
    hwclock --rtc=/dev/rtc1 --get
    # Stop ntp service
    systemctl stop ntp
    # 
    ntpdate -v time.nist.gov 
    # Update RTC time : --systohc
    hwclock --rtc=/dev/rtc1 -w
    # Check Current RTC time again.
    hwclock --rtc=/dev/rtc1 --get
    #
    # Reboot
    reboot
    

ビルド / build

  1. Prepare Build Environment ( cross / self ...they may need to be updated...)
  2. git clone --depth 1 -b linux4.4-rk3288 https://github.com/TinkerBoard/debian_kernel.git
  3. drivers/rtc/rtc-ds1307.ko

    drivers/rtc/rtc-ds1307.ko
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- miniarm-rk3288_defconfig
    echo "CONFIG_RTC_DRV_DS1307=m" >> .config
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules
    
  4. arch/arm/boot/dts/rk3288-miniarm.dtb

    arch/arm/boot/dts/rk3288-miniarm.dts
    diff --git a/arch/arm/boot/dts/rk3288-miniarm.dts b/arch/arm/boot/dts/rk3288-miniarm.dts
    index cf11a15..85e80c4 100755
    --- a/arch/arm/boot/dts/rk3288-miniarm.dts
    +++ b/arch/arm/boot/dts/rk3288-miniarm.dts
    @@ -589,6 +589,10 @@
                    reg = <0x4c>;
                    status = "disabled";
            };
    +        rtc: ds1307@68 {
    +                compatible = "dallas,ds1307";
    +                reg = <0x68>;
    +        };
     };
     &i2c3 {
    
    arch/arm/boot/dts/rk3288-miniarm.dtb
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
    
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした