Hi,Team,
I'm currently using the nrf54l15-dk. I want to set the rtc of the nrf54l15-dk to obtain the timestamp. How should I configure the rtc? Which examples should I refer to?
My ncs version is v2.8.0.
Thanks.
Hi,Team,
I'm currently using the nrf54l15-dk. I want to set the rtc of the nrf54l15-dk to obtain the timestamp. How should I configure the rtc? Which examples should I refer to?
My ncs version is v2.8.0.
Thanks.
Hello,
The error shows that one variable you have declared or defined (grtc_channel), but you have not actually used it anywhere in your code. This is a common warning or error in C/C++ development, especially when using strict compiler flags.
To resolve this, ensure that you use the variable in your code, for example by passing it to a function. Otherwise, you have to remove this.
Can you please share your application folder?
Kazi Afroza Sultana The unused var won't cause build error.
The main reason is the header not exits.
I don't want talk more. just show your code which is a complete project.
It won't be difficult for your verder, but cost much time for us costumers.
Thanks.
Hello,
I understand that you don't want to talk more. That's why I asked you in my previous reply to share your application code so I can look at from my side and also can try to reproduce the issue on nRF54L15 DK.
You can look at this previous case (18) Nordic DevZone to understand my previous reply.
Besides this, I would like to explain a bit more about two functions k_cycle_get_32() and k_cycle_get_64() which are used to read the current value of the hardware clock (system timer) in zephyr. To set the GRTC for obtaining the timestamp these functions are needed. These return the number of hardware cycles since boot, which we can use as timestamp for relative timing or real time clock.
To obtain a timestamp on the nRF54L15-DK, you generally use the system timer or RTC (Real-Time Counter/Clock) functionality provided by the hardware and the Zephyr OS. On nRF54L15, the GRTC (General Real-Time Counter) is the relevant hardware peripheral.
#include <zephyr/kernel.h> uint32_t timestamp_32 = k_cycle_get_32(); uint64_t timestamp_64 = k_cycle_get_64();
These functions are defined to "read the hardware clock" and are available in Zephyr's kernel API. The value returned is in hardware cycles, not seconds or milliseconds, so you may need to convert it using your system's clock frequency if you need standard time units. For nRF54L15, the system clock frequency is typically derived from the LFCLK (often 32.768 kHz) or HFCLK, depending on configuration. You have to check your board and project setting for the accurate frequency.
For direct hardware control of the nRF54L15's real-time counter and clock output features, you need to use nrfy_grtc_clkout_set() function. This case (18) nRF54L15 clock output - Nordic Q&A - Nordic DevZone - Nordic DevZone has shown how to use it.
#include <haly/nrfy_grtc.h>
nrfy_grtc_clkout_set(NRF_GRTC, NRF_GRTC_CLKOUT_32K, true);
There is no specific RTC samples for nrf54L15, but you can look at Zephyr's timer and counter driver samples (zephyr/samples/drivers/counter/alarm, for general usage patterns.
So, based on all the directions mentioned above, you can modify your code and send me the project file. I will help accordingly.
Thanks.
BR
Kazi
Hi,
Currently, I still haven't been able to implement the function of using grtc as the real-time clock for the nrf54l15-dk. Could you please provide some reference engineering examples?
Thanks.
To set the time, you can save the difference between GRTC and the timestamp (epoch microseconds) in memory. To get the time, you add the same difference to the GRTC. If you save the difference in a retained memory region, it will survive soft reboots.
Hi
I can understand what you mean. But I don't know how to do it. Could you please provide an example of a code engineering project?
Thanks.
This is how to read the GRTC:
In prj.conf:
CONFIG_NRFX_GRTC=y
In your code:
#include <nrfx_grtc.h>
...
uint64_t syscounter;
int ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
...
}
As for retained memory, see zephyr/samples/boards/nordic/system_off for an example.
This is how to read the GRTC:
In prj.conf:
CONFIG_NRFX_GRTC=y
In your code:
#include <nrfx_grtc.h>
...
uint64_t syscounter;
int ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
...
}
As for retained memory, see zephyr/samples/boards/nordic/system_off for an example.
Hi,
Thank you very much for your reply.
Thank you very much for your reply.
Now I can use the nrfx_grtc_syscounter_get() function to obtain the value. The app will send 8 bytes to my device: 0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00. Converting these to 13-digit decimal gives 1756344736528. This represents a Unix millisecond-level timestamp format. Converting it again to UTC format results in 20-09-27 21:32:16.528.
The first time, nrfx_grtc_syscounter_get(&syscounter) was called, and syscounter = . A delay of 1 second was then applied. Subsequently, nrfx_grtc_syscounter_get(&syscounter) was called again, and syscounter = 1127894. Based on the difference you described, I should do this: 1756344736528 + 1127894 - 126117 = 1756335738305. Right? If I'm wrong, please let me know.
This is my simple test code:
unsigned char bytes[] = {0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00};
uint64_t timestamp = 0;
// 从小端序字节构建64位整数
for (int i = 0; i < 8; i++) {
timestamp |= (uint64_t)bytes[i] << (i * 8);
}
// 输出时间戳(13位十进制数字)
printf("\n");
printf("Timestamp1: %" PRIu64 "\n", timestamp);
uint64_t syscounter;
ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
LOG_ERR("get grtc err");
}
printf("Timestamp2: %" PRIu64 "\n", syscounter);
k_msleep(1000);
ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
LOG_ERR("get grtc err");
}
printf("Timestamp3: %" PRIu64 "\n", syscounter);
The log printed by the device is as follows:
Timestamp1: 1756344736528 Timestamp2: 126117 Timestamp3: 1127894
Thanks.
I suggest you do like this:
uint64_t offset = 0;
int set_time(uint64_t timestamp)
{
uint64_t syscounter;
int ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
return ret;
}
offset = timestamp - syscounter;
return 0;
}
int get_time(uint64_t *timestamp)
{
uint64_t syscounter;
int ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
return ret;
}
*timestamp = syscounter + offset;
return 0;
}
If you call set_time() with your initial timestamp, then k_msleep(1000), then get_time() should give the initial timestamp plus one second.
Hi,
Thank you for your reply.
As you said, calling k_msleep(1000) indeed adds 1 second.
But how can I achieve adding 1 second to the timestamp? As I mentioned:
"The app will send 8 bytes to my device: 0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00. Converting these to 13-digit decimal gives 1756344736528. This represents a Unix millisecond-level timestamp format. Converting it again to UTC format results in 20-09-27 21:32:16.528." Currently, I can only calculate the 13-digit decimal number: 1756344736528. If I add 1 second to 1756344736528, converting it to UTC results in 2025-09-27 19:02:18.305, and the time is incorrect.
Could you please tell me how to add 1 second to the value of 1756344736528 to achieve the addition of year, month, day, hour, minute, second, and millisecond?
Thanks.
The GRTC measures time in microseconds, not milliseconds. You need to convert between them.