Skip to content

EspClass::deepSleep only accepts 32bit Integer instead of 64bit #9074

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

Closed
1 task done
juepi opened this issue Jan 6, 2024 · 3 comments · Fixed by #9077
Closed
1 task done

EspClass::deepSleep only accepts 32bit Integer instead of 64bit #9074

juepi opened this issue Jan 6, 2024 · 3 comments · Fixed by #9077
Assignees
Labels
Milestone

Comments

@juepi
Copy link

juepi commented Jan 6, 2024

Board

WEMOS S2 Mini (occurs probably on any ESP32)

Device Description

no other hardware involved

Hardware Configuration

Nothing special, just testing DeepSleep

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Windows 11

Flash frequency

default

PSRAM enabled

no

Upload speed

115200

Description

I'm really not sure if this is by intention as it's a so obvious bug to me that i really wonder why no one else has stumbled over it, but
according to file Esp.cpp:

void EspClass::deepSleep(uint32_t time_us)
{
    esp_deep_sleep(time_us);
}

Where esp_deep_sleep expects a uint64_t value (which makes much more sense, as the 32bit value limits sleep time to ~4300 seconds).

Sketch

uint32_t SleepTime = (7200 * 1000 * 1000); //µs -> overflow!
ESP.deepSleep(SleepTime); // -> actual sleep time ~2900sec

Debug Message

none

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@juepi juepi added the Status: Awaiting triage Issue is waiting for triage label Jan 6, 2024
@SuGlider SuGlider self-assigned this Jan 6, 2024
@SuGlider SuGlider added Type: Bug 🐛 All bugs Status: In Progress ⚠️ Issue is in progress and removed Status: Awaiting triage Issue is waiting for triage labels Jan 6, 2024
@SuGlider
Copy link
Collaborator

SuGlider commented Jan 6, 2024

Thanks @juepi !!

@SuGlider
Copy link
Collaborator

SuGlider commented Jan 6, 2024

@juepi - Just make sure you declare the time correctly for the compiler:

uint64_t time_us1 = 7200000000ull;  // works fine
uint64_t time_us2 = (uint64_t) 7200 * 1000 * 1000;  // works fine

//warning: integer overflow in expression of type 'int' results in '-1389934592' [-Woverflow]
uint64_t SleepTime = (7200 * 1000 * 1000); // <<<<===== this will not work. Compiler will try to use utin32_t in the right side.
// result is actually SleepTime = 2,905,032,704 in 32 bit ===> 18,446,744,072,319,617,024 in 64 bit representation

@juepi
Copy link
Author

juepi commented Jan 6, 2024

@juepi - Just make sure you declare the time correctly for the compiler:

uint64_t time_us1 = 7200000000ull;  // works fine
uint64_t time_us2 = (uint64_t) 7200 * 1000 * 1000;  // works fine

//warning: integer overflow in expression of type 'int' results in '-1389934592' [-Woverflow]
uint64_t SleepTime = (7200 * 1000 * 1000); // <<<<===== this will not work. Compiler will try to use utin32_t in the right side.
// result is actually SleepTime = 2,905,032,704 in 32 bit ===> 18,446,744,072,319,617,024 in 64 bit representation

Thanks for the hint @SuGlider, to be honest i managed to step into exactly the described problem when i was calculating my sleep time out of 2 time_t values as soon as i've switched to the uint64_t datatype 😆
But sleeping >2hrs works perfectly well now when calling esp_deep_sleep directly.

yours,
Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

2 participants