I am using nrf52832, and I want to use SYSTEM ON Sleep.
Also , my wake up sourses are timer based, and also GPIO interrupt based.
But I observed that the device cannot go to sleep for more than approximately 4 minutes.
Code:
I am using nrf52832, and I want to use SYSTEM ON Sleep.
Also , my wake up sourses are timer based, and also GPIO interrupt based.
But I observed that the device cannot go to sleep for more than approximately 4 minutes.
Code:
Hi,
the RTC rolls over at 512 seconds (24^2 * 1/32768), but the kernel timer driver wraps around at half of it, to avoid a corner case:
https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/timer/nrf_rtc_timer.c#L690-L694
255 seconds = 4.25 minutes, which is similar to what you're observing.
"WFI" waits for any interrupt and wakes up. In a RTOS, these can be internal to the OS, so I would recommend that you use k_cpu_idle() (https://docs.zephyrproject.org/latest/doxygen/html/group__cpu__idle__apis.html) instead.
Kind regards,
Håkon
Hello Hakon,
Thankyou for the response.
I tried to use k_cpu_idle() instead of WFI . But the same behaviour is seen.
After 4.5 minutes the device woke up again just like WFI.
I tried another configuration as well :
in prj.conf file:
Then, I tried to print the values of the ticks using this method, so i can spot the overflow at 4.5 minutes.
But it seemed to work fine here.
Hi,
Dinna said:Also please let me know if there is a way to know what interrupt was received from WFI.
There is no specific register to read. You need to check if your wanted condition (ie. your interrupt) has occurred.
Dinna said:Then, I tried to print the values of the ticks using this method, so i can spot the overflow at 4.5 minutes.
But it seemed to work fine here.
The driver handles the overflow, but the nRF will generate a wake up condition.
k_cpu_idle is a wrapper for __WFI(), while k_sleep() is a sleep function with a specific timeout parameter.
Kind regards,
Håkon
Hello,
You need to check if your wanted condition (ie. your interrupt) has occurred.
This is where the issue is, the device wakes up before the actual interrupt should occur, i.e., exactly 5 minutes or exactly 10 minutes.
The device wakes up before these conditions are met.
Do you have any suggestions on how to use SYSTEM ON sleep, with wake up on both timer expiry and GPIO interrupt generation.
Hi,
Dinna said:
Do you have any suggestions on how to use SYSTEM ON sleep, with wake up on both timer expiry and GPIO interrupt generation.
Check out the zephyr/samples/basic/button sample.
Try to combine this with a k_timer instance:
Kind regards,
Håkon
Hello,
Yes, As you suggested, I tried to use k_timer related functions alone, and the _WFI related issues are not seen anymore.
But, earlier, my device was running on 3uA during sleep(in _WFI).
But after making these changes, the device is taking 6.2uA in sleep. Which is not acceptable, as this is a low power device.
Hello,
Yes, As you suggested, I tried to use k_timer related functions alone, and the _WFI related issues are not seen anymore.
But, earlier, my device was running on 3uA during sleep(in _WFI).
But after making these changes, the device is taking 6.2uA in sleep. Which is not acceptable, as this is a low power device.
Please look at the samples that I shared with you for an event/ISR based approach.
The reason why you are seeing a higher consumption is because you are polling every 100 ms:
k_msleep(100);
Kind regards,
Håkon
You might find this code useful on ascertaining pending interrupts: how-do-i-read-the-event-register