Configuring RTC with Zephyr device tree approach

I need to develop the code for RTC configuration without using nrf_drv_rtc_* , hence  I started using zephyr  device tree approach . Below is my code .

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/counter.h>
#include <zephyr/logging/log.h>
#include <zephyr/device.h>
#include <zephyr/drivers/rtc.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/sys/util.h>

LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); // Register a module for your logs

const struct device *int_rtc_dev;

void set_next_alarm(const struct device *rtc_dev) {
struct rtc_time current_time;
rtc_get_time(rtc_dev, &current_time); // Get current RTC time

// Increment the time by 10 minutes
current_time.tm_min += 10;
if (current_time.tm_min >= 60) {
current_time.tm_min -= 60;
current_time.tm_hour += 1;
if (current_time.tm_hour >= 24) {
current_time.tm_hour -= 24; // Wrap around hours
}
}

// Define mask for minutes and hours
uint16_t mask = RTC_ALARM_TIME_MASK_HOUR | RTC_ALARM_TIME_MASK_MINUTE;

// Set the alarm time
if (rtc_alarm_set_time(rtc_dev, 0, mask, &current_time) < 0) {
LOG_ERR("Failed to set RTC alarm time");
}
}

void alarm_callback(const struct device *dev, uint16_t id, void *user_data) {
LOG_INF("Alarm triggered! Setting next alarm...");
set_next_alarm(dev);
}

void Internal_rtc_init(void) {
int_rtc_dev = DEVICE_DT_GET(DT_NODELABEL(rtc0)); // Use rtc1 if needed

if (!device_is_ready(int_rtc_dev)) {
LOG_ERR("RTC device not ready\n");
return;
}

// Set up the callback for the first alarm
rtc_alarm_set_callback(int_rtc_dev, 0, alarm_callback, NULL);

// Set the initial alarm
set_next_alarm(int_rtc_dev);

LOG_INF("RTC initialized");
}

Below is my proj.conf , Kconfig setting 

CONFIG_RTC=y
CONFIG_NRFX_RTC0=y # Enable RTC0
CONFIG_NRFX_RTC1=y # Disable RTC1
CONFIG_NRFX_CLOCK=y # Enables the necessary clocks for RTC operation
CONFIG_COUNTER=y

# Set the logging level to Debug
CONFIG_LOG_DEFAULT_LEVEL=2
# Enable RTT and logging
CONFIG_CONSOLE=y
CONFIG_LOG=y

While compiling I have linking issues

c:/zephyr_codebase/zephyr_prj/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `rtc_alarm_set_time':

C:/SP_GENE_FIRMWARE/SP_GenE_Zephyr/Internal_RTC/SP_GENE/build/zephyr/include/generated/zephyr/syscalls/rtc.h:111: undefined reference to `z_impl_rtc_alarm_set_time'

c:/zephyr_codebase/zephyr_prj/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `rtc_alarm_set_callback':

C:/SP_GENE_FIRMWARE/SP_GenE_Zephyr/Internal_RTC/SP_GENE/build/zephyr/include/generated/zephyr/syscalls/rtc.h:187: undefined reference to `z_impl_rtc_alarm_set_callback'

collect2.exe: error: ld returned 1 exit status

 

what is missing in the configuration, why there issue in linking?

Parents Reply Children
No Data
Related