nRF connect SDK v3.1.0 changes behavior of clock_gettime()

When updating from nRF connect SDK v3.0.1 to v3.1.0 we noticed a change in the clock_gettime() function.

In the old version, the clock was not reset by a reboot.

The new version does reset the clock when rebooting.

Here is a simple example:

main.c:

#include <stdio.h>

#include <zephyr/kernel.h>
#include <zephyr/posix/time.h>
#include <zephyr/sys/reboot.h>

void print_time(void)
{
struct timespec clock_now;
if (0 != clock_gettime(CLOCK_MONOTONIC, &clock_now))
{
return;
}
printk("Time: %u\n", (uint32_t)(clock_now.tv_sec));
}

int main(void)
{
printk("Hello World! %s\n", CONFIG_BOARD_TARGET);
print_time();
k_msleep(10000);
print_time();
sys_reboot(SYS_REBOOT_COLD);

return 0;
}
prj.conf:
CONFIG_DATE_TIME=y
CONFIG_DATE_TIME_NTP=n
CONFIG_DATE_TIME_AUTO_UPDATE=n
CONFIG_REBOOT=y
Output with v3.0.1:
Hello World! nrf54l15dk/nrf54l15/cpuapp
Time: 0
Time: 10
Hello World! nrf54l15dk/nrf54l15/cpuapp
Time: 10
Output with v3.1.0:
Hello World! nrf54l15dk/nrf54l15/cpuapp
Time: 0
Time: 10
Hello World! nrf54l15dk/nrf54l15/cpuapp
Time: 0
I'm not sure if this is a bug or a fix, as I could not found where the change was made.
However, we relied on the counter not being reset after a reboot.
Is there a way to restore the old behavior?
Best regards,
Raphael Lamp
Related