RTC
Last updated
Last updated
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:
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.
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:
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:
Modify the Kconfig in the driver path:
Enable the kernel:
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.
date
and hwclock
The following test steps are applicable to all systems. Step 6 is the most critical test.
Display the current Linux system time
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.
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)
Display the hardware RTC time
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.
Set the Linux system time to the hardware RTC
Check again whether the hardware RTC time is consistent with the system time
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.
Power off the device, wait for a few minutes, then power it on again and enter:
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.
Clear and restore
Set the time
+60: indicates that the interrupt will be triggered after 60 seconds
View RTC information
View system interrupt information:
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: