This guide shows how to set up a real-time clock (RTC) in embedded systems with the ROCK 4 SE to allow real-time monitoring with no main power or connection to the internet.
Learn how to set up the real-time clock (RTC) on the ROCK 4 SE in just 10 steps and learn how to use a Serial-to-USB cable to access the console for both boards. The officially supported operating systems, Debian Bullseye (Desktop) and Ubuntu Server (Headless), both support these features.
The ROCK 4 SE and ROCK 4C+ single board computers come with a built-in Real Time Clock (RTC) function as standard, which, when set up, can keep accurate time even when not connected to a network time service. They also have a Serial UART attached to the GPIO header for Serial Console access to the operating system for monitoring and debugging.
Note: The ROCK 4C+ does not have the RTC battery connector fitted, but it does have the Serial UART connected to the GPIO header.
A real-time clock (RTC) is used in embedded systems to keep track of the precise time and date even when the device is not connected to the network or the main power is off. The RTC is powered by its own internal lithium battery, and even if the power of the system is turned off, the RTC clock keeps running.
The RTC is widely used in various applications, including industrial manufacturing, commercial machines maintenance, healthcare machines management, agriculture installations, and many more. The ROCK board, with its RTC capability, can be integrated into any electronic device where real-time monitoring is required.
Some applications of the RTC include:
So, let’s discover how to set up the RTC on the ROCK 4 SE and start tracking time!
Most desktop and laptop PCs have a battery-backed RTC built into the motherboard, but many SBCs do not. The ROCK 4 SE & ROCK 4C+ both have RTC functions supported by the PMIC, but only the ROCK 4 SE has an RTC battery connector located on the underside of the board. It requires a battery (not supplied) of the type as shown below:
Tip: RTC batteries are widely available – make sure yours has a connector with the correct polarity.
Ensure the ROCK 4 SE is powered off before connecting the battery to the battery connector terminal.
Ground (Black lead) is nearest to the USB-C socket (Top Left), and Positive (Red lead) is nearest to the HDMI connector (Top Right), as viewed from the underside of the board below:
Set up your operating system for the ROCK 4 SE with either Debian Bullseye or Ubuntu Server. There are separate Getting Started instructions on how to do this here:
To obtain an accurate time setting, the ROCK 4 SE needs to be connected to the internet using either Ethernet or WiFi. Once the RTC has been set up, networking can be disconnected, and the time will be kept from the RTC.
Set up the time zone. A list of available timezones can be displayed by running the following command in the Terminal:
This example shows setting the timezone to London, UK time zone. The system automatically knows that it is currently in British Summer Time (BST).
Tip: Use TAB completion by typing the first few letters of the timezone, then press the TAB key.
sudo timedatectl set-timezone Europe/London
View the clock settings with the timedatectl command:
When the system starts up, the system clock may not have synchronised – System clock synchronised: no.
Wait until the System clock has synchronised. This can take five minutes or more. Keep refreshing timedatectl until System clock synchronised is marked yes.
After the system clock has synchronised, run the following command to write the system clock time to the hardware clock:
Now, if you run timedatectl again, you should find that the Universal time (UTC) and RTC time are synchronised. It is recommended to run the RTC in UTC time, i.e. with RTC in Local TZ: no.
If you power off and disconnect networking, you can now run the system without being connected to a network, and the system will keep accurate time from the hardware clock.
Both the ROCK 4 SE and ROCK 4C+ have a Serial UART connected to the GPIO header, so you can attach the board to a host PC using a USB-to-Serial cable and Serial Console application. This allows access to the boot sequence and kernel ring buffer output as the board boots up for monitoring and debugging, and once the system has booted, you can log in to the shell from the console.
If you are running Ubuntu Server as a headless device, this is especially useful for accessing the system before SSH access is established. More advanced use enables the whole boot sequence to be monitored and interrupted for debugging purposes, even before the OS initialises.
There are many USB-to-Serial cables available on the market. The ROCK board’s UART operates at a data rate of 1.5Mbps, so the cable must be able to support this. 3.3V cables based on the FTDI FT232R USB to Serial UART are suitable, for example, this one.
Warning: Some USB-to-Serial cables operate at 5.0V – DO NOT USE these as they will damage your board.
The ROCK’s serial console is exported on UART2 by default, which is connected to the following pins on the GPIO header. With the board powered off, connect the cable as shown below:
|ROCK GPIO Pin
Tip: Tape the Red power terminal (5.0V) on the cable safely away so that it cannot accidentally touch any of the GPIO pins, as this will damage your board.
Several Serial Terminal applications are available that run on the host PC. We used Minicom on a Debian Linux host.
Install Minicom with:
sudo apt install minicom
To run Minicom without root privileges, make sure that your user is in the dialout group:
If not, run the following command to add your user to the dialout group, then log out and back in again:
sudo usermod -aG dialout $USER
With the USB-to-serial cable plugged into your host, check which serial device it is attached to:
In our case, the device is on ttyUSB0.
Create a minicom configuration file in your home directory named .minirc.rock (note the preceding dot) with the following contents:
pu port /dev/ttyUSB0
pu baudrate 1500000
pu bits 8
pu parity N
pu stopbits 1
pu rtscts No
Now start minicom in a Terminal on the host with:
You should see output similar to the below:
Tip: Hardware flow control “rtscts” must be set to “no” to allow keyboard input.
Now, power on the ROCK. The U-boot messages will stream through the console, then Linux will initialise, and the kernel boot messages will appear, ending with a login prompt.
When the OS has finished booting, you may have to press “enter” to make the login prompt appear.
At the prompt, log in with username rock, and then you can run bash commands in the shell. There may be times when keyboard input is interrupted by kernel messages, so just press “enter” to return to the prompt and repeat the command.
Tip: Debian and Ubuntu’s default username is rock with password rock – we advise changing this to a more secure password.
This guide showed how to set up and configure the RTC so that your ROCK 4 SE board can keep accurate time even when it is not connected to the internet or a network with time services.
This is necessary for stand-alone projects that use time and date information. It is also important for some cloud services that use access tokens which contain time stamps which must be set correctly.
For users who want to get under the bonnet of Linux on the ROCK 4 SE or ROCK 4C+, we also showed how to use a USB-to-Serial cable to access the ROCK’s serial console. This gives access to the boot sequence and kernel messages. It also provides a way to log into the OS from a host PC without having a monitor attached to the ROCK or when SSH access is not possible.
Ready to ROCK your next project? Browse our ROCK Shop to find out the range of incredible ROCK single-board computers – the perfect Raspberry Pi alternative, compute modules and accessories. Be one of the first to know:
Do you want to know more about ROCK and how we, here at OKdo, can help solve your problem? Talk to us, get in touch with our Sales team to find the perfect solution.
Please select an option to see content specific to your location and shop online.