Answers checklist.
IDF version.
master and any earlier
Espressif SoC revision.
all
Operating System used.
Linux
How did you build your project?
Command line with Make
If you are using Windows, please specify command line type.
None
Development Kit.
all
Power Supply used.
USB
What is the expected behavior?
Passing 0xFFFFFFFF to the current ESP IDF usleep implementation should make the system sleep for 0xFFFFFFFF microseconds, OR return EINVAL to indicate that values larger than 1_000_000 are not supported (as per the usleep syscall spec).
What is the actual behavior?
Passing 0xFFFFFFFF to the current ESP IDF usleep implementation will overflow and sleep for a smaller amount of time.
Steps to reproduce.
- Generate an ESP-IDF template with
cargo generate https://github.com/esp-rs/esp-idf-template and accept all defaults
- Replace the
main.rs of the generated template with
use std::time::Instant;
use esp_idf_svc::sys::usleep;
fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches();
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();
for sleep_us in [
1_000_000, // Works
0xffff_ffffu32, // Will not work due to a silent integer overflow in `usleep`
0xffff_ffffu32 - 10 /*ms - the default tick-rate*/ * 1000 - 1 // Works as we avoid the integer overflow
] {
log::info!("About to sleep for ~{sleep_us}us");
let start_sleep = Instant::now();
let error_code = unsafe {
usleep(sleep_us)
};
log::info!("Actual sleep: ~{}us, error_code: {error_code}", start_sleep.elapsed().as_micros());
}
}
... or translate to C.
Build, flash and run.
Debug Logs.
No response
More Information.
Related to ivmarkov/rust@1faccba#diff-2b173511d53f2c01a70eac2f753b998948ca6cbe3d013b6119fbe4631770ec60R279 which fixes rust-lang/rust#129212 (comment)
Answers checklist.
IDF version.
master and any earlier
Espressif SoC revision.
all
Operating System used.
Linux
How did you build your project?
Command line with Make
If you are using Windows, please specify command line type.
None
Development Kit.
all
Power Supply used.
USB
What is the expected behavior?
Passing 0xFFFFFFFF to the current ESP IDF usleep implementation should make the system sleep for 0xFFFFFFFF microseconds, OR return
EINVALto indicate that values larger than 1_000_000 are not supported (as per theusleepsyscall spec).What is the actual behavior?
Passing 0xFFFFFFFF to the current ESP IDF usleep implementation will overflow and sleep for a smaller amount of time.
Steps to reproduce.
cargo generate https://github.com/esp-rs/esp-idf-templateand accept all defaultsmain.rsof the generated template with... or translate to C.
Build, flash and run.
Debug Logs.
No response
More Information.
Related to ivmarkov/rust@1faccba#diff-2b173511d53f2c01a70eac2f753b998948ca6cbe3d013b6119fbe4631770ec60R279 which fixes rust-lang/rust#129212 (comment)