Search code examples
cesp-idf

How to access compilation time inside ESP-IDF application code?


Is there a way to access compilation time from inside the ESP-IDF application code? Similarly to how you can access IDF version with IDF_VER?


Solution

  • It is available in IDF version >= 3.3

    See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html#application-description

    /**
     * @brief Description about application.
     */
    typedef struct {
        uint32_t magic_word;        /*!< Magic word ESP_APP_DESC_MAGIC_WORD */
        uint32_t secure_version;    /*!< Secure version */
        uint32_t reserv1[2];        /*!< --- */
        char version[32];           /*!< Application version */
        char project_name[32];      /*!< Project name */
        char time[16];              /*!< Compile time */
        char date[16];              /*!< Compile date*/
        char idf_ver[32];           /*!< Version IDF */
        uint8_t app_elf_sha256[32]; /*!< sha256 of elf file */
        uint32_t reserv2[20];       /*!< --- */
    } esp_app_desc_t;
    

    Access it like this:

    // Note esp_ota_get_partition_description() was introduced in ESP-IDF 3.3.
    #ifdef ESP_APP_DESC_MAGIC_WORD // enable functionality only if present in IDF by testing for macro.
    esp_app_desc_t app_info;
    if (esp_ota_get_partition_description(it_partition, &app_info) == ESP_OK)
    {
        ESP_LOGI(TAG, "compilation_time:%s", app_info.time);
    }
    #endif