1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-09-07

概要

ラズパイで使ったことのある、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

    ```bash
# 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` が現れる
  1. ファイルを4つ編集 / Edit 4 files.
    • rtc0 => rtc1

      /etc/default/hwclock

...
...
HCTOSYS_DEVICE=rtc1


        ```bash:/lib/udev/rules.d/85-hwclock.rules
KERNEL=="rtc1", RUN+="/lib/udev/hwclock-set $root/$name"
    ```bash:/lib/udev/rules.d/50-udev-default.rules

SUBSYSTEM=="rtc", KERNEL=="rtc1", SYMLINK+="rtc", OPTIONS+="link_priority=-100"


    - Comment out

        ```bash:/lib/udev/hwclock-set
# if [ -e /run/systemd/system ] ; then
#    exit 0
# fi
  1. 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](http://qiita.com/mt08/items/e8afe6de9e8a0bf1e89f) / [self](http://qiita.com/mt08/items/890a71d0b399ac1a9b49) ...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`

    ```bash: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
  1. 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


1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?