]> granicus.if.org Git - esp-idf/commitdiff
deep sleep: keep RTC_SLOW_MEM powered on if data is placed into RTC slow memory
authorIvan Grokhotkov <igrokhotkov@gmail.com>
Wed, 11 Jan 2017 09:23:23 +0000 (17:23 +0800)
committerIvan Grokhotkov <igrokhotkov@gmail.com>
Thu, 12 Jan 2017 06:15:30 +0000 (14:15 +0800)
components/esp32/deep_sleep.c
components/esp32/include/esp_attr.h
components/esp32/ld/esp32.common.ld
docs/api/deep_sleep.rst

index 774fd4ce7afdc3fea93685e555130b6235f3ec1a..3eef7ca29d0fce327cd0495d290bf07715a7245e 100644 (file)
@@ -302,12 +302,18 @@ static uint32_t get_power_down_flags()
 {
     // Where needed, convert AUTO options to ON. Later interpret AUTO as OFF.
 
-    // RTC_SLOW_MEM is needed only for the ULP.
-    // If RTC_SLOW_MEM is Auto, and ULP wakeup isn't enabled, power down RTC_SLOW_MEM.
-    if (s_config.pd_options[ESP_PD_DOMAIN_RTC_SLOW_MEM] == ESP_PD_OPTION_AUTO) {
-        if (s_config.wakeup_triggers & RTC_SAR_TRIG_EN) {
-            s_config.pd_options[ESP_PD_DOMAIN_RTC_SLOW_MEM] = ESP_PD_OPTION_ON;
-        }
+    // RTC_SLOW_MEM is needed for the ULP, so keep RTC_SLOW_MEM powered up if ULP
+    // is used and RTC_SLOW_MEM is Auto.
+    // If there is any data placed into .rtc.data or .rtc.bss segments, and
+    // RTC_SLOW_MEM is Auto, keep it powered up as well.
+
+    // These labels are defined in the linker script:
+    extern int _rtc_data_start, _rtc_data_end, _rtc_bss_start, _rtc_bss_end;
+
+    if (s_config.pd_options[ESP_PD_DOMAIN_RTC_SLOW_MEM] == ESP_PD_OPTION_AUTO ||
+            &_rtc_data_end > &_rtc_data_start ||
+            &_rtc_bss_end > &_rtc_bss_start) {
+        s_config.pd_options[ESP_PD_DOMAIN_RTC_SLOW_MEM] = ESP_PD_OPTION_ON;
     }
 
     // RTC_FAST_MEM is needed for deep sleep stub.
index 7ef2920d989225b1aaded699f5f28cca0e406c74..911201aace40cce8359581a84363df8c1d38266e 100644 (file)
@@ -26,7 +26,7 @@
 // Forces data into DRAM instead of flash
 #define DRAM_ATTR __attribute__((section(".dram1")))
 
-// Forces a string into DRAM instrad of flash
+// Forces a string into DRAM instead of flash
 // Use as ets_printf(DRAM_STR("Hello world!\n"));
 #define DRAM_STR(str) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;}))
 
index 833eb9096921c81c5d790b0dc0094e890b823f84..8cc3b5b22e42969b9e8cf3198cd44fbc30a3567e 100644 (file)
@@ -19,9 +19,11 @@ SECTIONS
   */
   .rtc.data :
   {
+    _rtc_data_start = ABSOLUTE(.);
     *(.rtc.data)
     *(.rtc.rodata)
     *rtc_wake_stub*.o(.data .rodata .data.* .rodata.* .bss .bss.*)
+    _rtc_data_end = ABSOLUTE(.);
   } > rtc_slow_seg
 
   /* RTC bss, from any source file named rtc_wake_stub*.c */
index 3a458fb4a8276f7d073d214d06c43e1573e97e39..9e6642fd907c7f7bc8187dbd6f0c35fd5be3195b 100644 (file)
@@ -73,6 +73,8 @@ By default, ``esp_deep_sleep_start`` function will power down all RTC power doma
 
 Note: on the first revision of the ESP32, RTC fast memory will always be kept enabled in deep sleep, so that the deep sleep stub can run after reset. This can be overriden, if the application doesn't need clean reset behaviour after deep sleep.
 
+If some variables in the program are placed into RTC slow memory (for example, using ``RTC_DATA_ATTR`` attribute), RTC slow memory will be kept powered on by default. This can be overriden using ``esp_deep_sleep_pd_config`` function, if desired.
+
 .. doxygenfunction:: esp_deep_sleep_pd_config
 .. doxygenenum:: esp_deep_sleep_pd_domain_t
 .. doxygenenum:: esp_deep_sleep_pd_option_t