Running RTC0 on nrf9151-DK using nrf (Nordic) libraries

Hello everybody,

                        I am trying to get the RTC0 peripheral working on Nordic nrf9151-DK using libraries from Nordic (nrfx_rtc.h, nrfx_clock.h and hal/nrf_rtc.h). I am not able to run rtc_handler using IRQ. Could you please help me with getting RTC0 up and running?

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;

int pocitadlo=0;


struct rtc_time time;
static const nrfx_rtc_t rtc0=NRFX_RTC_INSTANCE(0);

void rtc_handler(nrfx_rtc_int_type_t int_type)
{
    if (int_type == NRFX_RTC_INT_TICK) 
    {
        printk("RTC tick\n");
    }
    pocitadlo=pocitadlo+1;
    if(pocitadlo==10000)
    {
        pocitadlo=0;
        printk("Hoja hoj\n");
    }
    
}
 
int main(void)
{
       
       
        if (!nrfx_clock_lfclk_is_running()) 
        {
        nrfx_clock_enable();
        nrfx_clock_lfclk_start();
        printk("Povoleno + start\n");
         while (!nrfx_clock_lfclk_is_running()) 
          {
            /* čekej na start */
          }
        }
        printk("Hodiny jedou\n");
        nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG;
        config.prescaler = NRF_RTC_FREQ_TO_PRESCALER(10);
        config.tick_latency = NRFX_RTC_US_TO_TICKS(1000, 32768),
        config.reliable=true;
        nrfx_err_t err = nrfx_rtc_init(&rtc0, &config, rtc_handler);
        if (err != NRFX_SUCCESS) 
        {
           printk("RTC init error: %d\n", err);
       
        }
        else
        {
             printk("RTC slape\n");   
        }

        // Povol tick interrupt
        nrfx_rtc_tick_enable(&rtc0, true);

        // Start RTC
        nrfx_rtc_enable(&rtc0);
        //IRQ_CONNECT(RTC0_IRQn, 1, rtc_handler, NULL, 0);
        //irq_enable(RTC0_IRQn);
        while(1)
        {
                uint32_t ticks;
                ticks=nrfx_rtc_counter_get(&rtc0);
                k_msleep(1000); // zpomal pro debug
                printk("RTC hodnota: %d\n",ticks); 
               
        }
        return 0;
}

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

nrf9151dk_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_nrf9151.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;
};

My build configuration:

Could I use IRQ_CONNECT and irg_enable?

Kind regards

Jaroslav Havel

Parents Reply
  • Hi Jaroslav,

    Jaroslav Havel said:
    But i think, I don't have to use IRQ_CONNECT, because I am using nrfx_rtc_tick_enable() funkction. Compilator said, that I am doing the same thing if I am using IRQ_CONNECT and nrfx_rtc_tick_enable().

    That sounds wrong. What did the compiler tell you?

    Jaroslav Havel said:
    If I run code, I am not able to see anything inside while(1) loop. Could be some problem with internal fault that blocked all code?

    What is the full log?

    Best regards,

    Hieu

Children
No Data
Related