Hello Team,
I am using nrf54l15 dk for the development. In this, I am using k_sleep to put the device in system-on sleep mode. Using this, I have achieved the sleep current of 4 micro Amps with all RAM enabled. But I have a use case where I want to periodically wake the device from sleep mode. To wake up the device periodically, I configured the RTC by referring to the "Counter RTC Driver Sample" sample code from NCS v2.9.0, which provides an example of an alarm application. It sets an alarm with the desired time and sets a wake-up flag at alarm expiry. This is working as expected, but after configuring RTC sleep current is drastically increased from 4 micro Amps to 149 micro Amps, to reduce the sleep current, I tried to disable the RTC before putting the device in sleep mode, by disabling the RTC current is reduced to 4 micro Amps but here device will not wake up in a sleep mode. Below is the code snippet for the same.
int init_rtc(void) { //const struct device *const counter_dev = DEVICE_DT_GET(TIMER); int err; printf("Counter alarm sample\n\n"); if (!device_is_ready(RTC)) { printf("device not ready.\n"); return 0; } counter_start(RTC); alarm_cfg.flags = 0; alarm_cfg.ticks = counter_us_to_ticks(RTC, DELAY); alarm_cfg.callback = test_counter_interrupt_fn; alarm_cfg.user_data = &alarm_cfg; err = counter_set_channel_alarm(RTC, ALARM_CHANNEL_ID, &alarm_cfg); printf("Set alarm in %u sec (%u ticks)\n", (uint32_t)(counter_ticks_to_us(RTC, alarm_cfg.ticks) / USEC_PER_SEC), alarm_cfg.ticks); if (-EINVAL == err) { printf("Alarm settings invalid\n"); } else if (-ENOTSUP == err) { printf("Alarm setting request not supported\n"); } else if (err != 0) { printf("Error\n"); } } static void test_counter_interrupt_fn(const struct device *counter_dev, uint8_t chan_id, uint32_t ticks, void *user_data) { timer_wakeup = 1; err = counter_set_channel_alarm(counter_dev, ALARM_CHANNEL_ID, user_data); if (err != 0) { printf("Alarm could not be set\n"); } }
I am continuously checking the value of timer_wakeup, if it is 1, the device will wake up.
void execute_sleep_app(void) { if(sleep_flag) { pm_device_action_run(UART0, PM_DEVICE_ACTION_SUSPEND); pm_device_action_run(UART1, PM_DEVICE_ACTION_SUSPEND); pm_device_action_run(RTC, PM_DEVICE_ACTION_SUSPEND); while(1) { k_sleep(K_SECONDS(30)); if(get_timer_wakeup_flag()) { break; } } if(get_timer_wakeup_flag()) { pm_device_action_run(UART0, PM_DEVICE_ACTION_RESUME); pm_device_action_run(UART1, PM_DEVICE_ACTION_RESUME); pm_device_action_run(RTC, PM_DEVICE_ACTION_RESUME); set_timer_wakeup_flag(0); set_sleep_flag(0); //notify_wakeup(APP_BC65); notify_wakeup(APP_METER); } } }
Can you please help to configure the RTC with a reduced sleep current?
Along with this I came to know about GRTC but couldn't find the sample code for it.
The end goal is to wake up the device from sleep periodically. Could you help us with this query?
Thank you,
Payal