Article Directory
1 View RTC time
First, when the Linux system starts, we can see the system clock device information, as shown in Figure 1.1:
The Linux kernel sets snvs_rtc to rtc0 when booting. Different boards may have different boot information. The basic functions are the same.
Use the "date" command to view the time under the Linux system, as shown in Figure 1.2:
The above figure shows that the current time is 1970-01-01 00:06:11. Obviously, the time is wrong. You need to reset the time.
2 Set RTC time
The RTC time setting also uses the "date" command. Use the "date --help" command to view some usage methods of this command, as shown in the following figure:
If we want to set the current time to 13:25:00 on February 28th, 2020, enter the following command: After the
date -s "2020-02-28 13:25:00"
setting is completed, use the "date" command to view it again and find that the time will change. As shown in Figure 2.2:
But pay attention to a file. If you only use the "date" command to modify the time, if you restart the development board to check the time again and find that the time has changed back to 1970, it is because using the "date" command to modify the time only modifies the current system time. Write the time into the RTC device, so the system restart time is lost.
Use the "hwclock" command to write the current time to the RTC device. The command is as follows:
hwclock -w //Write the current system time to the RTC.
Write the time to the RTC device. The system will read from the RTC every time the system is turned on. Read the time in the device so that the time will not be lost. You can try it.