nRF52840 with Zephyr RTOS: How to use RTC with struct rtc_time?

Hello,
I have a custom board containing a module from Raytac with a Nordic nRF52840 microcontroller on it. The board also has a 32768kHz oscillator connected to the module to have a more accurate LFCLK. I am using VSCode with the nRF Connect SDK and the Zephyr RTOS and want to make use of Zephyrs RTC (https://docs.zephyrproject.org/latest/hardware/peripherals/rtc.html#overview) using the external oscillator to keep track of time, up to the level of months and years. I am not sure if in Zephyr it even is intended to use struct rtc_time.

Here (How to enable NRF52840 RTC using Zephyr? ) you recommend to use the kernel timer, but this is not suitable for the handling struct rtc_time.

I noticed that RTC0 still should be able to use by the user as its stated here:  Zephyr & RTC.  So I also want to use the RTC0.

I also came across https://devzone.nordicsemi.com/f/nordic-q-a/90810/how-to-rtc-with-nordic-and-zephyrbut it does not tell how to use it.

Also: I do not know if the description of the rtc in the device tree is correct. I simply enabled rtc0 in the device tree , resulting in the device tree node:

&rtc0 {
    status = "okay";
    prescaler = <4096>;
    wakeup-source;
};

Is the following define and code line the correct way to access the devicetree node and create a device?

#define RTC_TIMER DT_NODELABEL(rtc0)

const struct device *timer_dev = DEVICE_DT_GET(RTC_TIMER);

Kind regards,

Dominik

Related