Where is the definition of function millis() located used for ESP32

Hi everybody,

recently somebody asked a question about the rollover of millis() on ESP32-boards.

I tried to find the definition of the function millis() but had no luck so far.

I found something in
...packages\arduino\hardware\mbed\1.1.6\cores\arduino\wiring.cpp

unsigned long millis()
{
  return t.read_ms();
}

but I'm still unsure if this is the defintion used if I compile for the platform ESP32
So does somebody know where this definition is or a method to really find it?

best regards Stefan

esp32-hal-misc.c:

unsigned long IRAM_ATTR millis()
{
    return (unsigned long) (esp_timer_get_time() / 1000ULL);
}

Of course, that just begs the question .... why would you ever use millis() on an ESP32? The esp_timer_get_time() function returns a 64-bit integer, has microsecond-resolution, and won't roll over for more than 290,000 years.

1 Like

ah there it is. Thank you gfvavlo

yes very good question. hm well one argument is "oldwards" compatibility to Arduino Uno / Mega
Whenever I would like to re-use some code written for ESP on an Arduino this would require re-editing or do you have a clever solution how to make things like

uint64_t currentMicros = esp_timer_get_time();

compile the same way as

uint32_t currentMillis = millis();

?

best regards Stefan

Much of ESP32/ESP8266 Arduino cores are wrapper functions. If can get a bit hairy to go looking under the covers because you just find templates, macros, and raw IDF.

Efficiency and understanding comes from IDF programming the Espressif devices:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/index.html

One can mix the two functions, however:

https://medium.com/home-wireless/how-to-program-an-esp32-in-arduino-while-using-esp-idf-functions-90033d860f75

FTI: The Official STM32duino core does the same wrapper concept around their professional function library ... which does introduce some inefficiency.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.