Running RTC0 on nrf9151-DK using zephyr drivers libraries

Hello everybody,

                         I am trying to get the RTC0 peripheral working on Nordic nrf9151-DK. I wanna use zephyr/driver_rtc.h library and zephyr/device.h librrary. I am able to use DEVICE_DT_GET with rtc0, but if I use another function working with device, like device_is_ready(), it makes error. The given device (rtc0) is not known to the compiler.

The main.c looks like this:

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/rtc.h>

#include <nrfx_rtc.h>
#include <nrfx_clock.h>
#include <hal/nrf_rtc.h>

bool pripravenost=false;
int navratova=0;
struct rtc_time time;

 
int main(void)
{
        const struct device *muj_rtc = DEVICE_DT_GET(DT_NODELABEL(rtc0));
        pripravenost=device_is_ready(muj_rtc);
        if(pripravenost==true)
        {
           printk("Jsem ready\n");
        }
        else
        {
           printk("Nejsem ready\n");
        }

        while(1)
        {

               
        }
        return 0;
}

My prj.conf looks like this:

# Povolení konzole
CONFIG_CONSOLE=y

# Povolení standardního výstupu (např. printf)
CONFIG_PRINTK=y

CONFIG_RTC=y
CONFIG_CLOCK_CONTROL=y
CONFIG_CLOCK_CONTROL_NRF=y
CONFIG_NRFX_CLOCK=y
#CONFIG_NRFX_RTC=y
CONFIG_NRFX_RTC0=y
#CONFIG_NRFX_RTC1=y

CONFIG_MAIN_STACK_SIZE=2048
CONFIG_RTC_ALARM=y
CONFIG_RTC_UPDATE=y

nrf9151_dk_nrf9151_defconfig looks like this:

# SPDX-License-Identifier: Apache-2.0

# Enable MPU
CONFIG_ARM_MPU=y

# Enable hardware stack protection
CONFIG_HW_STACK_PROTECTION=y

# Enable TrustZone-M
CONFIG_ARM_TRUSTZONE_M=y

# Enable GPIO
CONFIG_GPIO=y

# Enable UART driver
CONFIG_SERIAL=y

# Enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
#CONFIG_RTC=y
CONFIG_CLOCK_CONTROL=y
CONFIG_CLOCK_CONTROL_NRF=y
CONFIG_NRFX_CLOCK=y
#CONFIG_NRFX_RTC=y
CONFIG_NRFX_RTC0=y
#CONFIG_NRFX_RTC1=y

nrf9151dk_nrf9151_ns.overlay looks like this:

/*
 * Copyright (c) 2024 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

&rtc0
{
	status="okay";
};
&clock {
    status = "okay";
};
&systick {
	zephyr,deferred-init;
};

nrf9151dk_9151_ns.dts looks like this:

/*
 * Copyright (c) 2023 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <nordic/nrf9151_laca.dtsi>
#include "nrf9151dk_nrf9151_common.dtsi"

/ {
	chosen {
		zephyr,sram = &sram0_s;
		zephyr,flash = &flash0;
		zephyr,code-partition = &slot0_partition;
		zephyr,sram-secure-partition = &sram0_s;
		zephyr,sram-non-secure-partition = &sram0_ns;
	};
};
&rtc0
{
	status="okay";
};
&clock {
    status = "okay";
};
&systick {
	zephyr,deferred-init;
};

Build configuration looks like this:

Kind regards

Jaroslav Havel

Related