Skip to content

light_sleep in v3.0-dev has several issues #908

Closed
@tferrin

Description

@tferrin

Hardware:

Board: Adafruit Huzzah32
Core Installation/update date: 6/dec/2017 (v3.0-dev-1325-ge5b2c1cf)
IDE name: Arduino IDE 1.8.5
Flash Frequency: 80MHz
Upload Speed: 115200

Description:

There are several problems with the current implementation of light_sleep. Since these are all related I'm including them together in one ticket.

Synopsis:

  1. A timer-based light_sleep sometimes never wakes up. The WDT appears to never trigger and the call to esp_light_sleep_start() never returns.
  2. The millis() timer doesn't tick during light_sleep leading to values that have nothing to do with the current run time of the program. It is easy to correct the value returned by millis() in user code, but a better place to do this is in the underlying implementation of millis().
  3. When light_sleep is made to work for longer time periods (see details below), the getimeofday() and time() clocks tick too fast.

Details:

  1. timer-based light_sleep sometimes never wakes up: calling suspend() in the sketch below will eventually cause esp_light_sleep_start() to never return. Small values of sleep (e.g., 10ms) will usually cause the hang to happen within a few minutes. Larger values (e.g., 1000ms) may take a few hours before the hang occurs. To me, this behavior is indicative of a race condition in esp_light_sleep_start() that is "tickled" the more frequently the function is called. I have tried several fixes for this issue without success and its root cause remains elusive.

  2. millis() timer doesn't tick during light_sleep: When light_sleep stalls the cpus, normal timers don't tick, including the timer used for the millis() function, and this can often lead to unexpected behavior in programs. The IDF provides the needed hooks to correct millis()'s notion of time (see adjustedMillis() in attached source code), but IMHO it would be much better if the underlying implementation of millis() incorporated this timing correction.

  3. light_sleep causes getimeofday() and time() to tick too fast: The sample output below provides the values of several time counters each second. Over an interval of a couple hours, these differ from real time by ~8 seconds on my WROOM-32 module. To see this, run the sketch and compare its output with the stopwatch on your smartphone. This behavior may be a byproduct of the different oscillator used for the RTC during light_sleep mode, but trying to re-sync the ESP32 TOD clock via NTP doesn't seem to work because the difference between the real (NTP) time and ESP32 TOD clock keeps growing. If the TOD clock cannot be made more accurate, then at least it needs to be correctable by LWIP's sntp module. [An example of attempting to re-sync the TOD clock via NTP is not included here but can be furnished on request.]

Sketch:

Program source:
programSource.txt

Debug Messages:

Sample output:
sampleOutput.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions