Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp_sleep_enable_timer_wakeup with UINT64_MAX wakes up immediately (IDFGH-14485) #15255

Open
3 tasks done
KenVanHoeylandt opened this issue Jan 22, 2025 · 0 comments
Open
3 tasks done
Assignees
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@KenVanHoeylandt
Copy link

KenVanHoeylandt commented Jan 22, 2025

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

5.3.2 (tested), 5.4 (very likely)

Espressif SoC revision.

ESP32-S3 (tested), but likely all SOCs

Operating System used.

Linux

How did you build your project?

Command line with CMake

If you are using Windows, please specify command line type.

None

Development Kit.

unPhone (likely platform-independent issue)

Power Supply used.

Battery

What is the expected behavior?

Context: esp_err_t esp_sleep_enable_timer_wakeup(uint64_t time_in_us)

esp_sleep_enable_timer_wakeup(UINT64_MAX); should time out for a very long time, but it wakes the device up immediately.

The cause is likely the internal code for esp_sleep_start():

int64_t sleep_duration = (int64_t) s_config.sleep_duration - (int64_t) s_config.sleep_time_adjustment;

int64_t sleep_duration = (int64_t) s_config.sleep_duration - (int64_t) s_config.sleep_time_adjustment;

It converts the uint64_t to int64_t, causing the value to overflow.

What is the actual behavior?

esp_sleep_enable_timer_wakeup(UINT64_MAX); causes a boot loop.

Steps to reproduce.

  1. Have an app with:
esp_sleep_enable_timer_wakeup(UINT64_MAX);
esp_deep_sleep_start();
  1. Observe boot loop
  2. Change code:
esp_sleep_enable_timer_wakeup(UINT64_MAX / 2);
esp_deep_sleep_start();
  1. Observe boot loop issue is fixed

More Information.

The problem is that multiple internal types work with int64_t so the fix isn't super obvious: you'd probably have to change all the internal sleep-related functions that use this type.

A short-term solution could be adding documentation about the value limits of the function parameter for esp_sleep_enable_timer_wakeup()

@KenVanHoeylandt KenVanHoeylandt added the Type: Bug bugs in IDF label Jan 22, 2025
@github-actions github-actions bot changed the title esp_sleep_enable_timer_wakeup with UINT64_MAX wakes up immediately esp_sleep_enable_timer_wakeup with UINT64_MAX wakes up immediately (IDFGH-14485) Jan 22, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants