Description
I've been thinking about how to support super-low power states in TinyGo, and I think there are two interesting cases:
- CPU core and peripherals powered off, but RAM still powered
- CPU core, peripherals and RAM powered off
Various chips (I'm most aware of the STM32 line) support entering sleep states like these, being woken on specific GPIO pins, RTC alarms, and similar. In order to support these low-power states, it would be super-cool to have ways to persist data. A beneficial side-effect is that it would also enable some persistence across reset (and potentially flashing).
Example use-cases:
- Battery-powered sensing device that wakes every minute (RTC alarm) to collect a sample, save to RAM, then returns to low-power state. Once per day it powers up wifi to deliver the samples collected.
- Logging device that wants to ensure samples are not lost on a crash / watchdog event by holding samples in RAM until they can be delivered.
- Configuration settings - allow users to configure a device and persist those settings to flash so they survive power-out and reset
I've put a prototype implementation for RAM persistence here: #1715
I've tried to put fairly details docs in the package runtime/persistence: https://github.com/tinygo-org/tinygo/blob/537ef22f7365bdc7d3e04b03dc943262f43730fe/src/runtime/persistence/persistence.go