meshtastic / firmware

Meshtastic device firmware
https://meshtastic.org
GNU General Public License v3.0
3k stars 719 forks source link

[Feature Request]: Implement RTC awake from deep sleep for NRF52 #2822

Open andrekir opened 9 months ago

andrekir commented 9 months ago

Platform

NRF52

Description

right now we're only using low-level sd_power_system_off() for deep sleep and it's not using the msecToWake parameter (ie. to wake up after N seconds).

RAK suggests ~using FreeRTOS~

if this is something that could be implemented it would allow, for example, SENSORS running for very long periods (months?) without a charge.

jp-bennett commented 9 months ago

If I understand it, this would mean converting our entire codebase away from using the Arduino threads concurrency library, to using full RTOS, which is very involved.

andrekir commented 9 months ago

got it, thanks. so the FreeRTOS method is not viable.

right now we're only using low-level NRF_POWER->SYSTEMOFF = 1; for deep sleep and it's not using the msecToWake parameter (ie. to wake up after N seconds).

the other examples I found require an RTC to generate an interrupt and not sure our RTC lib supports that.

jp-bennett commented 9 months ago

Would we do nearly as well, to just power everything down, like the lora chip, GPS, BLE, and LEDs, and then do a long delay() call?

andrekir commented 9 months ago

that's a great idea. perhaps we can get into sub-mA power draw using these NRF power states:

sd_power_mode_set(NRF_POWER_MODE_LOWPWR) // low power
delay(secToWake)
sd_power_mode_set(NRF_POWER_MODE_CONSTLAT) // default

~also, this might need to go into NRF52 Light Sleep logic (for TRACKERs and SENSORs).~

andrekir commented 9 months ago

for simplicity sake, going for RTC awake on this request, then open a separate one for low-power states for TRACKER/SENSOR roles.

current RTC libs: PCF8563 & Melopero_RV-3028.

PCF8563 example: https://github.com/Xinyuan-LilyGO/T-Echo/blob/main/examples/Sleep/Sleep.ino