Rock64 es az RTC DS3231 siker

3.3 V-on mukodik szepen!
RTC: https://www.hestore.hu/prod_10038042.html
Segitseg https://forum.armbian.com/topic/8856-solved-how-to-add-an-external-rtc-…
Kernel forras: https://github.com/ayufan-rock64/linux-kernel/archive/4.4.154-1128-rock…

Kernel module forditas pelda:
"
Kernel module compilation:
Follow these instructions to compile an additional kernel module.
In this example, we’ll compile the ds1307 RTC kernel module for version 4.4.154-1124:
Obtain your kernel version: uname -r (ex: 4.4.154-1124-rockchip-ayufan-ged3ce4d15ec1)
Download the kernel source code which matches your kernel version from github.com/ayufan-rock64/linux-kernel/releases
Extract the kernel: tar -zxvf 4.4.154-1124-rockchip-ayufan.tar.gz
Copy the old kernel config: bash cd linux-kernel-4.4.154-1124-rockchip-ayufan cp /usr/src/linux
headers-4.4.154-1124-rockchip-ayufan-ged3ce4d15ec1/.config . make oldconfig
Install required build packages: apt-get install bc python libncurses5-dev
Configure the kernel with the additional modules you want: make menuconfig (ex: Device Drivers --> [*] Real Time
Clock --> Dallas/Maxim DS1307..)
Exit and save the config
Prepare the modules: ```bash make EXTRAVERSION=-1124-rockchip-ayufan-ged3ce4d15ec1 modules_prepare ````
Build the module: make M=drivers/rtc (note: specify the correct directory containing the module you added)
Copy the module to the modules directory: bash mkdir -p /lib/modules/4.4.154-1124-rockchip-ayufan
ged3ce4d15ec1/kernel/drivers/rtc/ cp drivers/rtc/rtc-ds1307.ko /lib/modules/4.4.154-1124-rockchip
ayufan-ged3ce4d15ec1/kernel/drivers/rtc/
Ensure module is added to dep file: bash echo 'kernel/drivers/rtc/rtc-ds1307.ko:' >> /lib/modules
4.4.154-1124-rockchip-ayufan-ged3ce4d15ec1/modules.dep
Load the module: bash depmod -a modprobe rtc-ds1307
Ensure module is loaded on boot: echo "rtc-ds1307" >> /etc/modules
"

root@rock64:/lib/modules/4.4.154-1128-rockchip-ayufan-g61b4b1151f9a/kernel/drivers/rtc# uname -a && modinfo rtc_ds1307
Linux rock64 4.4.154-1128-rockchip-ayufan-g61b4b1151f9a #1 SMP Tue Dec 25 14:31:31 UTC 2018 aarch64 GNU/Linux
filename: /lib/modules/4.4.154-1128-rockchip-ayufan-g61b4b1151f9a/kernel/drivers/rtc/rtc-ds1307.ko
license: GPL
description: RTC driver for DS1307 and similar chips
alias: i2c:rx8025
alias: i2c:pt7c4338
alias: i2c:mcp7941x
alias: i2c:mcp7940x
alias: i2c:m41t00
alias: i2c:ds3231
alias: i2c:ds1340
alias: i2c:ds1388
alias: i2c:ds1339
alias: i2c:ds1338
alias: i2c:ds1337
alias: i2c:ds1307
depends:
vermagic: 4.4.154-1128-rockchip-ayufan-g61b4b1151f9a SMP mod_unload aarch64

i2c0 engedelyezese:
enable_dtoverlay i2c0 i2c@ff150000 okay

Megmonjuk a kernelnek, hogy a DS3231 chip hasznalja az i2c0-at:
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

root@rock64:/lib/modules/4.4.154-1128-rockchip-ayufan-g61b4b1151f9a/kernel/drivers/rtc# hwclock -r -D
hwclock from util-linux 2.29.2
Using the /dev interface to the clock.
Last drift adjustment done at 1549029470 seconds after 1969
Last calibration done at 1549029470 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2019/02/01 14:26:37
Hw clock time : 2019/02/01 14:26:37 = 1549031197 seconds since 1969
Time since last adjustment is 1727 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2019-02-01 15:26:36.139249+0100

root@rock64:/lib/modules/4.4.154-1128-rockchip-ayufan-g61b4b1151f9a/kernel/drivers/rtc# i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

/lib/udev/hwclock-set modositasa:

if [ -e /run/systemd/system ] ; then
# exit 0
/bin/enable_dtoverlay i2c0 i2c@ff150000 okay
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
fi

systemctl stop fake-hwclock.service
apt-get remove fake-hwclock.service

/etc/default/hwclock-ban

rtc1 beallitasa rtc0 helyett

reboot ...

Kar, hogy egy kicsit nagy, de kulon dobozba is rakhatom.
A lenyeg az, hogy 470+TREFA Ft(es nem tobb ezer) volt es szepen mukodik! :)
Egy ilyet meg megkockaztatok: https://www.aliexpress.com/item/Precision-DS3231-Real-Time-Clock-Module…

Hozzászólások

Én is vettem ilyet, Arduinoval raktam össze, ott is működött.

Ha én tervezném ezeket a hardwereket, akkor mai körülmények között már ésszerűbb lenne, ha nem lenne benne naptár, hanem csak egy nyers számláló volna. Amellé csak plusz regiszter kellene, aminél ha nagyobb az érték, akkor magasba menne az interrupt vonal. Esetleg ebből kettő: az egyik az ébresztőt vezérelné, a másik pedig arra lenne jó, hogy nagyon pontosan hozzá lehetne szinkronizálni - ha szükséges.

A beállításnál pedig beírjuk a számláló értékét egy latch-be, amit egy külső órajelre tölt be a fő számlálóba - szintén, hogy pontosan szinkornizálni tudjon.