Skip to content

esp_timer_get_time returning uint64_t but function declares itself as int64_t (IDFGH-15193) #11321

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
3 tasks done
NigelGuyLeeming opened this issue Apr 27, 2025 · 1 comment
Closed
3 tasks done

Comments

@NigelGuyLeeming
Copy link

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.

General issue report

esp_timer_get_time is declared
int64_t esp_timer_get_time(void) attribute((alias("esp_timer_impl_get_time")));
which in turn is declared
int64_t ESP_TIMER_IRAM_ATTR esp_timer_impl_get_time(void)
{
return esp_timer_impl_get_counter_reg() / TICKS_PER_US;
}
and calls
uint64_t ESP_TIMER_IRAM_ATTR esp_timer_impl_get_counter_reg(void)

this [return esp_timer_impl_get_counter_reg() / TICKS_PER_US;] will return a uint64_t.

Steps to reproduce in arduino ide

  1. Paste the following code
    int64_t times[15];
    uint64_t timesu[15];
    int count=0;

void setup() {
Serial.begin(115200);
}
void loop() {
times[0]=esp_timer_get_time();
timesu[0]=esp_timer_get_time();
delayMicroseconds(200);
times[1]=esp_timer_get_time();
timesu[1]=esp_timer_get_time();
times[2]=esp_timer_get_time();
timesu[2]=esp_timer_get_time();
Serial.println("int64_t");
Serial.printf("Raw times: %lld %lld %lld\n", times[0], times[1], times[2]);
Serial.printf("Raw timesu: %llu %llu %llu\n", timesu[0], timesu[1], timesu[2]);
Serial.println("uint64_t");
Serial.printf("Diff times: %lld %lld\n", times[1]-times[0], times[2]-times[0]);
Serial.printf("Diff timesu: %llu %llu\n", timesu[1]-timesu[0], timesu[2]-timesu[0]);

delay(2000);

}

  1. Run and observe serial output
    12:58:30.371 -> int64_t
    12:58:30.371 -> Raw times: -5611473693289987786 2098724293209941280 -1945483338840014608
    12:58:30.371 -> Raw timesu: 1226138255 1226138456 1226138457
    12:58:30.371 -> uint64_t
    12:58:30.371 -> Diff times: 7710197986499929066 3665990354449973178
    12:58:30.371 -> Diff timesu: 201 202

The raw and diff times stored as int64_t are meaningless. raw and diff for uint64_t are correct.

@github-actions github-actions bot changed the title esp_timer_get_time returning uint64_t but function declares itself as int64_t esp_timer_get_time returning uint64_t but function declares itself as int64_t (IDFGH-15193) Apr 27, 2025
@Alvin1Zhang Alvin1Zhang transferred this issue from espressif/esp-idf Apr 28, 2025
@me-no-dev
Copy link
Member

@Alvin1Zhang this is not an Arduino issue. esp_timer_get_time() is part of ESP-IDF

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

No branches or pull requests

2 participants