Closed blinry closed 7 months ago
To add context, I'm trying to find out why my program doesn't keep variables in the RTC RAM during deep sleep. I'm declaring them like this:
#[link_section = ".rtc.data"]
static mut COUNTER: u32 = 0;
But changes to it are not visible after a deep sleep. I figured the above "harder-than-expected-reboot" could be related?
entry 0x4008064c
0x4008064c - __user_exception
esp-flash tried to resolve hex values which look like an address and in this case, it resolved the entry point logged by the bootloader as the symbol __user_exception
. Not really something to worry about
As for the RTC data: We have a macro ram
which should place data into RTC RAM, e.g. https://github.com/esp-rs/esp-hal/blob/c4486800548aaacec26883a6f4491ad6860388ab/esp32-hal/examples/ram.rs#L23-L30
Thanks, those macros seem really helpful!
Persisting these variables through a deep sleep doesn't seem to work for me, though. I made a minimal project to reproduce this: https://github.com/blinry/esp32-deep-sleep-rtc-test
It contains all three variants:
#[ram(rtc_fast)]
static mut RTC_FAST_DATA: u32 = 42;
#[ram(rtc_fast, uninitialized)]
static mut RTC_FAST_NOINIT: u32 = 42;
#[ram(rtc_fast, zeroed)]
static mut RTC_FAST_BSS: u32 = 42;
When I run it (both on an Adafruit ESP32 Feather v2, as well as another random ESP32-WROOM-32 devboard), it shows values like these on the first run:
Value of RTC_FAST_DATA: 42
Value of RTC_FAST_NOINIT: 1644341610
Value of RTC_FAST_BSS: 0
Which is what I'd expect. The code then increments all three variables.
When the deep sleep ends, I get the the above output about __user_exception
and _ESP_HAL_DEVICE_PERIPHERALS
; the chip seems to reboot. Then, I get outputs like these:
Value of RTC_FAST_DATA: 2914262833
Value of RTC_FAST_NOINIT: 1644210282
Value of RTC_FAST_BSS: 0
So none of the values is persisted. Do you have an idea why?
sleep_deep
will power down RTC memory during sleep.
You can do something like this
let mut cfg = RtcSleepConfig::deep();
cfg.set_rtc_fastmem_pd_en(false);
cfg.set_rtc_slowmem_pd_en(false);
let timer = TimerWakeupSource::new(Duration::from_secs(3));
rtc.sleep(&cfg, &[&timer], &mut delay);
loop {}
instead to prevent RTC memory from getting powered down
Whoa, that's the solution! Thank you! I updated my minimal project.
Maybe something like this should be an additional example in the examples directory? I wasn't able to figure this out on my own.
@blinry Would you mind PRing an example? Totally okay if not, but like you said it would be helpful for others :).
I think this is solved now. @blinry it would still be really nice to have an example in esp-hal itself, if you find some free time :).
I'm developing for an "Adafruit ESP32 Feather v2", and tried the esp-template with its default settings.
When I run
cargo run
, the output looks like this:The program seems to work fine, but is the
__user_exception
an error, or something to be expected? (When I go into deep sleep, it happens for every wakeup.)What could I do to help you debug this further? Also let me know if I should file this issue in another project. Thanks! :)