Kickpi-Book
  • KICKPI Document
  • K5/K5C(A133)
    • A133中文文档
      • 01-主板介绍
        • 01-KICKPI-K5硬件介绍
        • 02-KICKPI-K5C硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-扩展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-SD卡烧录
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK源码编译
        • 03-ANDROID_SDK源码编译
      • 05-外设驱动
        • LCD功能调试
        • LRADC按键配置
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
      • 07-LINUX系统定制
        • 02-Linux常用系统定制
      • 08-进阶
        • K5C主板供电
        • 安卓休眠唤醒
        • 13-硬件工厂测试
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K5_Hardware_Introduction
        • 02-KICKPI-K5C_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-How_to_Get_Image_File
        • 02-SD Card Burning
        • 03-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • ADB_Tutorial
  • K2B/K2C(H618)
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K2B_Hardware_Introduction
        • 02-KICKPI-K2B_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-SD_Card_Flashing
        • 02-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 05-Drivers_Development
        • RTC
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • 01-Linux_Common_System_Customization
      • 08-Advanced_Topics
        • Hardware_Factory_Testing
        • Keybox
    • zh
      • 01-主板介绍
        • 01-KICKPI-K2B硬件介绍
        • 02-KICKPI-K2C硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-扩展引脚
      • 03-镜像烧录
        • 01-SD卡烧录
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK源码编译
        • 2. Android SDK编译
      • 05-外设驱动
        • RTC
      • 06-Android系统定制
        • Android常用系统定制
      • 07-Linux系统定制
        • 01-Linux常用系统定制
        • 02-Linux_QT开发环境搭建
      • 08-进阶
        • Keybox
        • Secure Boot
        • Windows_QT开发环境搭建
        • 扩展引脚功能定制
        • 硬件工厂测试
  • K1/K1B/K3/K8(RK356x-RK3588)
    • en
      • 01-Development_board_Introduction
        • 01-RK_Chip_Comparison_Introduction
        • 02-KICKPI-K1_Hardware_Introduction
        • 03-KICKPI-K1B_Hardware_Introduction
        • 04-KICKPI-K3_Hardware_Introduction
        • 05-KICKPI-K8_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-Cloud_Storage_Directory_Description
        • 02-K1-Quick_Start_Guide
        • 02-K1B-Quick_Start_Guide
        • 02-K3-Quick_Start_Guide
        • 02-K8-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins
      • 03-Image_Flashing_Guide
        • 01-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-LINUX_SDK_Compilation
        • 03-ANDROID_SDK_Compilation
      • 05-Drivers_Development
        • GPIO
        • Kernel
        • LCD
        • PWM
        • RTC
      • 06-Android_System_Customization
        • 01-Common_Android_System_Customizations
        • 01-Common_Android_System_Customizations
      • 07-Linux_System_Customization
        • 01-Common_Linux_System_Customization
        • 02-Installing_VNC_on_Linux
        • 03-Linux_Docker
        • 04-Linux_QT_Environment_Setup
        • 05-Linux_NPU_YOLOV5S_object_detection
      • 08-Advanced_Topics
        • 01-Hardware_Factory_Test
        • 02-Hardware_Aging_Test
        • 03-Firmware_Unpacking_and_Packing
    • zh
      • 01-主板介绍
        • 01-RK芯片对比介绍
        • 02-KICKPI-K1硬件介绍
        • 03-KICKPI-K1B硬件介绍
        • 04-KICKPI-K3硬件介绍
        • 05-KICKPI-K8硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-K1-快速使用
        • 02-K1B-快速使用
        • 02-K3-快速使用
        • 02-K8-快速使用
        • 03-功能测试
        • 04-拓展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK编译
        • 03-ANDROID_SDK编译
      • 05-外设驱动
        • GPIO
        • Kernel
        • LCD
        • PWM
        • RTC
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
        • 07-Android NPU YOLOV5 目标检测
      • 07-LINUX系统定制
        • 01-Linux常用系统定制
        • 02-Linux安装VNC
        • 03-Linux Docker环境搭建
        • 04-Linux QT环境搭建
        • 05-Linux NPU YOLOV5S 目标检测
      • 08-进阶
        • 01-硬件工厂测试
        • 02-硬件老化测试
        • 03-固件解包和打包
  • K7(RK3576)
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K7_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-How_to_Get_Image_File
        • 02-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 05-Drivers_Development
        • ADC
        • PWM
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • 01-Linux_Common_System_Customization
        • 02-Linux_Docker_Environment_Setup
        • 03-Linux_NPU_YOLOv5s_Object_Detection
        • 04-Linux_DeepSeek_Large_Model
        • 05-Linux_VNC_Remote_Control
      • 08-Advanced_Topics
        • Advanced_Testing
    • zh
      • 01-主板介绍
        • 01-KICKPI-K7硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-拓展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-Linux_SDK编译
        • 03-Android_SDK编译
      • 05-外设驱动
        • ADC
        • PWM
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
      • 07-LINUX系统定制
        • 01-Linux常用系统定制
        • 02-Linux Docker环境搭建
        • 03-Linux NPU YOLOV5S 目标检测
        • 04-Linux_Deepseek大模型
        • 05-Linux_VNC远程控制
      • 08-进阶
        • 进阶测试
  • K4B(T113-S3)
    • T113-S3中文文档
      • 01-KICKPI-K4B硬件介绍
      • 10-系统镜像烧录
      • 11-SDK源码编译
      • 12-硬件功能测试
      • 13-硬件工厂测试
      • LCD功能调试
      • 20-Ubuntu20.04系统定制
      • Buildroot_QT5配置
      • Buildroot系统定制
  • common
    • en
      • adb
        • ADB_Tutorial
      • allwinner_burnning
        • SD_Card_Flashing
        • USB_Cable_Flashing
      • debug
        • 01 - Log Collection
      • display
        • FPC_Interface_Introduction
      • linux
        • SSH
    • zh
      • adb
        • ADB教程
      • android
        • qt
      • debug
        • 01-日志抓取
        • 常见问题
      • display
        • FPC接口介绍
      • linux
        • SSH
        • VNC
        • qt
      • 全志烧录
        • SD卡烧录
        • USB线烧录
Powered by GitBook
On this page
  • Device Hardware Connection
  • IO ports used on the board:
  • Physical wiring is as follows:
  • Device Driver Transplantation
  • Add an RTC node to I2C3 in the device tree
  • Test whether the RTC driver works properly using date and hwclock
  • RTC Interrupt Test:
  1. K1/K1B/K3/K8(RK356x-RK3588)
  2. en
  3. 05-Drivers_Development

RTC

Last updated 4 days ago

Some boards do not have an on-board RTC module. Customers with time-saving requirements can choose to connect an external RTC module.

The following example shows how to connect an I2C-RTC module externally to a K1B-Android board:

Device Hardware Connection

IO ports used on the board:

image-20250222170554561

Physical wiring is as follows:

Usually, the CLK_OUT pin is not used and not connected. The INT pin can be connected according to requirements. Since the board does not have IO ports with pull-up resistors, it is not connected here.

Device Driver Transplantation

The RK356x SDK comes with drivers for some RTC models by default. If the model you are using is not included, you need to transplant the driver. In the example, the hym8563 driver is used (which is already included in the SDK), but the following briefly introduces the steps for driver transplantation.

RK-RTC driver location path:

rk-android13.0\kernel-5.10\drivers\rtc\

Place the kernel driver obtained from the RTC manufacturer in this directory.

Some manufacturers may not provide kernel driver code, only MCU code. In this case, you have to convert the MCU driver to a Linux kernel driver by yourself.

Modify the Makefile in the driver path:

+ obj-$(CONFIG_RTC_DRV_HYM8563)	+= rtc-hym8563.o 

Modify the Kconfig in the driver path:

+//make menuconfig
+config RTC_DRV_HYM8563
+	tristate "Haoyu Microelectronics HYM8563"
+	depends on OF
+	help
+	  Say Y to enable support for the HYM8563 I2C RTC chip. Apart
+	  from the usual rtc functions it provides a clock output of
+	  up to 32kHz.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-hym8563.

Enable the kernel:

--- a/kernel-5.10/arch/arm64/configs/rockchip_defconfig
+++ b/kernel-5.10/arch/arm64/configs/rockchip_defconfig
@@ -864,7 +864,6 @@ CONFIG_LEDS_TRIGGER_BACKLIGHT=y
 CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
 CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_HYM8563=y
 CONFIG_DMADEVICES=y
 CONFIG_PL330_DMA=y
 CONFIG_RK_DMABUF_DEBUG=y

Add an RTC node to I2C3 in the device tree

--- a/kernel-5.10/arch/arm64/boot/dts/rockchip/rk3568-kickpi-extend-20pin.dtsi
+++ b/kernel-5.10/arch/arm64/boot/dts/rockchip/rk3568-kickpi-extend-20pin.dtsi
@@ -15,6 +15,17 @@ 
&i2c3 {
     status = "okay";
     pinctrl-names = "default";
     pinctrl-0 = <&i2c3m0_xfer>;
+
+    hym8563: hym8563@51 {
+               compatible = "haoyu,hym8563";
+               reg = <0x51>;
+               #clock-cells = <0>;
+               clock-frequency = <32768>;
+               clock-output-names = "hym8563";
+               // IRQ GPIO IS MODIFYED FOR UPDATE HYM8562 DRIVER 
+               //rtc-irq-gpio = <&gpio0 RK_PC2 IRQ_TYPE_EDGE_FALLING>;
+       };
+
 };

The rtc-irq-gpio corresponds to the IO port where the INT pin is connected. Since it was not connected in the test, it is commented out.

Test whether the RTC driver works properly using date and hwclock

The following test steps are applicable to all systems. Step 6 is the most critical test.

  1. Display the current Linux system time

$ date
  1. If the date time is incorrect, for example, it shows a time like 1970 instead of the current time (e.g., 2009), manually set the correct time.

$ date MMDDhhmm[[[CC]YY][.ss]]

MM is the month (01 - 12)

DD is the day (01 - 31)

hh is the hour (00 - 23)

mm is the minute (00 - 59)

[[CC]YY] is the year (optional, CC is the century, YY is the year)

[.ss] is the second (optional)

  1. Display the hardware RTC time

$ hwclock

Since this is the first time the RTC driver is loaded, some platforms may not have the correct time set yet. The displayed time may be incorrect, such as 1969 or 1970.

  1. Set the Linux system time to the hardware RTC

$ hwclock -w
  1. Check again whether the hardware RTC time is consistent with the system time

$ hwclock

If the driver is working correctly, the displayed time here should be consistent with the current system time, which means the time is synchronized. Otherwise, it indicates that the driver is not working correctly and has not set the system time to the hardware RTC properly. You need to go back and debug the driver to find the cause.

  1. Power off the device, wait for a few minutes, then power it on again and enter:

$ hwclock

Normally, you will see that the time here has increased by the corresponding minutes and seconds compared to the time displayed in step 5, indicating that the RTC is working properly.

RTC Interrupt Test:

  1. Clear and restore

$ echo 0 > /sys/class/rtc/rtc0/wakealarm
  1. Set the time

$ echo +60 > /sys/class/rtc/rtc0/wakealarm 

+60: indicates that the interrupt will be triggered after 60 seconds

View RTC information

$ cat /proc/driver/rtc
rtc_time        : 07:16:39
rtc_date        : 2025-03-08
alrm_time       : 06:42:53
alrm_date       : 2025-03-08
alarm_IRQ       : yes
alrm_pending    : no
update IRQ enabled      : no
periodic IRQ enabled    : no
periodic IRQ frequency  : 1
max user IRQ frequency  : 64
24hr            : yes

View system interrupt information:

$ cat /proc/interrupts

To visually observe the interrupt, you can add a print statement for the RTC interrupt time in the RTC interrupt function. You can refer to the following modification:

---a\kernel-5.10\drivers\rtc\rtc-hym8563.c
+++b\kernel-5.10\drivers\rtc\rtc-hym8563.c

static irqreturn_t hym8563_irq(int irq, void *dev_id)
{
  struct hym8563 *hym8563 = (struct hym8563 *)dev_id;
  struct i2c_client *client = hym8563->client;
  struct mutex *lock = &hym8563->rtc->ops_lock;
  int data, ret;
+  printk("kickpi %s %d\n",__FUNCTION__,__LINE__); //add log
  mutex_lock(lock);

  /* Clear the alarm flag */
  data = i2c_smbus_read_byte_data(client, HYM8563_CTL2);
  if (data < 0) {
    dev_err(&client->dev, "%s: error reading i2c data %d\n",
      __func__, data);
    goto out;
  }
  data &= ~HYM8563_CTL2_AF;
  
  ret = i2c_smbus_write_byte_data(client, HYM8563_CTL2, data);
  if (ret < 0) {
   dev_err(&client->dev, "%s: error writing i2c data %d\n",
     __func__, ret);
  }
out:
  mutex_unlock(lock);
  return IRQ_HANDLED;
}
image-20250308154357655