keep variable after restart
keep variable after restart
There is a RTC_DATA_ATTR which can keep the variable after deepsleep wake up, is there any method to keep the variable after restart?
Re: keep variable after restart
Software restart? RTC_NOINIT_ATTR
Re: keep variable after restart
Hi WiFive,
Yes, not power restart,but just software restart or restart cause by system crash.
I have tried the following way, but it seems the value cannot be init to zero. It started with some value. I expected it start with 0 and then increment after each esp_restart(). Any example on how to use this ATTR?
Yes, not power restart,but just software restart or restart cause by system crash.
I have tried the following way, but it seems the value cannot be init to zero. It started with some value. I expected it start with 0 and then increment after each esp_restart(). Any example on how to use this ATTR?
Code: Select all
static RTC_NOINIT_ATTR int test=0;
void app_main(){
test++;
esp_restart();
}
Re: keep variable after restart
I found that the RTC_NOINIT_ATTR variable will be reset if it's wake up from deep sleep.
Re: keep variable after restart
You have to check reset reason and init to 0 yourself.
You have to make sure RTC_SLOW_MEM is powered during deepsleep.
You have to make sure RTC_SLOW_MEM is powered during deepsleep.
Re: keep variable after restart
yes, I did.
below is my simple code.
If I use part A, variable test will increment every 4 second.
However, if I comment out PART A, and use the esp_deep_sleep, the test variable become a strange value and won't increment. that means deep sleep wake up cleared the test variable?
below is my simple code.
If I use part A, variable test will increment every 4 second.
However, if I comment out PART A, and use the esp_deep_sleep, the test variable become a strange value and won't increment. that means deep sleep wake up cleared the test variable?
Code: Select all
static RTC_NOINIT_ATTR int test;
void app_main() {
esp_reset_reason_t reason = esp_reset_reason();
if ((reason != ESP_RST_DEEPSLEEP) && (reason != ESP_RST_SW)) {
test = 0;
}
test++;
printf("test %d",test);
/**********PART A*********/
delay_ms(4000)
esp_restart();
/****************************/
//esp_deep_sleep(1000000LL*4);
}
Re: keep variable after restart
The fact that RTC_NOINIT variable is lost after deep sleep is a bug, thank you for reporting this.
You can work around this by adding some RTC_DATA variable into your program or by calling esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON); before entering deep sleep.
You can work around this by adding some RTC_DATA variable into your program or by calling esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON); before entering deep sleep.
Re: keep variable after restart
Hi Ivan,
it seems RTC_DATA_ATTR will lose after software reset.
In fact, I am working on this to resolve the problem of wifi turn on/off and then RTC IO case deep sleep current increase which I raised in github issue, is there any update on this issue?
it seems RTC_DATA_ATTR will lose after software reset.
In fact, I am working on this to resolve the problem of wifi turn on/off and then RTC IO case deep sleep current increase which I raised in github issue, is there any update on this issue?
Re: keep variable after restart
What I meant was to use RTC_NOINIT_ATTR for your variable, and then force RTC_SLOW_MEM to be powered on in deep sleep — currently this does not happen automatically (which is a bug) hence RTC_NOINIT variables are getting lost.
Regarding wifi/RTC IOs, will follow up on GitHub.
Regarding wifi/RTC IOs, will follow up on GitHub.
Re: keep variable after restart
i see,, thx ivan
Who is online
Users browsing this forum: No registered users and 81 guests